[llvm] [X86][GlobalISel] Use GIntrinsic during custom intrinsic selection (PR #83498)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 29 14:56:40 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-globalisel

@llvm/pr-subscribers-backend-x86

Author: Evgenii Kudriashov (e-kud)

<details>
<summary>Changes</summary>



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


2 Files Affected:

- (modified) llvm/lib/Target/X86/GISel/X86InstructionSelector.cpp (+1-1) 
- (added) llvm/test/CodeGen/X86/GlobalISel/select-custom-intrinsic.mir (+27) 


``````````diff
diff --git a/llvm/lib/Target/X86/GISel/X86InstructionSelector.cpp b/llvm/lib/Target/X86/GISel/X86InstructionSelector.cpp
index 26932ba2c8e242..34d0daf4296990 100644
--- a/llvm/lib/Target/X86/GISel/X86InstructionSelector.cpp
+++ b/llvm/lib/Target/X86/GISel/X86InstructionSelector.cpp
@@ -1843,7 +1843,7 @@ bool X86InstructionSelector::selectIntrinsicWSideEffects(
   assert(I.getOpcode() == TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS &&
          "unexpected instruction");
 
-  if (I.getOperand(0).getIntrinsicID() != Intrinsic::trap)
+  if (cast<GIntrinsic>(I).getIntrinsicID() != Intrinsic::trap)
     return false;
 
   BuildMI(*I.getParent(), I, I.getDebugLoc(), TII.get(X86::TRAP));
diff --git a/llvm/test/CodeGen/X86/GlobalISel/select-custom-intrinsic.mir b/llvm/test/CodeGen/X86/GlobalISel/select-custom-intrinsic.mir
new file mode 100644
index 00000000000000..85c59b1566164b
--- /dev/null
+++ b/llvm/test/CodeGen/X86/GlobalISel/select-custom-intrinsic.mir
@@ -0,0 +1,27 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
+# RUN: llc -mtriple=x86_64-linux-gnu -run-pass=instruction-select -global-isel-abort=2 -pass-remarks-missed='gisel*' 2>&1 %s -o - | FileCheck %s --check-prefixes=CHECK
+# RUN: llc -mtriple=i386-linux-gnu -run-pass=instruction-select -global-isel-abort=2 -pass-remarks-missed='gisel*' 2>&1 %s -o - | FileCheck %s --check-prefixes=CHECK
+
+# CHECK: remark: <unknown>:0:0: cannot select: %2:gpr(s8) = G_INTRINSIC_W_SIDE_EFFECTS intrinsic(@llvm.x86.atomic.sub.cc), %0:gpr(p0), %1:gpr(s32), 4 (in function: intrinsic_returns)
+
+...
+---
+name:            intrinsic_returns
+legalized:       true
+regBankSelected: true
+body:             |
+  bb.1:
+
+    ; CHECK-LABEL: name: intrinsic_returns
+    ; CHECK: [[DEF:%[0-9]+]]:gpr(p0) = IMPLICIT_DEF
+    ; CHECK-NEXT: [[C:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 1
+    ; CHECK-NEXT: [[INT:%[0-9]+]]:gpr(s8) = G_INTRINSIC_W_SIDE_EFFECTS intrinsic(@llvm.x86.atomic.sub.cc), [[DEF]](p0), [[C]](s32), 4
+    ; CHECK-NEXT: $al = COPY [[INT]](s8)
+    ; CHECK-NEXT: RET 0, implicit $al
+    %0:gpr(p0) = IMPLICIT_DEF
+    %1:gpr(s32) = G_CONSTANT i32 1
+    %2:gpr(s8) = G_INTRINSIC_W_SIDE_EFFECTS intrinsic(@llvm.x86.atomic.sub.cc), %0(p0), %1(s32), 4
+    $al = COPY %2(s8)
+    RET 0, implicit $al
+
+...

``````````

</details>


https://github.com/llvm/llvm-project/pull/83498


More information about the llvm-commits mailing list