xref: /aosp_15_r20/external/llvm/test/Transforms/SCCP/undef-resolve.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt -sccp -S < %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Worker; PR6940
5*9880d681SAndroid Build Coastguard Workerdefine double @test1() {
6*9880d681SAndroid Build Coastguard Worker  %t = sitofp i32 undef to double
7*9880d681SAndroid Build Coastguard Worker  ret double %t
8*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test1(
9*9880d681SAndroid Build Coastguard Worker; CHECK: ret double 0.0
10*9880d681SAndroid Build Coastguard Worker}
11*9880d681SAndroid Build Coastguard Worker
12*9880d681SAndroid Build Coastguard Worker
13*9880d681SAndroid Build Coastguard Worker; rdar://7832370
14*9880d681SAndroid Build Coastguard Worker; Check that lots of stuff doesn't get turned into undef.
15*9880d681SAndroid Build Coastguard Workerdefine i32 @test2() nounwind readnone ssp {
16*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test2(
17*9880d681SAndroid Build Coastguard Workerinit:
18*9880d681SAndroid Build Coastguard Worker  br label %control.outer.outer
19*9880d681SAndroid Build Coastguard Worker
20*9880d681SAndroid Build Coastguard Workercontrol.outer.loopexit.us-lcssa:                  ; preds = %control
21*9880d681SAndroid Build Coastguard Worker  br label %control.outer.loopexit
22*9880d681SAndroid Build Coastguard Worker
23*9880d681SAndroid Build Coastguard Workercontrol.outer.loopexit:                           ; preds = %control.outer.loopexit.us-lcssa.us, %control.outer.loopexit.us-lcssa
24*9880d681SAndroid Build Coastguard Worker  br label %control.outer.outer.backedge
25*9880d681SAndroid Build Coastguard Worker
26*9880d681SAndroid Build Coastguard Workercontrol.outer.outer:                              ; preds = %control.outer.outer.backedge, %init
27*9880d681SAndroid Build Coastguard Worker  %switchCond.0.ph.ph = phi i32 [ 2, %init ], [ 3, %control.outer.outer.backedge ] ; <i32> [#uses=2]
28*9880d681SAndroid Build Coastguard Worker  %i.0.ph.ph = phi i32 [ undef, %init ], [ %i.0.ph.ph.be, %control.outer.outer.backedge ] ; <i32> [#uses=1]
29*9880d681SAndroid Build Coastguard Worker  %tmp4 = icmp eq i32 %i.0.ph.ph, 0               ; <i1> [#uses=1]
30*9880d681SAndroid Build Coastguard Worker  br i1 %tmp4, label %control.outer.outer.split.us, label %control.outer.outer.control.outer.outer.split_crit_edge
31*9880d681SAndroid Build Coastguard Worker
32*9880d681SAndroid Build Coastguard Workercontrol.outer.outer.control.outer.outer.split_crit_edge: ; preds = %control.outer.outer
33*9880d681SAndroid Build Coastguard Worker  br label %control.outer
34*9880d681SAndroid Build Coastguard Worker
35*9880d681SAndroid Build Coastguard Workercontrol.outer.outer.split.us:                     ; preds = %control.outer.outer
36*9880d681SAndroid Build Coastguard Worker  br label %control.outer.us
37*9880d681SAndroid Build Coastguard Worker
38*9880d681SAndroid Build Coastguard Workercontrol.outer.us:                                 ; preds = %bb3.us, %control.outer.outer.split.us
39*9880d681SAndroid Build Coastguard Worker  %A.0.ph.us = phi i32 [ %switchCond.0.us, %bb3.us ], [ 4, %control.outer.outer.split.us ] ; <i32> [#uses=2]
40*9880d681SAndroid Build Coastguard Worker  %switchCond.0.ph.us = phi i32 [ %A.0.ph.us, %bb3.us ], [ %switchCond.0.ph.ph, %control.outer.outer.split.us ] ; <i32> [#uses=1]
41*9880d681SAndroid Build Coastguard Worker  br label %control.us
42*9880d681SAndroid Build Coastguard Worker
43*9880d681SAndroid Build Coastguard Workerbb3.us:                                           ; preds = %control.us
44*9880d681SAndroid Build Coastguard Worker  br label %control.outer.us
45*9880d681SAndroid Build Coastguard Worker
46*9880d681SAndroid Build Coastguard Workerbb0.us:                                           ; preds = %control.us
47*9880d681SAndroid Build Coastguard Worker  br label %control.us
48*9880d681SAndroid Build Coastguard Worker
49*9880d681SAndroid Build Coastguard Worker; CHECK: control.us:                                       ; preds = %bb0.us, %control.outer.us
50*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  %switchCond.0.us = phi i32
51*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  switch i32 %switchCond.0.us
52*9880d681SAndroid Build Coastguard Workercontrol.us:                                       ; preds = %bb0.us, %control.outer.us
53*9880d681SAndroid Build Coastguard Worker  %switchCond.0.us = phi i32 [ %A.0.ph.us, %bb0.us ], [ %switchCond.0.ph.us, %control.outer.us ] ; <i32> [#uses=2]
54*9880d681SAndroid Build Coastguard Worker  switch i32 %switchCond.0.us, label %control.outer.loopexit.us-lcssa.us [
55*9880d681SAndroid Build Coastguard Worker    i32 0, label %bb0.us
56*9880d681SAndroid Build Coastguard Worker    i32 1, label %bb1.us-lcssa.us
57*9880d681SAndroid Build Coastguard Worker    i32 3, label %bb3.us
58*9880d681SAndroid Build Coastguard Worker    i32 4, label %bb4.us-lcssa.us
59*9880d681SAndroid Build Coastguard Worker  ]
60*9880d681SAndroid Build Coastguard Worker
61*9880d681SAndroid Build Coastguard Workercontrol.outer.loopexit.us-lcssa.us:               ; preds = %control.us
62*9880d681SAndroid Build Coastguard Worker  br label %control.outer.loopexit
63*9880d681SAndroid Build Coastguard Worker
64*9880d681SAndroid Build Coastguard Workerbb1.us-lcssa.us:                                  ; preds = %control.us
65*9880d681SAndroid Build Coastguard Worker  br label %bb1
66*9880d681SAndroid Build Coastguard Worker
67*9880d681SAndroid Build Coastguard Workerbb4.us-lcssa.us:                                  ; preds = %control.us
68*9880d681SAndroid Build Coastguard Worker  br label %bb4
69*9880d681SAndroid Build Coastguard Worker
70*9880d681SAndroid Build Coastguard Workercontrol.outer:                                    ; preds = %bb3, %control.outer.outer.control.outer.outer.split_crit_edge
71*9880d681SAndroid Build Coastguard Worker  %A.0.ph = phi i32 [ %nextId17, %bb3 ], [ 4, %control.outer.outer.control.outer.outer.split_crit_edge ] ; <i32> [#uses=1]
72*9880d681SAndroid Build Coastguard Worker  %switchCond.0.ph = phi i32 [ 0, %bb3 ], [ %switchCond.0.ph.ph, %control.outer.outer.control.outer.outer.split_crit_edge ] ; <i32> [#uses=1]
73*9880d681SAndroid Build Coastguard Worker  br label %control
74*9880d681SAndroid Build Coastguard Worker
75*9880d681SAndroid Build Coastguard Workercontrol:                                          ; preds = %bb0, %control.outer
76*9880d681SAndroid Build Coastguard Worker  %switchCond.0 = phi i32 [ %A.0.ph, %bb0 ], [ %switchCond.0.ph, %control.outer ] ; <i32> [#uses=2]
77*9880d681SAndroid Build Coastguard Worker  switch i32 %switchCond.0, label %control.outer.loopexit.us-lcssa [
78*9880d681SAndroid Build Coastguard Worker    i32 0, label %bb0
79*9880d681SAndroid Build Coastguard Worker    i32 1, label %bb1.us-lcssa
80*9880d681SAndroid Build Coastguard Worker    i32 3, label %bb3
81*9880d681SAndroid Build Coastguard Worker    i32 4, label %bb4.us-lcssa
82*9880d681SAndroid Build Coastguard Worker  ]
83*9880d681SAndroid Build Coastguard Worker
84*9880d681SAndroid Build Coastguard Workerbb4.us-lcssa:                                     ; preds = %control
85*9880d681SAndroid Build Coastguard Worker  br label %bb4
86*9880d681SAndroid Build Coastguard Worker
87*9880d681SAndroid Build Coastguard Workerbb4:                                              ; preds = %bb4.us-lcssa, %bb4.us-lcssa.us
88*9880d681SAndroid Build Coastguard Worker  br label %control.outer.outer.backedge
89*9880d681SAndroid Build Coastguard Worker
90*9880d681SAndroid Build Coastguard Workercontrol.outer.outer.backedge:                     ; preds = %bb4, %control.outer.loopexit
91*9880d681SAndroid Build Coastguard Worker  %i.0.ph.ph.be = phi i32 [ 1, %bb4 ], [ 0, %control.outer.loopexit ] ; <i32> [#uses=1]
92*9880d681SAndroid Build Coastguard Worker  br label %control.outer.outer
93*9880d681SAndroid Build Coastguard Worker
94*9880d681SAndroid Build Coastguard Workerbb3:                                              ; preds = %control
95*9880d681SAndroid Build Coastguard Worker  %nextId17 = add i32 %switchCond.0, -2           ; <i32> [#uses=1]
96*9880d681SAndroid Build Coastguard Worker  br label %control.outer
97*9880d681SAndroid Build Coastguard Worker
98*9880d681SAndroid Build Coastguard Workerbb0:                                              ; preds = %control
99*9880d681SAndroid Build Coastguard Worker  br label %control
100*9880d681SAndroid Build Coastguard Worker
101*9880d681SAndroid Build Coastguard Workerbb1.us-lcssa:                                     ; preds = %control
102*9880d681SAndroid Build Coastguard Worker  br label %bb1
103*9880d681SAndroid Build Coastguard Worker
104*9880d681SAndroid Build Coastguard Workerbb1:                                              ; preds = %bb1.us-lcssa, %bb1.us-lcssa.us
105*9880d681SAndroid Build Coastguard Worker  ret i32 0
106*9880d681SAndroid Build Coastguard Worker}
107*9880d681SAndroid Build Coastguard Worker
108*9880d681SAndroid Build Coastguard Worker; Make sure SCCP honors the xor "idiom"
109*9880d681SAndroid Build Coastguard Worker; rdar://9956541
110*9880d681SAndroid Build Coastguard Workerdefine i32 @test3() {
111*9880d681SAndroid Build Coastguard Worker  %t = xor i32 undef, undef
112*9880d681SAndroid Build Coastguard Worker  ret i32 %t
113*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test3(
114*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 0
115*9880d681SAndroid Build Coastguard Worker}
116*9880d681SAndroid Build Coastguard Worker
117*9880d681SAndroid Build Coastguard Worker; Be conservative with FP ops
118*9880d681SAndroid Build Coastguard Workerdefine double @test4(double %x) {
119*9880d681SAndroid Build Coastguard Worker  %t = fadd double %x, undef
120*9880d681SAndroid Build Coastguard Worker  ret double %t
121*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test4(
122*9880d681SAndroid Build Coastguard Worker; CHECK: fadd double %x, undef
123*9880d681SAndroid Build Coastguard Worker}
124*9880d681SAndroid Build Coastguard Worker
125*9880d681SAndroid Build Coastguard Worker; Make sure casts produce a possible value
126*9880d681SAndroid Build Coastguard Workerdefine i32 @test5() {
127*9880d681SAndroid Build Coastguard Worker  %t = sext i8 undef to i32
128*9880d681SAndroid Build Coastguard Worker  ret i32 %t
129*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test5(
130*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 0
131*9880d681SAndroid Build Coastguard Worker}
132*9880d681SAndroid Build Coastguard Worker
133*9880d681SAndroid Build Coastguard Worker; Make sure ashr produces a possible value
134*9880d681SAndroid Build Coastguard Workerdefine i32 @test6() {
135*9880d681SAndroid Build Coastguard Worker  %t = ashr i32 undef, 31
136*9880d681SAndroid Build Coastguard Worker  ret i32 %t
137*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test6(
138*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 -1
139*9880d681SAndroid Build Coastguard Worker}
140*9880d681SAndroid Build Coastguard Worker
141*9880d681SAndroid Build Coastguard Worker; Make sure lshr produces a possible value
142*9880d681SAndroid Build Coastguard Workerdefine i32 @test7() {
143*9880d681SAndroid Build Coastguard Worker  %t = lshr i32 undef, 31
144*9880d681SAndroid Build Coastguard Worker  ret i32 %t
145*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test7(
146*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 0
147*9880d681SAndroid Build Coastguard Worker}
148*9880d681SAndroid Build Coastguard Worker
149*9880d681SAndroid Build Coastguard Worker; icmp eq with undef simplifies to undef
150*9880d681SAndroid Build Coastguard Workerdefine i1 @test8() {
151*9880d681SAndroid Build Coastguard Worker  %t = icmp eq i32 undef, -1
152*9880d681SAndroid Build Coastguard Worker  ret i1 %t
153*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test8(
154*9880d681SAndroid Build Coastguard Worker; CHECK: ret i1 undef
155*9880d681SAndroid Build Coastguard Worker}
156*9880d681SAndroid Build Coastguard Worker
157*9880d681SAndroid Build Coastguard Worker; Make sure we don't conclude that relational comparisons simplify to undef
158*9880d681SAndroid Build Coastguard Workerdefine i1 @test9() {
159*9880d681SAndroid Build Coastguard Worker  %t = icmp ugt i32 undef, -1
160*9880d681SAndroid Build Coastguard Worker  ret i1 %t
161*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test9(
162*9880d681SAndroid Build Coastguard Worker; CHECK: icmp ugt
163*9880d681SAndroid Build Coastguard Worker}
164*9880d681SAndroid Build Coastguard Worker
165*9880d681SAndroid Build Coastguard Worker; Make sure we handle extractvalue
166*9880d681SAndroid Build Coastguard Workerdefine i64 @test10() {
167*9880d681SAndroid Build Coastguard Workerentry:
168*9880d681SAndroid Build Coastguard Worker  %e = extractvalue { i64, i64 } undef, 1
169*9880d681SAndroid Build Coastguard Worker  ret i64 %e
170*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test10(
171*9880d681SAndroid Build Coastguard Worker; CHECK: ret i64 undef
172*9880d681SAndroid Build Coastguard Worker}
173*9880d681SAndroid Build Coastguard Worker
174*9880d681SAndroid Build Coastguard Worker@GV = external global i32
175*9880d681SAndroid Build Coastguard Worker
176*9880d681SAndroid Build Coastguard Workerdefine i32 @test11(i1 %tobool) {
177*9880d681SAndroid Build Coastguard Workerentry:
178*9880d681SAndroid Build Coastguard Worker  %shr4 = ashr i32 undef, zext (i1 icmp eq (i32* bitcast (i32 (i1)* @test11 to i32*), i32* @GV) to i32)
179*9880d681SAndroid Build Coastguard Worker  ret i32 %shr4
180*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test11(
181*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 -1
182*9880d681SAndroid Build Coastguard Worker}
183