summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/GVNHoist.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Scalar/GVNHoist.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/GVNHoist.cpp21
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
OpenPOWER on IntegriCloud