Skip to content

Commit 9d020de

Browse files
committed
[PredicateInfo] Do not process unreachable operands.
Summary: We should excluded unreachable operands from processing as their DFS visitation order is undefined. When `renameUses` function sorts `OpsToRename` (https://fburl.com/d2wubn60), the comparator assumes that the parent block of the operand has a corresponding dominator tree node. This is not the case for unreachable operands and crashes the compiler. Reviewers: dberlin, mgrang, davide Subscribers: efriedma, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61154 llvm-svn: 360796
1 parent e8a039d commit 9d020de

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

llvm/lib/Transforms/Utils/PredicateInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ void PredicateInfo::buildPredicateInfo() {
473473
}
474474
for (auto &Assume : AC.assumptions()) {
475475
if (auto *II = dyn_cast_or_null<IntrinsicInst>(Assume))
476-
processAssume(II, II->getParent(), OpsToRename);
476+
if (DT.isReachableFromEntry(II->getParent()))
477+
processAssume(II, II->getParent(), OpsToRename);
477478
}
478479
// Now rename all our operations.
479480
renameUses(OpsToRename);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; RUN: opt -print-predicateinfo < %s 2>&1 | FileCheck %s
2+
3+
declare void @foo()
4+
declare void @llvm.assume(i1)
5+
6+
define void @bar(i32* %p) {
7+
entry:
8+
; CHECK-LABEL: @bar
9+
br label %end
10+
11+
unreachable1:
12+
%v1 = load i32, i32* %p, align 4
13+
%c1 = icmp eq i32 %v1, 0
14+
call void @llvm.assume(i1 %c1)
15+
br label %unreachable2
16+
17+
unreachable2:
18+
%v2 = load i32, i32* %p, align 4
19+
%c2 = icmp eq i32 %v2, 0
20+
call void @llvm.assume(i1 %c2)
21+
br label %end
22+
23+
end:
24+
ret void
25+
}

0 commit comments

Comments
 (0)