diff options
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
-rw-r--r-- | llvm/lib/Transforms/Scalar/GVNHoist.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Scalar/GVNHoist.cpp b/llvm/lib/Transforms/Scalar/GVNHoist.cpp index 0b5e94f8fb9..194405ded55 100644 --- a/llvm/lib/Transforms/Scalar/GVNHoist.cpp +++ b/llvm/lib/Transforms/Scalar/GVNHoist.cpp @@ -23,6 +23,7 @@ #include "llvm/Analysis/ValueTracking.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar/GVN.h" +#include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/MemorySSA.h" using namespace llvm; @@ -172,6 +173,15 @@ typedef DenseMap<const BasicBlock *, bool> BBSideEffectsSet; typedef SmallVector<Instruction *, 4> SmallVecInsn; typedef SmallVectorImpl<Instruction *> SmallVecImplInsn; +static void combineKnownMetadata(Instruction *ReplInst, Instruction *I) { + static const unsigned KnownIDs[] = { + LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope, + LLVMContext::MD_noalias, LLVMContext::MD_range, + LLVMContext::MD_fpmath, LLVMContext::MD_invariant_load, + LLVMContext::MD_invariant_group}; + combineMetadata(ReplInst, I, KnownIDs); +} + // This pass hoists common computations across branches sharing common // dominator. The primary goal is to reduce the code size, and in some // cases reduce critical path (by exposing more ILP). @@ -604,15 +614,15 @@ public: ClonedGep->insertBefore(HoistPt->getTerminator()); // Conservatively discard any optimization hints, they may differ on the // other paths. - ClonedGep->dropUnknownNonDebugMetadata(); - for (const Instruction *OtherInst : InstructionsToHoist) { - const GetElementPtrInst *OtherGep; + for (Instruction *OtherInst : InstructionsToHoist) { + 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); + combineKnownMetadata(ClonedGep, OtherGep); } Repl->replaceUsesOfWith(Gep, ClonedGep); @@ -622,11 +632,11 @@ public: ClonedVal->insertBefore(HoistPt->getTerminator()); // Conservatively discard any optimization hints, they may differ on the // other paths. - ClonedVal->dropUnknownNonDebugMetadata(); - for (const Instruction *OtherInst : InstructionsToHoist) { - const auto *OtherVal = + for (Instruction *OtherInst : InstructionsToHoist) { + auto *OtherVal = cast<Instruction>(cast<StoreInst>(OtherInst)->getValueOperand()); ClonedVal->intersectOptionalDataWith(OtherVal); + combineKnownMetadata(ClonedVal, OtherVal); } Repl->replaceUsesOfWith(Val, ClonedVal); } @@ -668,7 +678,6 @@ public: Repl->moveBefore(HoistPt->getTerminator()); // TBAA may differ on one of the other paths, we need to get rid of // anything which might conflict. - Repl->dropUnknownNonDebugMetadata(); } if (isa<LoadInst>(Repl)) @@ -702,6 +711,7 @@ public: ++NumCallsRemoved; } Repl->intersectOptionalDataWith(I); + combineKnownMetadata(Repl, I); I->replaceAllUsesWith(Repl); I->eraseFromParent(); } |