[PATCH] D16785: [AArch64] AArch64LoadStoreOptimizer: fix bug in pre-inc check iterator

Geoff Berry via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 1 13:00:58 PST 2016


gberry created this revision.
gberry added reviewers: mcrosier, jmolloy, t.p.northover, junbuml.
gberry added a subscriber: llvm-commits.
Herald added subscribers: mcrosier, rengolin, aemerson.

Fix case where a pre-inc/dec load/store would not be formed if the
add/sub that forms the inc/dec part of the operation was the first
instruction in the block being examined.

http://reviews.llvm.org/D16785

Files:
  lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
  test/CodeGen/AArch64/arm64-nvcast.ll

Index: test/CodeGen/AArch64/arm64-nvcast.ll
===================================================================
--- test/CodeGen/AArch64/arm64-nvcast.ll
+++ test/CodeGen/AArch64/arm64-nvcast.ll
@@ -2,7 +2,7 @@
 
 ; CHECK-LABEL: _test:
 ; CHECK:  fmov.2d v0, #2.00000000
-; CHECK:  str  q0, [sp]
+; CHECK:  str  q0, [sp, #-16]!
 ; CHECK:  mov  x8, sp
 ; CHECK:  ldr s0, [x8, w1, sxtw #2]
 ; CHECK:  str  s0, [x0]
@@ -16,7 +16,7 @@
 
 ; CHECK-LABEL: _test2
 ; CHECK: movi.16b  v0, #0x3f
-; CHECK: str  q0, [sp]
+; CHECK: str  q0, [sp, #-16]!
 ; CHECK: mov  x8, sp
 ; CHECK: ldr s0, [x8, w1, sxtw #2]
 ; CHECK: str  s0, [x0]
Index: lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
===================================================================
--- lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
+++ lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
@@ -954,6 +954,8 @@
     if (!MO.isReg())
       continue;
     unsigned Reg = MO.getReg();
+    if (!Reg)
+      continue;
     if (MO.isDef()) {
       for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI)
         ModifiedRegs.set(*AI);
@@ -1431,12 +1433,9 @@
   BitVector ModifiedRegs, UsedRegs;
   ModifiedRegs.resize(TRI->getNumRegs());
   UsedRegs.resize(TRI->getNumRegs());
-  --MBBI;
-  for (; MBBI != B; --MBBI) {
+  do {
+    --MBBI;
     MachineInstr *MI = MBBI;
-    // Skip DBG_VALUE instructions.
-    if (MI->isDebugValue())
-      continue;
 
     // If we found a match, return it.
     if (isMatchingUpdateInsn(I, MI, BaseReg, Offset))
@@ -1449,7 +1448,10 @@
     // return early.
     if (ModifiedRegs[BaseReg] || UsedRegs[BaseReg])
       return E;
-  }
+
+    if (MBBI == B)
+      break;
+  } while(true);
   return E;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16785.46572.patch
Type: text/x-patch
Size: 1709 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160201/8d3e6d46/attachment.bin>


More information about the llvm-commits mailing list