Fold preceding / trailing base inc / dec into the single load / store as well.
authorEvan Cheng <evan.cheng@apple.com>
Wed, 3 Jun 2009 06:14:58 +0000 (06:14 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Wed, 3 Jun 2009 06:14:58 +0000 (06:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72756 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMLoadStoreOptimizer.cpp
test/CodeGen/ARM/str_pre-2.ll [new file with mode: 0644]

index 047552f627db4b531732a6ad41f206d5ab735ea4..108c6dd4d6b46eb416968babb0fed7d5eecd805f 100644 (file)
@@ -697,7 +697,7 @@ bool ARMLoadStoreOpt::LoadStoreMultipleOpti(MachineBasicBlock &MBB) {
         // LDM/STM ops.
         for (unsigned i = 0, e = MBBII.size(); i < e; ++i)
           if (mergeBaseUpdateLSMultiple(MBB, MBBII[i], Advance, MBBI))
-            NumMerges++;
+            ++NumMerges;
         NumMerges += MBBII.size();
 
         // Try folding preceeding/trailing base inc/dec into those load/store
@@ -705,10 +705,17 @@ bool ARMLoadStoreOpt::LoadStoreMultipleOpti(MachineBasicBlock &MBB) {
         for (unsigned i = 0; i != NumMemOps; ++i)
           if (!MemOps[i].Merged)
             if (mergeBaseUpdateLoadStore(MBB, MemOps[i].MBBI, TII,Advance,MBBI))
-              NumMerges++;
+              ++NumMerges;
 
         // RS may be pointing to an instruction that's deleted. 
         RS->skipTo(prior(MBBI));
+      } else if (NumMemOps == 1) {
+        // Try folding preceeding/trailing base inc/dec into the single
+        // load/store.
+        if (mergeBaseUpdateLoadStore(MBB, MemOps[0].MBBI, TII, Advance, MBBI)) {
+          ++NumMerges;
+          RS->skipTo(prior(MBBI));
+        }
       }
 
       CurrBase = 0;
diff --git a/test/CodeGen/ARM/str_pre-2.ll b/test/CodeGen/ARM/str_pre-2.ll
new file mode 100644 (file)
index 0000000..e9f1945
--- /dev/null
@@ -0,0 +1,12 @@
+; RUN: llvm-as < %s | llc -mtriple=arm-linux-gnu | grep {str.*\\!}
+; RUN: llvm-as < %s | llc -mtriple=arm-linux-gnu | grep {ldr.*\\\[.*\], #+4}
+
+@b = external global i64*
+
+define i64 @t(i64 %a) nounwind readonly {
+entry:
+       %0 = load i64** @b, align 4
+       %1 = load i64* %0, align 4
+       %2 = mul i64 %1, %a
+       ret i64 %2
+}