[llvm-commits] [llvm] r135650 - in /llvm/trunk: lib/Transforms/Scalar/LoopStrengthReduce.cpp test/Transforms/LoopStrengthReduce/2011-07-20-DoubleIV.ll

Andrew Trick atrick at apple.com
Wed Jul 20 18:05:01 PDT 2011


Author: atrick
Date: Wed Jul 20 20:05:01 2011
New Revision: 135650

URL: http://llvm.org/viewvc/llvm-project?rev=135650&view=rev
Log:
LSR must sometimes sign-extend before generating double constants.

rdar://9786536

Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
    llvm/trunk/test/Transforms/LoopStrengthReduce/2011-07-20-DoubleIV.ll

Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=135650&r1=135649&r2=135650&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Wed Jul 20 20:05:01 2011
@@ -1427,6 +1427,7 @@
     ++UI;
     Instruction *ShadowUse = CandidateUI->getUser();
     Type *DestTy = NULL;
+    bool IsSigned = false;
 
     /* If shadow use is a int->float cast then insert a second IV
        to eliminate this cast.
@@ -1440,10 +1441,14 @@
          for (unsigned i = 0; i < n; ++i, ++d)
            foo(d);
     */
-    if (UIToFPInst *UCast = dyn_cast<UIToFPInst>(CandidateUI->getUser()))
+    if (UIToFPInst *UCast = dyn_cast<UIToFPInst>(CandidateUI->getUser())) {
+      IsSigned = false;
       DestTy = UCast->getDestTy();
-    else if (SIToFPInst *SCast = dyn_cast<SIToFPInst>(CandidateUI->getUser()))
+    }
+    else if (SIToFPInst *SCast = dyn_cast<SIToFPInst>(CandidateUI->getUser())) {
+      IsSigned = true;
       DestTy = SCast->getDestTy();
+    }
     if (!DestTy) continue;
 
     if (TLI) {
@@ -1474,7 +1479,9 @@
 
     ConstantInt *Init = dyn_cast<ConstantInt>(PH->getIncomingValue(Entry));
     if (!Init) continue;
-    Constant *NewInit = ConstantFP::get(DestTy, Init->getZExtValue());
+    Constant *NewInit = ConstantFP::get(DestTy, IsSigned ?
+                                        Init->getSExtValue() :
+                                        Init->getZExtValue());
 
     BinaryOperator *Incr =
       dyn_cast<BinaryOperator>(PH->getIncomingValue(Latch));

Modified: llvm/trunk/test/Transforms/LoopStrengthReduce/2011-07-20-DoubleIV.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopStrengthReduce/2011-07-20-DoubleIV.ll?rev=135650&r1=135649&r2=135650&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopStrengthReduce/2011-07-20-DoubleIV.ll (original)
+++ llvm/trunk/test/Transforms/LoopStrengthReduce/2011-07-20-DoubleIV.ll Wed Jul 20 20:05:01 2011
@@ -15,7 +15,26 @@
 
 loop:
   %i.01 = phi i32 [ -39, %entry ], [ %inc, %loop ]
-  %conv7 = sitofp i32 %i.01 to double
+  %conv = sitofp i32 %i.01 to double
+  %inc = add nsw i32 %i.01, 1
+  br i1 undef, label %loop, label %for.end
+
+for.end:
+  unreachable
+}
+
+; Now check that the computed double constant is correct.
+; CHECK: @doubleIV
+; CHECK: phi double [ 0x43F0000000000000, %entry ]
+; CHECK: br
+define void @doubleIV() nounwind {
+entry:
+  br label %loop
+
+loop:
+  %i.01 = phi i32 [ -39, %entry ], [ %inc, %loop ]
+  %conv = sitofp i32 %i.01 to double
+  %div = fdiv double %conv, 4.000000e+01
   %inc = add nsw i32 %i.01, 1
   br i1 undef, label %loop, label %for.end
 





More information about the llvm-commits mailing list