Skip to content

Commit 4e83e59

Browse files
committed
[GVN] Add missing ICF update
performScalarPREInsertion() inserts instructions into blocks that we need to tell ImplicitControlFlowTracking about, otherwise the ICF cache may be invalid. Fixes PR49193. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D99909
1 parent 801cea2 commit 4e83e59

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,6 +2466,8 @@ bool GVN::performScalarPREInsertion(Instruction *Instr, BasicBlock *Pred,
24662466
Instr->setName(Instr->getName() + ".pre");
24672467
Instr->setDebugLoc(Instr->getDebugLoc());
24682468

2469+
ICF->insertInstructionTo(Instr, Pred);
2470+
24692471
unsigned Num = VN.lookupOrAdd(Instr);
24702472
VN.add(Instr, Num);
24712473

llvm/test/Transforms/GVN/pr49193.ll

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
; RUN: opt -passes=gvn -S < %s | FileCheck %s
2+
3+
@a = external local_unnamed_addr global i32, align 4
4+
@b = external local_unnamed_addr global i32, align 4
5+
6+
; Function Attrs: nounwind readnone
7+
declare i32* @j() local_unnamed_addr #0
8+
9+
; CHECK: define {{.*}}@k()
10+
11+
define i64 @k() local_unnamed_addr {
12+
bb:
13+
br i1 undef, label %bb10.preheader, label %bb3
14+
15+
bb10.preheader: ; preds = %bb
16+
br label %bb13
17+
18+
bb3: ; preds = %bb
19+
%i4 = load i32, i32* @a, align 4
20+
%i5.not = icmp eq i32 %i4, 0
21+
br label %bb7
22+
23+
bb7: ; preds = %bb3
24+
%i8 = tail call i32* @j()
25+
br label %bb37
26+
27+
bb13: ; preds = %bb34, %bb10.preheader
28+
br i1 undef, label %bb30thread-pre-split, label %bb16
29+
30+
bb16: ; preds = %bb13
31+
%i17 = tail call i32* @j()
32+
br i1 undef, label %bb22thread-pre-split, label %bb37.loopexit
33+
34+
bb22thread-pre-split: ; preds = %bb16
35+
br label %bb27
36+
37+
bb27: ; preds = %bb22thread-pre-split
38+
br i1 undef, label %bb30thread-pre-split, label %bb37.loopexit
39+
40+
bb30thread-pre-split: ; preds = %bb27, %bb13
41+
%i31.pr = load i32, i32* @a, align 4
42+
%i32.not2 = icmp eq i32 %i31.pr, 0
43+
br label %bb34
44+
45+
bb34: ; preds = %bb30thread-pre-split
46+
br i1 undef, label %bb37.loopexit, label %bb13
47+
48+
bb37.loopexit: ; preds = %bb34, %bb27, %bb16
49+
br label %bb37
50+
51+
bb37: ; preds = %bb37.loopexit, %bb7
52+
%i38 = load i32, i32* @a, align 4
53+
store i32 %i38, i32* @b, align 4
54+
%i39 = tail call i32* @j()
55+
unreachable
56+
}
57+
58+
attributes #0 = { nounwind readnone }

0 commit comments

Comments
 (0)