From 9233137390a935ee2834f82a627c9fde5402db04 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Fri, 22 May 2015 02:47:29 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237990 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopUnrollPass.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/Transforms/Scalar/LoopUnrollPass.cpp b/lib/Transforms/Scalar/LoopUnrollPass.cpp index 03e1f4cbf60..9f142a6b357 100644 --- a/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -402,14 +402,10 @@ class UnrollAnalyzer : public InstVisitor { else SimpleV = SimplifyBinOp(I.getOpcode(), LHS, RHS, DL); - if (SimpleV) - NumberOfOptimizedInstructions += TTI.getUserCost(&I); - - if (Constant *C = dyn_cast_or_null(SimpleV)) { + if (Constant *C = dyn_cast_or_null(SimpleV)) SimplifiedValues[&I] = C; - return true; - } - return false; + + return SimpleV; } /// Try to fold load I. @@ -452,7 +448,6 @@ class UnrollAnalyzer : public InstVisitor { 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) -- 2.34.1