diff options
| author | Philip Reames <listmail@philipreames.com> | 2015-05-22 02:14:05 +0000 |
|---|---|---|
| committer | Philip Reames <listmail@philipreames.com> | 2015-05-22 02:14:05 +0000 |
| commit | b47b9c2b2b97307ebd2426cd1761da89affb8d5b (patch) | |
| tree | 91da869a9a34c8a765eaad87e3326b3bd5b6c2df /llvm/lib | |
| parent | 2ecb8dc39c807554109d638ea2f1842ef73dda5e (diff) | |
| download | bcm5719-llvm-b47b9c2b2b97307ebd2426cd1761da89affb8d5b.tar.gz bcm5719-llvm-b47b9c2b2b97307ebd2426cd1761da89affb8d5b.zip | |
[LICM] Sinking doesn't involve the preheader
PR23608 pointed out that using the preheader to gain a context instruction isn't always legal because a loop might not have a preheader. When looking into that, I realized that using the preheader to determine legality for sinking is questionable at best. Given no test covers that case and the original commit didn't seem to intend it, I restructured the code to only ask context sensative queries for hoising of loads and stores. This is effectively a partial revert of 237593.
llvm-svn: 237985
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/LICM.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index b71fd56a66c..f0e6d641b18 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -84,7 +84,8 @@ static bool isSafeToExecuteUnconditionally(const Instruction &Inst, const DominatorTree *DT, const TargetLibraryInfo *TLI, const Loop *CurLoop, - const LICMSafetyInfo *SafetyInfo); + const LICMSafetyInfo *SafetyInfo, + const Instruction *CtxI = nullptr); static bool pointerInvalidatedByLoop(Value *V, uint64_t Size, const AAMDNodes &AAInfo, AliasSetTracker *CurAST); @@ -388,7 +389,8 @@ bool llvm::hoistRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI, // if (CurLoop->hasLoopInvariantOperands(&I) && canSinkOrHoistInst(I, AA, DT, TLI, CurLoop, CurAST, SafetyInfo) && - isSafeToExecuteUnconditionally(I, DT, TLI, CurLoop, SafetyInfo)) + isSafeToExecuteUnconditionally(I, DT, TLI, CurLoop, SafetyInfo, + CurLoop->getLoopPreheader()->getTerminator())) Changed |= hoist(I, CurLoop->getLoopPreheader()); } @@ -487,7 +489,11 @@ bool canSinkOrHoistInst(Instruction &I, AliasAnalysis *AA, DominatorTree *DT, !isa<InsertValueInst>(I)) return false; - return isSafeToExecuteUnconditionally(I, DT, TLI, CurLoop, SafetyInfo); + // TODO: Plumb the context instruction through to make hoisting and sinking + // more powerful. Hoisting of loads already works due to the special casing + // above. + return isSafeToExecuteUnconditionally(I, DT, TLI, CurLoop, SafetyInfo, + nullptr); } /// Returns true if a PHINode is a trivially replaceable with an @@ -647,8 +653,8 @@ static bool isSafeToExecuteUnconditionally(const Instruction &Inst, const DominatorTree *DT, const TargetLibraryInfo *TLI, const Loop *CurLoop, - const LICMSafetyInfo *SafetyInfo) { - const Instruction *CtxI = CurLoop->getLoopPreheader()->getTerminator(); + const LICMSafetyInfo *SafetyInfo, + const Instruction *CtxI) { if (isSafeToSpeculativelyExecute(&Inst, CtxI, DT, TLI)) return true; |

