[llvm] r237990 - [Unroll] Refactor the accumulation of optimized instruction costs into

Chandler Carruth chandlerc at gmail.com
Thu May 21 19:47:29 PDT 2015


Author: chandlerc
Date: Thu May 21 21:47:29 2015
New Revision: 237990

URL: http://llvm.org/viewvc/llvm-project?rev=237990&view=rev
Log:
[Unroll] Refactor the accumulation of optimized instruction costs into
a single location.

This reduces code duplication a bit and will also pave the way for
a better separation between the visitation algorithm and the unroll
analysis.

No functionality changed.

Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp?rev=237990&r1=237989&r2=237990&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp Thu May 21 21:47:29 2015
@@ -402,14 +402,10 @@ class UnrollAnalyzer : public InstVisito
     else
       SimpleV = SimplifyBinOp(I.getOpcode(), LHS, RHS, DL);
 
-    if (SimpleV)
-      NumberOfOptimizedInstructions += TTI.getUserCost(&I);
-
-    if (Constant *C = dyn_cast_or_null<Constant>(SimpleV)) {
+    if (Constant *C = dyn_cast_or_null<Constant>(SimpleV))
       SimplifiedValues[&I] = C;
-      return true;
-    }
-    return false;
+
+    return SimpleV;
   }
 
   /// Try to fold load I.
@@ -452,7 +448,6 @@ class UnrollAnalyzer : public InstVisito
     assert(CV && "Constant expected.");
     SimplifiedValues[&I] = CV;
 
-    NumberOfOptimizedInstructions += TTI.getUserCost(&I);
     return true;
   }
 
@@ -571,7 +566,13 @@ public:
         // opportunities.
         for (Instruction &I : *BB) {
           UnrolledLoopSize += TTI.getUserCost(&I);
-          Base::visit(I);
+
+          // Visit the instruction to analyze its loop cost after unrolling,
+          // and if the visitor returns true, then we can optimize this
+          // instruction away.
+          if (Base::visit(I))
+            NumberOfOptimizedInstructions += TTI.getUserCost(&I);
+
           // If unrolled body turns out to be too big, bail out.
           if (UnrolledLoopSize - NumberOfOptimizedInstructions >
               MaxUnrolledLoopSize)





More information about the llvm-commits mailing list