File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed
lib/Transforms/InstCombine
test/Transforms/InstCombine Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -3753,7 +3753,9 @@ Instruction *InstCombinerImpl::visitBranchInst(BranchInst &BI) {
3753
3753
}
3754
3754
3755
3755
// Replace all dominated uses of the condition with true/false
3756
- if (BI.getSuccessor (0 ) != BI.getSuccessor (1 )) {
3756
+ // Ignore constant expressions to avoid iterating over uses on other
3757
+ // functions.
3758
+ if (!isa<Constant>(Cond) && BI.getSuccessor (0 ) != BI.getSuccessor (1 )) {
3757
3759
for (auto &U : make_early_inc_range (Cond->uses ())) {
3758
3760
BasicBlockEdge Edge0 (BI.getParent (), BI.getSuccessor (0 ));
3759
3761
if (DT.dominates (Edge0, U)) {
Original file line number Diff line number Diff line change
1
+ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2
+ ; RUN: opt -S -passes=instcombine < %s | FileCheck %s
3
+
4
+ ; Make sure we don't crash in this case.
5
+ @g = global i32 0
6
+
7
+ define i1 @foo () {
8
+ ; CHECK-LABEL: define i1 @foo() {
9
+ ; CHECK-NEXT: [[ENTRY:.*:]]
10
+ ; CHECK-NEXT: br i1 ptrtoint (ptr @g to i1), label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
11
+ ; CHECK: [[IF_THEN]]:
12
+ ; CHECK-NEXT: ret i1 true
13
+ ; CHECK: [[IF_ELSE]]:
14
+ ; CHECK-NEXT: ret i1 false
15
+ ;
16
+ entry:
17
+ br i1 ptrtoint (ptr @g to i1 ), label %if.then , label %if.else
18
+
19
+ if.then:
20
+ ret i1 true
21
+
22
+ if.else:
23
+ ret i1 false
24
+ }
25
+
26
+ define i1 @bar () {
27
+ ; CHECK-LABEL: define i1 @bar() {
28
+ ; CHECK-NEXT: [[ENTRY:.*:]]
29
+ ; CHECK-NEXT: br i1 ptrtoint (ptr @g to i1), label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
30
+ ; CHECK: [[IF_THEN]]:
31
+ ; CHECK-NEXT: ret i1 true
32
+ ; CHECK: [[IF_ELSE]]:
33
+ ; CHECK-NEXT: ret i1 false
34
+ ;
35
+ entry:
36
+ br i1 ptrtoint (ptr @g to i1 ), label %if.then , label %if.else
37
+
38
+ if.then:
39
+ ret i1 true
40
+
41
+ if.else:
42
+ ret i1 false
43
+ }
You can’t perform that action at this time.
0 commit comments