[PATCH] D158473: [AArch64] Check opcode before trying to extract register from operand

David Tellenbach via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 21 18:03:10 PDT 2023


tellenbach created this revision.
tellenbach added reviewers: jroelofs, davide.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
tellenbach requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When matching FNEG patterns for the MachineCombiner we need to check for
opcodes first, before trying to extract a register from an operand.
Otherwise handling of instructions with non-register operands causes the
compiler to crash.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158473

Files:
  llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
  llvm/test/CodeGen/AArch64/inline-asm-empty-template.ll


Index: llvm/test/CodeGen/AArch64/inline-asm-empty-template.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/inline-asm-empty-template.ll
@@ -0,0 +1,29 @@
+; RUN: llc -mtriple=aarch64 %s -o - | FileCheck %s
+
+ at c = global double 0.000000e+00, align 8
+
+; CHECK:       a:                                      // @a
+define void @a(double %c) {
+; CHECK:      // %bb.0:                               // %entry
+entry:
+  %0 = load double, ptr @c, align 8
+; CHECK:  	    //APP
+; CHECK-NEXT:	  //NO_APP
+  %1 = tail call double asm sideeffect "", "=w,0"(double %0)
+  %2 = load double, ptr @c, align 8
+; CHECK:  	    //APP
+; CHECK-NEXT:	  //NO_APP
+  %3 = tail call double asm sideeffect "", "=w,0"(double %2)
+  %fneg = fneg double %1
+  %cmp = fcmp oeq double %3, %fneg
+  br i1 %cmp, label %if.then, label %if.end
+
+if.then:
+  tail call void @b(double noundef %1)
+  br label %if.end
+
+if.end:
+  ret void
+}
+
+declare void @b(double noundef)
Index: llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -5508,8 +5508,8 @@
   auto Match = [&](unsigned Opcode, MachineCombinerPattern Pattern) -> bool {
     MachineOperand &MO = Root.getOperand(1);
     MachineInstr *MI = MRI.getUniqueVRegDef(MO.getReg());
-    if (MI != nullptr && MRI.hasOneNonDBGUse(MI->getOperand(0).getReg()) &&
-        (MI->getOpcode() == Opcode) &&
+    if (MI != nullptr && (MI->getOpcode() == Opcode) &&
+        MRI.hasOneNonDBGUse(MI->getOperand(0).getReg()) &&
         Root.getFlag(MachineInstr::MIFlag::FmContract) &&
         Root.getFlag(MachineInstr::MIFlag::FmNsz) &&
         MI->getFlag(MachineInstr::MIFlag::FmContract) &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158473.552180.patch
Type: text/x-patch
Size: 1845 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230822/58d1fc58/attachment.bin>


More information about the llvm-commits mailing list