[llvm] a0f627d - [IndVarSimplify] Fix for MemorySSA preserve.
Alina Sbirlea via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 23 11:06:58 PST 2020
Author: Alina Sbirlea
Date: 2020-01-23T11:06:16-08:00
New Revision: a0f627d58428efba18dbf882b1ff34764e439e59
URL: https://github.com/llvm/llvm-project/commit/a0f627d58428efba18dbf882b1ff34764e439e59
DIFF: https://github.com/llvm/llvm-project/commit/a0f627d58428efba18dbf882b1ff34764e439e59.diff
LOG: [IndVarSimplify] Fix for MemorySSA preserve.
Added:
llvm/test/Transforms/IndVarSimplify/preserve-memoryssa.ll
Modified:
llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
llvm/include/llvm/Transforms/Utils/Local.h
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
llvm/lib/Transforms/Utils/Local.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
index dec8447c9f52..f87bee5a6c83 100644
--- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
@@ -79,7 +79,8 @@ void FoldSingleEntryPHINodes(BasicBlock *BB,
/// recursively delete any operands that become dead as a result. This includes
/// tracing the def-use list from the PHI to see if it is ultimately unused or
/// if it reaches an unused cycle. Return true if any PHIs were deleted.
-bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI = nullptr);
+bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI = nullptr,
+ MemorySSAUpdater *MSSAU = nullptr);
/// Attempts to merge a block into its predecessor, if possible. The return
/// value indicates success or failure.
diff --git a/llvm/include/llvm/Transforms/Utils/Local.h b/llvm/include/llvm/Transforms/Utils/Local.h
index d1dc0b3e46b9..be619d74da33 100644
--- a/llvm/include/llvm/Transforms/Utils/Local.h
+++ b/llvm/include/llvm/Transforms/Utils/Local.h
@@ -162,7 +162,8 @@ void RecursivelyDeleteTriviallyDeadInstructions(
/// operands trivially dead, delete them too, recursively. Return true if a
/// change was made.
bool RecursivelyDeleteDeadPHINode(PHINode *PN,
- const TargetLibraryInfo *TLI = nullptr);
+ const TargetLibraryInfo *TLI = nullptr,
+ MemorySSAUpdater *MSSAU = nullptr);
/// Scan the specified basic block and try to simplify any instructions in it
/// and recursively delete dead instructions.
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index 89373be3887c..210f6bcfdc93 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -2781,7 +2781,8 @@ bool IndVarSimplify::run(Loop *L) {
while (!DeadInsts.empty())
if (Instruction *Inst =
dyn_cast_or_null<Instruction>(DeadInsts.pop_back_val()))
- Changed |= RecursivelyDeleteTriviallyDeadInstructions(Inst, TLI);
+ Changed |=
+ RecursivelyDeleteTriviallyDeadInstructions(Inst, TLI, MSSAU.get());
// The Rewriter may not be used from this point on.
@@ -2795,7 +2796,7 @@ bool IndVarSimplify::run(Loop *L) {
Changed |= rewriteFirstIterationLoopExitValues(L);
// Clean up dead instructions.
- Changed |= DeleteDeadPHIs(L->getHeader(), TLI);
+ Changed |= DeleteDeadPHIs(L->getHeader(), TLI, MSSAU.get());
// Check a post-condition.
assert(L->isRecursivelyLCSSAForm(*DT, *LI) &&
@@ -2818,6 +2819,8 @@ bool IndVarSimplify::run(Loop *L) {
assert(!SE->isKnownPredicate(ICmpInst::ICMP_ULT, BackedgeTakenCount,
NewBECount) && "indvars must preserve SCEV");
}
+ if (VerifyMemorySSA && MSSAU)
+ MSSAU->getMemorySSA()->verifyMemorySSA();
#endif
return Changed;
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index c9eb4abfa21a..19b926d79049 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -153,7 +153,8 @@ void llvm::FoldSingleEntryPHINodes(BasicBlock *BB,
}
}
-bool llvm::DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI) {
+bool llvm::DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI,
+ MemorySSAUpdater *MSSAU) {
// Recursively deleting a PHI may cause multiple PHIs to be deleted
// or RAUW'd undef, so use an array of WeakTrackingVH for the PHIs to delete.
SmallVector<WeakTrackingVH, 8> PHIs;
@@ -163,7 +164,7 @@ bool llvm::DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI) {
bool Changed = false;
for (unsigned i = 0, e = PHIs.size(); i != e; ++i)
if (PHINode *PN = dyn_cast_or_null<PHINode>(PHIs[i].operator Value*()))
- Changed |= RecursivelyDeleteDeadPHINode(PN, TLI);
+ Changed |= RecursivelyDeleteDeadPHINode(PN, TLI, MSSAU);
return Changed;
}
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index b2d511c7c9a9..5b188fc4385d 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -521,19 +521,20 @@ static bool areAllUsesEqual(Instruction *I) {
/// delete it. If that makes any of its operands trivially dead, delete them
/// too, recursively. Return true if a change was made.
bool llvm::RecursivelyDeleteDeadPHINode(PHINode *PN,
- const TargetLibraryInfo *TLI) {
+ const TargetLibraryInfo *TLI,
+ llvm::MemorySSAUpdater *MSSAU) {
SmallPtrSet<Instruction*, 4> Visited;
for (Instruction *I = PN; areAllUsesEqual(I) && !I->mayHaveSideEffects();
I = cast<Instruction>(*I->user_begin())) {
if (I->use_empty())
- return RecursivelyDeleteTriviallyDeadInstructions(I, TLI);
+ return RecursivelyDeleteTriviallyDeadInstructions(I, TLI, MSSAU);
// If we find an instruction more than once, we're on a cycle that
// won't prove fruitful.
if (!Visited.insert(I).second) {
// Break the cycle and delete the instruction and its operands.
I->replaceAllUsesWith(UndefValue::get(I->getType()));
- (void)RecursivelyDeleteTriviallyDeadInstructions(I, TLI);
+ (void)RecursivelyDeleteTriviallyDeadInstructions(I, TLI, MSSAU);
return true;
}
}
diff --git a/llvm/test/Transforms/IndVarSimplify/preserve-memoryssa.ll b/llvm/test/Transforms/IndVarSimplify/preserve-memoryssa.ll
new file mode 100644
index 000000000000..dcbad54eb404
--- /dev/null
+++ b/llvm/test/Transforms/IndVarSimplify/preserve-memoryssa.ll
@@ -0,0 +1,21 @@
+; RUN: opt -S -licm -indvars -verify-memoryssa < %s | FileCheck %s
+; REQUIRES: asserts
+ at v_69 = external constant { i16, i16 }, align 1
+
+; CHECK-LABEL: @f()
+define void @f() {
+entry:
+ br label %for.cond26
+
+for.cond26: ; preds = %for.body28, %entry
+ br i1 true, label %for.body28, label %for.cond.cleanup27
+
+for.cond.cleanup27: ; preds = %for.cond26
+ unreachable
+
+for.body28: ; preds = %for.cond26
+ %v_69.imag = load volatile i16, i16* getelementptr inbounds ({ i16, i16 }, { i16, i16 }* @v_69, i32 0, i32 1), align 1
+ %.real42 = load i32, i32* undef, align 1
+ store i32 %.real42, i32* undef, align 1
+ br label %for.cond26
+}
More information about the llvm-commits
mailing list