xref: /llvm-project/llvm/test/Transforms/PhaseOrdering/simplifycfg-options.ll (revision 462cb3cd6cecd0511ecaf0e3ebcaba455ece587d)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -O1 -S < %s                    | FileCheck %s
3; RUN: opt -passes='default<O1>' -S < %s  | FileCheck %s
4
5; Don't simplify unconditional branches from empty blocks in simplifyCFG
6; until late in the pipeline because it can destroy canonical loop structure.
7
8define i1 @PR33605(i32 %a, i32 %b, ptr %c) {
9; CHECK-LABEL: @PR33605(
10; CHECK-NEXT:  entry:
11; CHECK-NEXT:    [[OR:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
12; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds nuw i8, ptr [[C:%.*]], i64 4
13; CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
14; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[OR]], [[TMP0]]
15; CHECK-NEXT:    br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
16; CHECK:       if.then:
17; CHECK-NEXT:    store i32 [[OR]], ptr [[ARRAYIDX]], align 4
18; CHECK-NEXT:    tail call void @foo()
19; CHECK-NEXT:    br label [[IF_END]]
20; CHECK:       if.end:
21; CHECK-NEXT:    [[TMP1:%.*]] = load i32, ptr [[C]], align 4
22; CHECK-NEXT:    [[CMP_1:%.*]] = icmp eq i32 [[OR]], [[TMP1]]
23; CHECK-NEXT:    br i1 [[CMP_1]], label [[IF_END_1:%.*]], label [[IF_THEN_1:%.*]]
24; CHECK:       if.then.1:
25; CHECK-NEXT:    store i32 [[OR]], ptr [[C]], align 4
26; CHECK-NEXT:    tail call void @foo()
27; CHECK-NEXT:    br label [[IF_END_1]]
28; CHECK:       if.end.1:
29; CHECK-NEXT:    [[CHANGED_1_OFF0_1:%.*]] = phi i1 [ true, [[IF_THEN_1]] ], [ [[CMP]], [[IF_END]] ]
30; CHECK-NEXT:    ret i1 [[CHANGED_1_OFF0_1]]
31;
32entry:
33  br label %for.cond
34
35for.cond:
36  %i.0 = phi i32 [ 2, %entry ], [ %dec, %if.end ]
37  %changed.0.off0 = phi i1 [ false, %entry ], [ %changed.1.off0, %if.end ]
38  %dec = add nsw i32 %i.0, -1
39  %tobool = icmp eq i32 %i.0, 0
40  br i1 %tobool, label %for.cond.cleanup, label %for.body
41
42for.cond.cleanup:
43  %changed.0.off0.lcssa = phi i1 [ %changed.0.off0, %for.cond ]
44  ret i1 %changed.0.off0.lcssa
45
46for.body:
47  %or = or i32 %a, %b
48  %idxprom = sext i32 %dec to i64
49  %arrayidx = getelementptr inbounds i32, ptr %c, i64 %idxprom
50  %0 = load i32, ptr %arrayidx, align 4
51  %cmp = icmp eq i32 %or, %0
52  br i1 %cmp, label %if.end, label %if.then
53
54if.then:
55  store i32 %or, ptr %arrayidx, align 4
56  call void @foo()
57  br label %if.end
58
59if.end:
60  %changed.1.off0 = phi i1 [ true, %if.then ], [ %changed.0.off0, %for.body ]
61  br label %for.cond
62}
63
64declare void @foo()
65
66; PR34603 - https://bugs.llvm.org/show_bug.cgi?id=34603
67; We should have a select of doubles, not a select of double pointers.
68; SimplifyCFG should not flatten this before early-cse has a chance to eliminate redundant ops.
69
70define double @max_of_loads(ptr %x, ptr %y, i64 %i) {
71; CHECK-LABEL: @max_of_loads(
72; CHECK-NEXT:  entry:
73; CHECK-NEXT:    [[XI_PTR:%.*]] = getelementptr double, ptr [[X:%.*]], i64 [[I:%.*]]
74; CHECK-NEXT:    [[YI_PTR:%.*]] = getelementptr double, ptr [[Y:%.*]], i64 [[I]]
75; CHECK-NEXT:    [[XI:%.*]] = load double, ptr [[XI_PTR]], align 8
76; CHECK-NEXT:    [[YI:%.*]] = load double, ptr [[YI_PTR]], align 8
77; CHECK-NEXT:    [[CMP:%.*]] = fcmp ogt double [[XI]], [[YI]]
78; CHECK-NEXT:    [[XI_YI:%.*]] = select i1 [[CMP]], double [[XI]], double [[YI]]
79; CHECK-NEXT:    ret double [[XI_YI]]
80;
81entry:
82  %xi_ptr = getelementptr double, ptr %x, i64 %i
83  %yi_ptr = getelementptr double, ptr %y, i64 %i
84  %xi = load double, ptr %xi_ptr
85  %yi = load double, ptr %yi_ptr
86  %cmp = fcmp ogt double %xi, %yi
87  br i1 %cmp, label %if, label %else
88
89if:
90  %xi_ptr_again = getelementptr double, ptr %x, i64 %i
91  %xi_again = load double, ptr %xi_ptr_again
92  br label %end
93
94else:
95  %yi_ptr_again = getelementptr double, ptr %y, i64 %i
96  %yi_again = load double, ptr %yi_ptr_again
97  br label %end
98
99end:
100  %max = phi double [ %xi_again,  %if ], [ %yi_again, %else ]
101  ret double %max
102}
103
104define i1 @PR58313(i1 %lhs, i1 %rhs) {
105; CHECK-LABEL: @PR58313(
106; CHECK-NEXT:  andandend:
107; CHECK-NEXT:    [[SPEC_SELECT:%.*]] = xor i1 [[LHS:%.*]], [[RHS:%.*]]
108; CHECK-NEXT:    ret i1 [[SPEC_SELECT]]
109;
110andandend:
111  %0 = xor i1 %rhs, true
112  %andandval = select i1 %lhs, i1 %0, i1 false
113  br i1 %andandval, label %ororend, label %oror
114
115oror:
116  %1 = xor i1 %lhs, true
117  %andandval3 = select i1 %1, i1 %rhs, i1 false
118  br label %ororend
119
120ororend:
121  %ororval = phi i1 [ true, %andandend ], [ %andandval3, %oror ]
122  ret i1 %ororval
123}
124
125