[PATCH] D78265: [AArch64ConditionOptimizer] Fix missed optimization due to debug insts [10/10]

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 15 18:46:49 PDT 2020


vsk created this revision.
vsk added reviewers: aemerson, paquette.
Herald added subscribers: danielkiss, hiraditya, kristof.beyls.
Herald added a project: LLVM.

The findSuitableCompare method can fail if debug instructions are
present in the MBB -- fix this by using helpers to skip over debug
insts.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78265

Files:
  llvm/lib/Target/AArch64/AArch64ConditionOptimizer.cpp
  llvm/test/CodeGen/AArch64/combine-comparisons-by-cse.ll


Index: llvm/test/CodeGen/AArch64/combine-comparisons-by-cse.ll
===================================================================
--- llvm/test/CodeGen/AArch64/combine-comparisons-by-cse.ll
+++ llvm/test/CodeGen/AArch64/combine-comparisons-by-cse.ll
@@ -1,4 +1,4 @@
-; RUN: llc < %s -mtriple=aarch64-linux-gnu | FileCheck %s
+; RUN: llc -debugify-and-strip-all-safe < %s -mtriple=aarch64-linux-gnu | FileCheck %s
 
 ; marked as external to prevent possible optimizations
 @a = external global i32
Index: llvm/lib/Target/AArch64/AArch64ConditionOptimizer.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64ConditionOptimizer.cpp
+++ llvm/lib/Target/AArch64/AArch64ConditionOptimizer.cpp
@@ -159,7 +159,7 @@
 
   // Now find the instruction controlling the terminator.
   for (MachineBasicBlock::iterator B = MBB->begin(); I != B;) {
-    --I;
+    I = prev_nodbg(I, MBB->begin());
     assert(!I->isTerminator() && "Spurious terminator");
     // Check if there is any use of NZCV between CMP and Bcc.
     if (I->readsRegister(AArch64::NZCV))
@@ -179,7 +179,7 @@
         LLVM_DEBUG(dbgs() << "Immediate of cmp may be out of range, " << *I
                           << '\n');
         return nullptr;
-      } else if (!MRI->use_empty(I->getOperand(0).getReg())) {
+      } else if (!MRI->use_nodbg_empty(I->getOperand(0).getReg())) {
         LLVM_DEBUG(dbgs() << "Destination of cmp is not dead, " << *I << '\n');
         return nullptr;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78265.257935.patch
Type: text/x-patch
Size: 1508 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200416/88069e65/attachment.bin>


More information about the llvm-commits mailing list