Skip to content

[GlobalISel] Fix silently dropped MIFlags on selected instructions #138851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025

Conversation

Pierre-vh
Copy link
Contributor

We used uint16 for flags but flags now go up to 24 bits, so all flags in bits 16-24 were lost.

Fixes #110801

We used uint16 for flags but flags now go up to 24 bits, so all flags in bits 16-24 were lost.

Fixes #110801
Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Pierre-vh Pierre-vh requested review from arsenm, jayfoad and shiltian May 7, 2025 11:40
@Pierre-vh Pierre-vh marked this pull request as ready for review May 7, 2025 11:40
@llvmbot
Copy link
Member

llvmbot commented May 7, 2025

@llvm/pr-subscribers-llvm-globalisel

@llvm/pr-subscribers-backend-amdgpu

Author: Pierre van Houtryve (Pierre-vh)

Changes

We used uint16 for flags but flags now go up to 24 bits, so all flags in bits 16-24 were lost.

Fixes #110801


Full diff: https://github.com/llvm/llvm-project/pull/138851.diff

2 Files Affected:

  • (modified) llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h (+2-2)
  • (added) llvm/test/CodeGen/AMDGPU/GlobalISel/selected-inst-flags.mir (+28)
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h b/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h
index 654112e86e873..6c4f03649149e 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h
@@ -61,7 +61,7 @@ bool GIMatchTableExecutor::executeMatchTable(
   // Bypass the flag check on the instruction, and only look at the MCInstrDesc.
   bool NoFPException = !State.MIs[0]->getDesc().mayRaiseFPException();
 
-  const uint16_t Flags = State.MIs[0]->getFlags();
+  const uint32_t Flags = State.MIs[0]->getFlags();
 
   enum RejectAction { RejectAndGiveUp, RejectAndResume };
   auto handleReject = [&]() -> RejectAction {
@@ -80,7 +80,7 @@ bool GIMatchTableExecutor::executeMatchTable(
     for (auto MIB : OutMIs) {
       // Set the NoFPExcept flag when no original matched instruction could
       // raise an FP exception, but the new instruction potentially might.
-      uint16_t MIBFlags = Flags | MIB.getInstr()->getFlags();
+      uint32_t MIBFlags = Flags | MIB.getInstr()->getFlags();
       if (NoFPException && MIB->mayRaiseFPException())
         MIBFlags |= MachineInstr::NoFPExcept;
       if (Observer)
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/selected-inst-flags.mir b/llvm/test/CodeGen/AMDGPU/GlobalISel/selected-inst-flags.mir
new file mode 100644
index 0000000000000..c87284fade303
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/selected-inst-flags.mir
@@ -0,0 +1,28 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
+# RUN: llc -mtriple=amdgcn-- -run-pass=instruction-select -o - %s | FileCheck %s
+
+# Checks MI Flags are preserved on selected instructions.
+
+---
+name:            s_or_i32_disjoint
+tracksRegLiveness: true
+regBankSelected: true
+legalized: true
+body:             |
+  bb.0:
+    liveins: $sgpr0, $sgpr1
+
+    ; CHECK-LABEL: name: s_or_i32_disjoint
+    ; CHECK: liveins: $sgpr0, $sgpr1
+    ; CHECK-NEXT: {{  $}}
+    ; CHECK-NEXT: [[COPY:%[0-9]+]]:sreg_32 = COPY $sgpr0
+    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:sreg_32 = COPY $sgpr1
+    ; CHECK-NEXT: [[S_OR_B32_:%[0-9]+]]:sreg_32 = disjoint S_OR_B32 [[COPY]], [[COPY1]], implicit-def dead $scc
+    ; CHECK-NEXT: $sgpr0 = COPY [[S_OR_B32_]]
+    ; CHECK-NEXT: SI_RETURN_TO_EPILOG implicit $sgpr0
+    %0:sgpr(s32) = COPY $sgpr0
+    %1:sgpr(s32) = COPY $sgpr1
+    %2:sgpr(s32) = disjoint G_OR %0, %1
+    $sgpr0 = COPY %2
+    SI_RETURN_TO_EPILOG implicit $sgpr0
+...

Copy link
Contributor Author

Pierre-vh commented May 7, 2025

Merge activity

  • May 7, 8:06 AM EDT: A user started a stack merge that includes this pull request via Graphite.
  • May 7, 8:07 AM EDT: @Pierre-vh merged this pull request with Graphite.

@Pierre-vh Pierre-vh merged commit c3a638c into main May 7, 2025
11 of 15 checks passed
@Pierre-vh Pierre-vh deleted the users/pierre-vh/fix-propagateflags branch May 7, 2025 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GlobalISel selection loses disjoint flag on or
3 participants