• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -instcombine -S < %s | FileCheck %s
3; RUN: opt -passes=instcombine -S < %s | FileCheck %s
4
5; Check that we fold the condition of branches of the
6; form: br <condition> dest1, dest2, where dest1 == dest2.
7define i32 @test(i32 %x) {
8; CHECK-LABEL: @test(
9; CHECK-NEXT:  entry:
10; CHECK-NEXT:    br i1 false, label [[MERGE:%.*]], label [[MERGE]]
11; CHECK:       merge:
12; CHECK-NEXT:    ret i32 [[X:%.*]]
13;
14entry:
15  %cmp = icmp ult i32 %x, 7
16  br i1 %cmp, label %merge, label %merge
17merge:
18  ret i32 %x
19}
20
21@global = global i8 0
22
23define i32 @pat(i32 %x) {
24; CHECK-LABEL: @pat(
25; CHECK-NEXT:    br i1 false, label [[PATATINO:%.*]], label [[PATATINO]]
26; CHECK:       patatino:
27; CHECK-NEXT:    ret i32 [[X:%.*]]
28;
29  %y = icmp eq i32 27, ptrtoint(i8* @global to i32)
30  br i1 %y, label %patatino, label %patatino
31patatino:
32  ret i32 %x
33}
34
35define i1 @test01(i1 %cond) {
36; CHECK-LABEL: @test01(
37; CHECK-NEXT:  entry:
38; CHECK-NEXT:    br i1 [[COND:%.*]], label [[IF_TRUE_1:%.*]], label [[IF_FALSE_1:%.*]]
39; CHECK:       if.true.1:
40; CHECK-NEXT:    br label [[MERGE_1:%.*]]
41; CHECK:       if.false.1:
42; CHECK-NEXT:    br label [[MERGE_1]]
43; CHECK:       merge.1:
44; CHECK-NEXT:    br i1 [[COND]], label [[IF_TRUE_2:%.*]], label [[IF_FALSE_2:%.*]]
45; CHECK:       if.true.2:
46; CHECK-NEXT:    br label [[MERGE_2:%.*]]
47; CHECK:       if.false.2:
48; CHECK-NEXT:    br label [[MERGE_2]]
49; CHECK:       merge.2:
50; CHECK-NEXT:    ret i1 [[COND]]
51;
52entry:
53  br i1 %cond, label %if.true.1, label %if.false.1
54
55if.true.1:
56  br label %merge.1
57
58if.false.1:
59  br label  %merge.1
60
61merge.1:
62  %merge.cond.1 = phi i1 [true, %if.true.1], [false, %if.false.1]
63  br i1 %merge.cond.1, label %if.true.2, label %if.false.2
64
65if.true.2:
66  br label %merge.2
67
68if.false.2:
69  br label  %merge.2
70
71merge.2:
72  %merge.cond.2 = phi i1 [true, %if.true.2], [false, %if.false.2]
73  ret i1 %merge.cond.2
74}
75
76define i1 @test02(i1 %cond) {
77; CHECK-LABEL: @test02(
78; CHECK-NEXT:  entry:
79; CHECK-NEXT:    br i1 [[COND:%.*]], label [[IF_TRUE_1:%.*]], label [[IF_FALSE_1:%.*]]
80; CHECK:       if.true.1:
81; CHECK-NEXT:    br label [[MERGE_1:%.*]]
82; CHECK:       if.false.1:
83; CHECK-NEXT:    br label [[MERGE_1]]
84; CHECK:       merge.1:
85; CHECK-NEXT:    br i1 [[COND]], label [[IF_FALSE_2:%.*]], label [[IF_TRUE_2:%.*]]
86; CHECK:       if.true.2:
87; CHECK-NEXT:    br label [[MERGE_2:%.*]]
88; CHECK:       if.false.2:
89; CHECK-NEXT:    br label [[MERGE_2]]
90; CHECK:       merge.2:
91; CHECK-NEXT:    ret i1 [[COND]]
92;
93entry:
94  br i1 %cond, label %if.true.1, label %if.false.1
95
96if.true.1:
97  br label %merge.1
98
99if.false.1:
100  br label  %merge.1
101
102merge.1:
103  %merge.cond.1 = phi i1 [false, %if.true.1], [true, %if.false.1]
104  br i1 %merge.cond.1, label %if.true.2, label %if.false.2
105
106if.true.2:
107  br label %merge.2
108
109if.false.2:
110  br label  %merge.2
111
112merge.2:
113  %merge.cond.2 = phi i1 [false, %if.true.2], [true, %if.false.2]
114  ret i1 %merge.cond.2
115}
116