[llvm] r198659 - Revert "indvars: sink truncates outside the loop."

Andrew Trick atrick at apple.com
Mon Jan 6 17:50:58 PST 2014


Author: atrick
Date: Mon Jan  6 19:50:58 2014
New Revision: 198659

URL: http://llvm.org/viewvc/llvm-project?rev=198659&view=rev
Log:
Revert "indvars: sink truncates outside the loop."

This reverts commit r198654.

One of the bots reported a SciMark failure.

Modified:
    llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
    llvm/trunk/test/Transforms/IndVarSimplify/iv-widen.ll

Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=198659&r1=198658&r2=198659&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Mon Jan  6 19:50:58 2014
@@ -883,8 +883,6 @@ const SCEVAddRecExpr *WidenIV::GetWideRe
 /// This IV user cannot be widen. Replace this use of the original narrow IV
 /// with a truncation of the new wide IV to isolate and eliminate the narrow IV.
 static void truncateIVUse(NarrowIVDefUse DU, DominatorTree *DT) {
-  DEBUG(dbgs() << "INDVARS: Truncate IV " << *DU.WideDef
-        << " for user " << *DU.NarrowUse << "\n");
   IRBuilder<> Builder(getInsertPointForUses(DU.NarrowUse, DU.NarrowDef, DT));
   Value *Trunc = Builder.CreateTrunc(DU.WideDef, DU.NarrowDef->getType());
   DU.NarrowUse->replaceUsesOfWith(DU.NarrowDef, Trunc);
@@ -895,27 +893,10 @@ static void truncateIVUse(NarrowIVDefUse
 Instruction *WidenIV::WidenIVUse(NarrowIVDefUse DU, SCEVExpander &Rewriter) {
 
   // Stop traversing the def-use chain at inner-loop phis or post-loop phis.
-  if (PHINode *UsePhi = dyn_cast<PHINode>(DU.NarrowUse)) {
-    if (LI->getLoopFor(UsePhi->getParent()) != L) {
-      // For LCSSA phis, sink the truncate outside the loop.
-      // After SimplifyCFG most loop exit targets have a single predecessor.
-      // Otherwise fall back to a truncate within the loop.
-      if (UsePhi->getNumOperands() != 1)
-        truncateIVUse(DU, DT);
-      else {
-        PHINode *WidePhi =
-          PHINode::Create(DU.WideDef->getType(), 1, UsePhi->getName() + ".wide",
-                          UsePhi);
-        WidePhi->addIncoming(DU.WideDef, UsePhi->getIncomingBlock(0));
-        IRBuilder<> Builder(WidePhi->getParent()->getFirstInsertionPt());
-        Value *Trunc = Builder.CreateTrunc(WidePhi, DU.NarrowDef->getType());
-        UsePhi->replaceAllUsesWith(Trunc);
-        DeadInsts.push_back(UsePhi);
-        DEBUG(dbgs() << "INDVARS: Widen lcssa phi " << *UsePhi
-              << " to " << *WidePhi << "\n");
-      }
-      return 0;
-    }
+  if (isa<PHINode>(DU.NarrowUse) &&
+      LI->getLoopFor(DU.NarrowUse->getParent()) != L) {
+    truncateIVUse(DU, DT);
+    return 0;
   }
   // Our raison d'etre! Eliminate sign and zero extension.
   if (IsSigned ? isa<SExtInst>(DU.NarrowUse) : isa<ZExtInst>(DU.NarrowUse)) {

Modified: llvm/trunk/test/Transforms/IndVarSimplify/iv-widen.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/iv-widen.ll?rev=198659&r1=198658&r2=198659&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/iv-widen.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/iv-widen.ll Mon Jan  6 19:50:58 2014
@@ -7,11 +7,10 @@ target triple = "x86_64-apple-darwin"
 ; Only one phi now.
 ; CHECK: phi
 ; CHECK-NOT: phi
-; One trunc for the gep.
+; We now get 2 trunc, one for the gep and one for the lcssa phi.
 ; CHECK: trunc i64 %indvars.iv to i32
-; One trunc for the dummy() call.
-; CHECK-LABEL: exit24:
-; CHECK: trunc i64 {{.*}}lcssa.wide to i32
+; CHECK: trunc i64 %indvars.iv to i32
+; CHECK-LABEL: B24:
 define void @sloop(i32* %a) {
 Prologue:
   br i1 undef, label %B18, label %B6





More information about the llvm-commits mailing list