Skip to content

Commit 19cad46

Browse files
committed
Approved by Chris:
$ svn merge -c 113820 https://llvm.org/svn/llvm-project/llvm/trunk --- Merging r113820 into '.': U test/Transforms/LICM/crash.ll U lib/Transforms/Scalar/LICM.cpp Log: fix PR8102, a case where we'd copyValue from a value that we already deleted. Fix this by doing the copyValue's before we delete stuff! llvm-svn: 113823
1 parent 078d13e commit 19cad46

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,17 @@ void LICM::PromoteAliasSet(AliasSet &AS) {
852852
ReplacedLoads[ALoad] = NewVal;
853853
}
854854

855+
// If the preheader load is itself a pointer, we need to tell alias analysis
856+
// about the new pointer we created in the preheader block and about any PHI
857+
// nodes that just got inserted.
858+
if (PreheaderLoad->getType()->isPointerTy()) {
859+
// Copy any value stored to or loaded from a must-alias of the pointer.
860+
CurAST->copyValue(SomeValue, PreheaderLoad);
861+
862+
for (unsigned i = 0, e = NewPHIs.size(); i != e; ++i)
863+
CurAST->copyValue(SomeValue, NewPHIs[i]);
864+
}
865+
855866
// Now that everything is rewritten, delete the old instructions from the body
856867
// of the loop. They should all be dead now.
857868
for (unsigned i = 0, e = LoopUses.size(); i != e; ++i) {
@@ -882,17 +893,6 @@ void LICM::PromoteAliasSet(AliasSet &AS) {
882893
User->eraseFromParent();
883894
}
884895

885-
// If the preheader load is itself a pointer, we need to tell alias analysis
886-
// about the new pointer we created in the preheader block and about any PHI
887-
// nodes that just got inserted.
888-
if (PreheaderLoad->getType()->isPointerTy()) {
889-
// Copy any value stored to or loaded from a must-alias of the pointer.
890-
CurAST->copyValue(SomeValue, PreheaderLoad);
891-
892-
for (unsigned i = 0, e = NewPHIs.size(); i != e; ++i)
893-
CurAST->copyValue(SomeValue, NewPHIs[i]);
894-
}
895-
896896
// fwew, we're done!
897897
}
898898

llvm/test/Transforms/LICM/crash.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,23 @@ for.body: ; preds = %for.body, %entry
3939
store i32 undef, i32* @g_8, align 4
4040
br label %for.body
4141
}
42+
43+
; PR8102
44+
define void @test3() {
45+
entry:
46+
%__first = alloca { i32* }
47+
br i1 undef, label %for.cond, label %for.end
48+
49+
for.cond: ; preds = %for.cond, %entry
50+
%tmp1 = getelementptr { i32*}* %__first, i32 0, i32 0
51+
%tmp2 = load i32** %tmp1, align 4
52+
%call = tail call i32* @test3helper(i32* %tmp2)
53+
%tmp3 = getelementptr { i32*}* %__first, i32 0, i32 0
54+
store i32* %call, i32** %tmp3, align 4
55+
br i1 false, label %for.cond, label %for.end
56+
57+
for.end: ; preds = %for.cond, %entry
58+
ret void
59+
}
60+
61+
declare i32* @test3helper(i32*)

0 commit comments

Comments
 (0)