[llvm] 63844c1 - [MemorySSA] Clean up single value phis.
Alina Sbirlea via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 31 19:26:42 PDT 2020
Author: Alina Sbirlea
Date: 2020-08-31T19:26:08-07:00
New Revision: 63844c116a0acf8a75ebe4ed6f25fced3c655710
URL: https://github.com/llvm/llvm-project/commit/63844c116a0acf8a75ebe4ed6f25fced3c655710
DIFF: https://github.com/llvm/llvm-project/commit/63844c116a0acf8a75ebe4ed6f25fced3c655710.diff
LOG: [MemorySSA] Clean up single value phis.
MemoryPhis with a single value are correct, but can lead to errors when
updating. Clean up single entry Phis newly added when cloning blocks.
Resolves PR46574.
Added:
llvm/test/Analysis/MemorySSA/pr46574.ll
Modified:
llvm/lib/Analysis/MemorySSAUpdater.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp
index 1de562fd7f31..671d9e60ab7a 100644
--- a/llvm/lib/Analysis/MemorySSAUpdater.cpp
+++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp
@@ -543,6 +543,20 @@ void MemorySSAUpdater::removeDuplicatePhiEdgesBetween(const BasicBlock *From,
}
}
+/// If all arguments of a MemoryPHI are defined by the same incoming
+/// argument, return that argument.
+static MemoryAccess *onlySingleValue(MemoryPhi *MP) {
+ MemoryAccess *MA = nullptr;
+
+ for (auto &Arg : MP->operands()) {
+ if (!MA)
+ MA = cast<MemoryAccess>(Arg);
+ else if (MA != Arg)
+ return nullptr;
+ }
+ return MA;
+}
+
static MemoryAccess *getNewDefiningAccessForClone(MemoryAccess *MA,
const ValueToValueMapTy &VMap,
PhiToDefMap &MPhiMap,
@@ -699,6 +713,10 @@ void MemorySSAUpdater::updateForClonedLoop(const LoopBlocksRPO &LoopBlocks,
NewPhi->addIncoming(IncPhi, IncBB);
}
}
+ if (onlySingleValue(NewPhi)) {
+ MPhiMap[Phi] = nullptr;
+ removeMemoryAccess(NewPhi);
+ }
};
auto ProcessBlock = [&](BasicBlock *BB) {
@@ -1231,20 +1249,6 @@ void MemorySSAUpdater::moveAllAfterMergeBlocks(BasicBlock *From, BasicBlock *To,
MPhi->setIncomingBlock(MPhi->getBasicBlockIndex(From), To);
}
-/// If all arguments of a MemoryPHI are defined by the same incoming
-/// argument, return that argument.
-static MemoryAccess *onlySingleValue(MemoryPhi *MP) {
- MemoryAccess *MA = nullptr;
-
- for (auto &Arg : MP->operands()) {
- if (!MA)
- MA = cast<MemoryAccess>(Arg);
- else if (MA != Arg)
- return nullptr;
- }
- return MA;
-}
-
void MemorySSAUpdater::wireOldPredecessorsToNewImmediatePredecessor(
BasicBlock *Old, BasicBlock *New, ArrayRef<BasicBlock *> Preds,
bool IdenticalEdgesWereMerged) {
diff --git a/llvm/test/Analysis/MemorySSA/pr46574.ll b/llvm/test/Analysis/MemorySSA/pr46574.ll
new file mode 100644
index 000000000000..4e107478ab50
--- /dev/null
+++ b/llvm/test/Analysis/MemorySSA/pr46574.ll
@@ -0,0 +1,33 @@
+; RUN: opt -loop-instsimplify -loop-simplifycfg -licm -simple-loop-unswitch -enable-nontrivial-unswitch %s -disable-output
+; REQUIRES: asserts
+
+%0 = type { i24, i32, i32, i8 }
+
+ at g_1077 = external dso_local local_unnamed_addr global [4 x [3 x [2 x { i8, i8, i8, i8, i8, i8, i8, i8, i32 }]]], align 4
+
+define void @func_22() {
+bb:
+ br label %bb13
+
+bb13: ; preds = %bb38, %bb31, %bb
+ %i15 = load i32, i32* undef, align 4
+ %i16 = trunc i32 %i15 to i8
+ %i18 = load %0*, %0** undef, align 8
+ %i19 = icmp eq %0* %i18, null
+ br i1 %i19, label %bb31, label %safe_mod_func_uint8_t_u_u.exit
+
+bb31: ; preds = %bb13
+ %i25 = load i8, i8* getelementptr inbounds ([4 x [3 x [2 x { i8, i8, i8, i8, i8, i8, i8, i8, i32 }]]], [4 x [3 x [2 x { i8, i8, i8, i8, i8, i8, i8, i8, i32 }]]]* @g_1077, i64 0, i64 2, i64 2, i64 1, i32 6), align 2
+ %i28 = or i8 %i25, %i16
+ store i8 %i28, i8* getelementptr inbounds ([4 x [3 x [2 x { i8, i8, i8, i8, i8, i8, i8, i8, i32 }]]], [4 x [3 x [2 x { i8, i8, i8, i8, i8, i8, i8, i8, i32 }]]]* @g_1077, i64 0, i64 2, i64 2, i64 1, i32 6), align 2
+ %i30 = icmp ne i8 %i28, 0
+ %i37.not = icmp eq i8 %i16, 0
+ %or.cond = or i1 %i37.not, %i30
+ br i1 %or.cond, label %bb13, label %bb38
+
+safe_mod_func_uint8_t_u_u.exit: ; preds = %bb13
+ br label %bb38
+
+bb38: ; preds = %safe_mod_func_uint8_t_u_u.exit, %bb31
+ br label %bb13
+}
More information about the llvm-commits
mailing list