[llvm-commits] [llvm] r154079 - in /llvm/trunk: lib/Transforms/Scalar/LoopStrengthReduce.cpp test/CodeGen/ARM/commute-movcc.ll

Jakob Stoklund Olesen stoklund at 2pi.dk
Wed Apr 4 20:10:56 PDT 2012


Author: stoklund
Date: Wed Apr  4 22:10:56 2012
New Revision: 154079

URL: http://llvm.org/viewvc/llvm-project?rev=154079&view=rev
Log:
Pass the right sign to TLI->isLegalICmpImmediate.

LSR can fold three addressing modes into its ICmpZero node:

  ICmpZero BaseReg + Offset      => ICmp BaseReg, -Offset
  ICmpZero -1*ScaleReg + Offset  => ICmp ScaleReg, Offset
  ICmpZero BaseReg + -1*ScaleReg => ICmp BaseReg, ScaleReg

The first two cases are only used if TLI->isLegalICmpImmediate() likes
the offset.

Make sure the right Offset sign is passed to this method in the second
case. The ARM version is not symmetric.

<rdar://problem/11184260>

Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
    llvm/trunk/test/CodeGen/ARM/commute-movcc.ll

Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=154079&r1=154078&r2=154079&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Wed Apr  4 22:10:56 2012
@@ -1282,10 +1282,19 @@
     // If we have low-level target information, ask the target if it can fold an
     // integer immediate on an icmp.
     if (AM.BaseOffs != 0) {
-      if (TLI) return TLI->isLegalICmpImmediate(-(uint64_t)AM.BaseOffs);
-      return false;
+      if (!TLI)
+        return false;
+      // We have one of:
+      // ICmpZero     BaseReg + Offset => ICmp BaseReg, -Offset
+      // ICmpZero -1*ScaleReg + Offset => ICmp ScaleReg, Offset
+      // Offs is the ICmp immediate.
+      int64_t Offs = AM.BaseOffs;
+      if (AM.Scale == 0)
+        Offs = -(uint64_t)Offs; // The cast does the right thing with INT64_MIN.
+      return TLI->isLegalICmpImmediate(Offs);
     }
 
+    // ICmpZero BaseReg + -1*ScaleReg => ICmp BaseReg, ScaleReg
     return true;
 
   case LSRUse::Basic:

Modified: llvm/trunk/test/CodeGen/ARM/commute-movcc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/commute-movcc.ll?rev=154079&r1=154078&r2=154079&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/commute-movcc.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/commute-movcc.ll Wed Apr  4 22:10:56 2012
@@ -17,7 +17,11 @@
 ; CHECK: movls
 ; CHECK-NOT: mov
 
+; This is really an LSR test: Make sure that cmp is using the incremented
+; induction variable.
 ; CHECK: %if.end8
+; CHECK: add{{(s|\.w)?}} [[IV:r[0-9]+]], {{.*}}#1
+; CHECK: cmp [[IV]], #
 
 define i32 @f(i32* nocapture %a, i32 %Pref) nounwind ssp {
 entry:





More information about the llvm-commits mailing list