Skip to content

Commit 8693210

Browse files
committed
NewGVN: Make sure we don't incorrectly use PredicateInfo when doing PHI of ops
Summary: When we backtranslate expressions, we can't use the predicateinfo, since we are evaluating them in a different context. Reviewers: davide, mcrosier Subscribers: sanjoy, Prazek, llvm-commits Differential Revision: https://reviews.llvm.org/D37174 llvm-svn: 312352
1 parent 75557fa commit 8693210

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

llvm/lib/Transforms/Scalar/NewGVN.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,10 +1782,15 @@ const Expression *NewGVN::performSymbolicCmpEvaluation(Instruction *I) const {
17821782
if (PI == LastPredInfo)
17831783
continue;
17841784
LastPredInfo = PI;
1785-
1786-
// TODO: Along the false edge, we may know more things too, like icmp of
1785+
// In phi of ops cases, we may have predicate info that we are evaluating
1786+
// in a different context.
1787+
if (!DT->dominates(PBranch->To, getBlockForValue(I)))
1788+
continue;
1789+
// TODO: Along the false edge, we may know more things too, like
1790+
// icmp of
17871791
// same operands is false.
1788-
// TODO: We only handle actual comparison conditions below, not and/or.
1792+
// TODO: We only handle actual comparison conditions below, not
1793+
// and/or.
17891794
auto *BranchCond = dyn_cast<CmpInst>(PBranch->Condition);
17901795
if (!BranchCond)
17911796
continue;
@@ -2533,11 +2538,13 @@ NewGVN::makePossiblePhiOfOps(Instruction *I,
25332538
// and make sure anything that tries to add it's DFS number is
25342539
// redirected to the instruction we are making a phi of ops
25352540
// for.
2541+
TempToBlock.insert({ValueOp, PredBB});
25362542
InstrDFS.insert({ValueOp, IDFSNum});
25372543
const Expression *E = performSymbolicEvaluation(ValueOp, Visited);
25382544
InstrDFS.erase(ValueOp);
25392545
AllTempInstructions.erase(ValueOp);
25402546
ValueOp->deleteValue();
2547+
TempToBlock.erase(ValueOp);
25412548
if (MemAccess)
25422549
TempToMemory.erase(ValueOp);
25432550
if (!E)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -newgvn -enable-phi-of-ops=true -S | FileCheck %s
3+
;; Make sure we don't incorrectly use predicateinfo to simplify phi of ops cases
4+
source_filename = "pr34135.ll"
5+
6+
define void @snork(i32 %arg) {
7+
; CHECK-LABEL: @snork(
8+
; CHECK-NEXT: bb:
9+
; CHECK-NEXT: [[TMP:%.*]] = sext i32 [[ARG:%.*]] to i64
10+
; CHECK-NEXT: br label [[BB1:%.*]]
11+
; CHECK: bb1:
12+
; CHECK-NEXT: [[TMP2:%.*]] = phi i64 [ 0, [[BB:%.*]] ], [ [[TMP3:%.*]], [[BB1]] ]
13+
; CHECK-NEXT: [[TMP3]] = add i64 [[TMP2]], 1
14+
; CHECK-NEXT: [[TMP4:%.*]] = icmp slt i64 [[TMP3]], [[TMP]]
15+
; CHECK-NEXT: br i1 [[TMP4]], label [[BB1]], label [[BB7:%.*]]
16+
; CHECK: bb5:
17+
; CHECK-NEXT: [[TMP6:%.*]] = icmp sgt i64 [[TMP]], 1
18+
; CHECK-NEXT: br i1 [[TMP6]], label [[BB7]], label [[BB9:%.*]]
19+
; CHECK: bb7:
20+
; CHECK-NEXT: br label [[BB5:%.*]]
21+
; CHECK: bb9:
22+
; CHECK-NEXT: unreachable
23+
;
24+
bb:
25+
%tmp = sext i32 %arg to i64
26+
br label %bb1
27+
28+
bb1: ; preds = %bb1, %bb
29+
%tmp2 = phi i64 [ 0, %bb ], [ %tmp3, %bb1 ]
30+
%tmp3 = add i64 %tmp2, 1
31+
%tmp4 = icmp slt i64 %tmp3, %tmp
32+
br i1 %tmp4, label %bb1, label %bb7
33+
34+
bb5: ; preds = %bb7
35+
%tmp6 = icmp sgt i64 %tmp8, 1
36+
br i1 %tmp6, label %bb7, label %bb9
37+
38+
bb7: ; preds = %bb5, %bb1
39+
%tmp8 = phi i64 [ undef, %bb5 ], [ %tmp, %bb1 ]
40+
br label %bb5
41+
42+
bb9: ; preds = %bb5
43+
unreachable
44+
}

0 commit comments

Comments
 (0)