Skip to content

Commit 6345202

Browse files
committed
[ConstraintElimination] Remove over-eager assertion.
After moving the CanAdd check in c60cdb4 and using it for the assume cases as well, the passed in block may not have a branch instruction as terminator. This can trigger the assertion. Given the new use case, it doesn't add value any longer and can be removed. Fixes llvm#54281
1 parent 260379f commit 6345202

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
275275
// Succ (e.g. the case when adding a condition from a pre-header to a loop
276276
// header).
277277
auto CanAdd = [&BB, &DT](BasicBlock *Succ) {
278-
assert(isa<BranchInst>(BB.getTerminator()));
279278
return any_of(successors(&BB),
280279
[Succ](const BasicBlock *S) { return S != Succ; }) &&
281280
all_of(predecessors(Succ), [&BB, &DT, Succ](BasicBlock *Pred) {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
3+
4+
declare void @may_unwind()
5+
6+
declare i32 @__gxx_personality_v0(...);
7+
8+
define i1 @test_invoke_in_block_with_assume(i32 %x) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
9+
; CHECK-LABEL: @test_invoke_in_block_with_assume(
10+
; CHECK-NEXT: entry:
11+
; CHECK-NEXT: call void @may_unwind()
12+
; CHECK-NEXT: [[C_1:%.*]] = icmp ult i32 [[X:%.*]], 10
13+
; CHECK-NEXT: call void @llvm.assume(i1 [[C_1]])
14+
; CHECK-NEXT: invoke void @may_unwind()
15+
; CHECK-NEXT: to label [[CONT:%.*]] unwind label [[LPAD:%.*]]
16+
; CHECK: cont:
17+
; CHECK-NEXT: [[T_1:%.*]] = icmp ult i32 [[X]], 10
18+
; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[X]], 9
19+
; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, [[C_2]]
20+
; CHECK-NEXT: ret i1 [[RES_1]]
21+
; CHECK: lpad:
22+
; CHECK-NEXT: [[LP:%.*]] = landingpad { i8*, i32 }
23+
; CHECK-NEXT: filter [0 x i8*] zeroinitializer
24+
; CHECK-NEXT: [[T_2:%.*]] = icmp ult i32 [[X]], 10
25+
; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[X]], 9
26+
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 true, [[C_3]]
27+
; CHECK-NEXT: ret i1 [[RES_2]]
28+
;
29+
entry:
30+
call void @may_unwind()
31+
%c.1 = icmp ult i32 %x, 10
32+
call void @llvm.assume(i1 %c.1)
33+
invoke void @may_unwind() to label %cont unwind label %lpad
34+
35+
cont:
36+
%t.1 = icmp ult i32 %x, 10
37+
%c.2 = icmp ult i32 %x, 9
38+
%res.1 = xor i1 %t.1, %c.2
39+
ret i1 %res.1
40+
41+
lpad:
42+
%lp = landingpad { i8*, i32 }
43+
filter [0 x i8*] zeroinitializer
44+
%t.2 = icmp ult i32 %x, 10
45+
%c.3 = icmp ult i32 %x, 9
46+
%res.2 = xor i1 %t.2, %c.3
47+
ret i1 %res.2
48+
}
49+
50+
declare void @llvm.assume(i1)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
3+
4+
declare void @may_unwind()
5+
6+
define i1 @test_switch_in_block_with_assume(i32 %x) {
7+
; CHECK-LABEL: @test_switch_in_block_with_assume(
8+
; CHECK-NEXT: entry:
9+
; CHECK-NEXT: call void @may_unwind()
10+
; CHECK-NEXT: [[C_1:%.*]] = icmp ult i32 [[X:%.*]], 10
11+
; CHECK-NEXT: call void @llvm.assume(i1 [[C_1]])
12+
; CHECK-NEXT: switch i32 0, label [[EXIT_1:%.*]] [
13+
; CHECK-NEXT: i32 1, label [[EXIT_2:%.*]]
14+
; CHECK-NEXT: ]
15+
; CHECK: exit.1:
16+
; CHECK-NEXT: [[T_1:%.*]] = icmp ult i32 [[X]], 10
17+
; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[X]], 9
18+
; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, [[C_2]]
19+
; CHECK-NEXT: ret i1 [[RES_1]]
20+
; CHECK: exit.2:
21+
; CHECK-NEXT: [[T_2:%.*]] = icmp ult i32 [[X]], 10
22+
; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[X]], 9
23+
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 true, [[C_3]]
24+
; CHECK-NEXT: ret i1 [[RES_2]]
25+
;
26+
entry:
27+
call void @may_unwind()
28+
%c.1 = icmp ult i32 %x, 10
29+
call void @llvm.assume(i1 %c.1)
30+
switch i32 0, label %exit.1 [
31+
i32 1, label %exit.2
32+
]
33+
34+
exit.1:
35+
%t.1 = icmp ult i32 %x, 10
36+
%c.2 = icmp ult i32 %x, 9
37+
%res.1 = xor i1 %t.1, %c.2
38+
ret i1 %res.1
39+
40+
exit.2:
41+
%t.2 = icmp ult i32 %x, 10
42+
%c.3 = icmp ult i32 %x, 9
43+
%res.2 = xor i1 %t.2, %c.3
44+
ret i1 %res.2
45+
}
46+
47+
declare void @llvm.assume(i1)

0 commit comments

Comments
 (0)