summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/GVNHoist.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-07-21 07:16:26 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-07-21 07:16:26 +0000
commit825e4ab9e39ce2a3f115e19ecb09fd97c8a03432 (patch)
tree10cb599b6d3c280986e06877970a3acc9dc68a15 /llvm/lib/Transforms/Scalar/GVNHoist.cpp
parent903eefd1f22dfbbbf2443274d27ae93af60fd146 (diff)
downloadbcm5719-llvm-825e4ab9e39ce2a3f115e19ecb09fd97c8a03432.tar.gz
bcm5719-llvm-825e4ab9e39ce2a3f115e19ecb09fd97c8a03432.zip
[GVNHoist] Preserve optimization hints which agree
If we have optimization hints with agree with each other along different paths, preserve them. llvm-svn: 276248
Diffstat (limited to 'llvm/lib/Transforms/Scalar/GVNHoist.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/GVNHoist.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/GVNHoist.cpp b/llvm/lib/Transforms/Scalar/GVNHoist.cpp
index 9ca6ea04f4d..cf2181b34eb 100644
--- a/llvm/lib/Transforms/Scalar/GVNHoist.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNHoist.cpp
@@ -574,7 +574,8 @@ public:
llvm_unreachable("Both I and J must be from same BB");
}
- bool makeOperandsAvailable(Instruction *Repl, BasicBlock *HoistPt) const {
+ bool makeOperandsAvailable(Instruction *Repl, BasicBlock *HoistPt,
+ const SmallVecInsn &InstructionsToHoist) const {
// Check whether the GEP of a ld/st can be synthesized at HoistPt.
GetElementPtrInst *Gep = nullptr;
Instruction *Val = nullptr;
@@ -606,7 +607,15 @@ public:
// Conservatively discard any optimization hints, they may differ on the
// other paths.
ClonedGep->dropUnknownNonDebugMetadata();
- ClonedGep->clearSubclassOptionalData();
+ for (const Instruction *OtherInst : InstructionsToHoist) {
+ const GetElementPtrInst *OtherGep;
+ if (auto *OtherLd = dyn_cast<LoadInst>(OtherInst))
+ OtherGep = cast<GetElementPtrInst>(OtherLd->getPointerOperand());
+ else
+ OtherGep = cast<GetElementPtrInst>(
+ cast<StoreInst>(OtherInst)->getPointerOperand());
+ ClonedGep->intersectOptionalDataWith(OtherGep);
+ }
Repl->replaceUsesOfWith(Gep, ClonedGep);
// Also copy Val.
@@ -616,6 +625,11 @@ public:
// Conservatively discard any optimization hints, they may differ on the
// other paths.
ClonedVal->dropUnknownNonDebugMetadata();
+ for (const Instruction *OtherInst : InstructionsToHoist) {
+ const auto *OtherVal =
+ cast<Instruction>(cast<StoreInst>(OtherInst)->getValueOperand());
+ ClonedVal->intersectOptionalDataWith(OtherVal);
+ }
ClonedVal->clearSubclassOptionalData();
Repl->replaceUsesOfWith(Val, ClonedVal);
}
@@ -652,7 +666,7 @@ public:
// The order in which hoistings are done may influence the availability
// of operands.
if (!allOperandsAvailable(Repl, HoistPt) &&
- !makeOperandsAvailable(Repl, HoistPt))
+ !makeOperandsAvailable(Repl, HoistPt, InstructionsToHoist))
continue;
Repl->moveBefore(HoistPt->getTerminator());
// TBAA may differ on one of the other paths, we need to get rid of
OpenPOWER on IntegriCloud