forked from OSchip/llvm-project
[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.
This commit is contained in:
parent
428b2ffad4
commit
63844c116a
|
@ -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) {
|
||||
|
|
|
@ -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 }
|
||||
|
||||
@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
|
||||
}
|
Loading…
Reference in New Issue