diff options
author | Sebastian Pop <sebpop@gmail.com> | 2016-07-21 23:22:10 +0000 |
---|---|---|
committer | Sebastian Pop <sebpop@gmail.com> | 2016-07-21 23:22:10 +0000 |
commit | 31fd506623efc23e28be6909b5656eb7945e8bb3 (patch) | |
tree | 076a7317b3d6d9f5c9a1747125fc766d9ab0d952 /llvm/lib/Transforms/Scalar/GVNHoist.cpp | |
parent | 718734a3627602fb6c627c08751a87ad46e199af (diff) | |
download | bcm5719-llvm-31fd506623efc23e28be6909b5656eb7945e8bb3.tar.gz bcm5719-llvm-31fd506623efc23e28be6909b5656eb7945e8bb3.zip |
GVH-hoist: only clone GEPs (PR28606)
Do not clone stored values unless they are GEPs that are special cased to avoid
hoisting them without hoisting their associated ld/st.
Differential revision: https://reviews.llvm.org/D22652
llvm-svn: 276358
Diffstat (limited to 'llvm/lib/Transforms/Scalar/GVNHoist.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/GVNHoist.cpp | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/llvm/lib/Transforms/Scalar/GVNHoist.cpp b/llvm/lib/Transforms/Scalar/GVNHoist.cpp index cf2181b34eb..ad373ba542e 100644 --- a/llvm/lib/Transforms/Scalar/GVNHoist.cpp +++ b/llvm/lib/Transforms/Scalar/GVNHoist.cpp @@ -584,21 +584,14 @@ public: if (auto *St = dyn_cast<StoreInst>(Repl)) { Gep = dyn_cast<GetElementPtrInst>(St->getPointerOperand()); Val = dyn_cast<Instruction>(St->getValueOperand()); + // Check that the stored value is available. + if (Val && !isa<GetElementPtrInst>(Val) && + !DT->dominates(Val->getParent(), HoistPt)) + return false; } - if (!Gep) - return false; - - // PHIs may only be inserted at the start of a block. - if (Val && isa<PHINode>(Val)) - return false; - // Check whether we can compute the Gep at HoistPt. - if (!allOperandsAvailable(Gep, HoistPt)) - return false; - - // Also check that the stored value is available. - if (Val && !allOperandsAvailable(Val, HoistPt)) + if (!Gep || !allOperandsAvailable(Gep, HoistPt)) return false; // Copy the gep before moving the ld/st. @@ -618,8 +611,8 @@ public: } Repl->replaceUsesOfWith(Gep, ClonedGep); - // Also copy Val. - if (Val) { + // Also copy Val when it is a GEP. + if (Val && isa<GetElementPtrInst>(Val)) { Instruction *ClonedVal = Val->clone(); ClonedVal->insertBefore(HoistPt->getTerminator()); // Conservatively discard any optimization hints, they may differ on the |