1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=instcombine < %s | FileCheck %s
4 ; Check that we don't create two redundant phi nodes when %val is used in a
5 ; form where we can't rewrite it in terms of the new phi node.
7 ; Use %val in an instruction type not supported by optimizeBitCastFromPhi.
8 define float @sitofp(float %x) {
9 ; CHECK-LABEL: @sitofp(
11 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
13 ; CHECK-NEXT: [[VAL:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[VAL_INCR_CASTED:%.*]], [[LOOP:%.*]] ]
14 ; CHECK-NEXT: [[VAL_CASTED:%.*]] = bitcast i32 [[VAL]] to float
15 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[VAL_CASTED]], [[X:%.*]]
16 ; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[LOOP]]
18 ; CHECK-NEXT: [[VAL_INCR:%.*]] = fadd float [[VAL_CASTED]], 1.000000e+00
19 ; CHECK-NEXT: [[VAL_INCR_CASTED]] = bitcast float [[VAL_INCR]] to i32
20 ; CHECK-NEXT: br label [[LOOP_HEADER]]
22 ; CHECK-NEXT: [[RESULT:%.*]] = sitofp i32 [[VAL]] to float
23 ; CHECK-NEXT: ret float [[RESULT]]
28 %val = phi i32 [ 0, %entry ], [ %val_incr_casted, %loop ]
29 %val_casted = bitcast i32 %val to float
30 %cmp = fcmp ogt float %val_casted, %x
31 br i1 %cmp, label %end, label %loop
33 %val_incr = fadd float %val_casted, 1.0
34 %val_incr_casted = bitcast float %val_incr to i32
37 %result = sitofp i32 %val to float
41 ; Use %val in an incompatible bitcast.
42 define <2 x i16> @bitcast(float %x) {
43 ; CHECK-LABEL: @bitcast(
45 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
47 ; CHECK-NEXT: [[VAL:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[VAL_INCR_CASTED:%.*]], [[LOOP:%.*]] ]
48 ; CHECK-NEXT: [[VAL_CASTED:%.*]] = bitcast i32 [[VAL]] to float
49 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[VAL_CASTED]], [[X:%.*]]
50 ; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[LOOP]]
52 ; CHECK-NEXT: [[VAL_INCR:%.*]] = fadd float [[VAL_CASTED]], 1.000000e+00
53 ; CHECK-NEXT: [[VAL_INCR_CASTED]] = bitcast float [[VAL_INCR]] to i32
54 ; CHECK-NEXT: br label [[LOOP_HEADER]]
56 ; CHECK-NEXT: [[RESULT:%.*]] = bitcast i32 [[VAL]] to <2 x i16>
57 ; CHECK-NEXT: ret <2 x i16> [[RESULT]]
62 %val = phi i32 [ 0, %entry ], [ %val_incr_casted, %loop ]
63 %val_casted = bitcast i32 %val to float
64 %cmp = fcmp ogt float %val_casted, %x
65 br i1 %cmp, label %end, label %loop
67 %val_incr = fadd float %val_casted, 1.0
68 %val_incr_casted = bitcast float %val_incr to i32
71 %result = bitcast i32 %val to <2 x i16>
75 @global = global i32 0
77 ; Use %val with a volatile store.
78 define void @store_volatile(float %x) {
79 ; CHECK-LABEL: @store_volatile(
81 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
83 ; CHECK-NEXT: [[VAL:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[VAL_INCR_CASTED:%.*]], [[LOOP:%.*]] ]
84 ; CHECK-NEXT: [[VAL_CASTED:%.*]] = bitcast i32 [[VAL]] to float
85 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[VAL_CASTED]], [[X:%.*]]
86 ; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[LOOP]]
88 ; CHECK-NEXT: [[VAL_INCR:%.*]] = fadd float [[VAL_CASTED]], 1.000000e+00
89 ; CHECK-NEXT: [[VAL_INCR_CASTED]] = bitcast float [[VAL_INCR]] to i32
90 ; CHECK-NEXT: br label [[LOOP_HEADER]]
92 ; CHECK-NEXT: store volatile i32 [[VAL]], ptr @global, align 4
93 ; CHECK-NEXT: ret void
98 %val = phi i32 [ 0, %entry ], [ %val_incr_casted, %loop ]
99 %val_casted = bitcast i32 %val to float
100 %cmp = fcmp ogt float %val_casted, %x
101 br i1 %cmp, label %end, label %loop
103 %val_incr = fadd float %val_casted, 1.0
104 %val_incr_casted = bitcast float %val_incr to i32
105 br label %loop_header
107 store volatile i32 %val, ptr @global
111 ; Use %val with a store where it's actually the address.
112 define void @store_address(i32 %x) {
113 ; CHECK-LABEL: @store_address(
115 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
116 ; CHECK: loop_header:
117 ; CHECK-NEXT: [[VAL:%.*]] = phi ptr [ @global, [[ENTRY:%.*]] ], [ [[VAL_INCR:%.*]], [[LOOP:%.*]] ]
118 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
119 ; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[LOOP]]
121 ; CHECK-NEXT: [[VAL_INCR]] = getelementptr float, ptr [[VAL]], i64 1
122 ; CHECK-NEXT: br label [[LOOP_HEADER]]
124 ; CHECK-NEXT: store i32 0, ptr [[VAL]], align 4
125 ; CHECK-NEXT: ret void
128 br label %loop_header
130 %val = phi ptr [ @global, %entry ], [ %val_incr, %loop ]
131 %i = phi i32 [ 0, %entry ], [ %i_incr, %loop ]
132 %cmp = icmp sgt i32 %i, %x
133 br i1 %cmp, label %end, label %loop
135 %i_incr = add i32 %i, 0
136 %val_incr = getelementptr float, ptr %val, i32 1
137 br label %loop_header
139 store i32 0, ptr %val
143 ; Test where a phi (%val2) other than the original one (%val) has an
145 define i32 @multiple_phis(float %x) {
146 ; CHECK-LABEL: @multiple_phis(
148 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
149 ; CHECK: loop_header:
150 ; CHECK-NEXT: [[VAL:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[VAL2:%.*]], [[LOOP_END:%.*]] ]
151 ; CHECK-NEXT: [[VAL_CASTED:%.*]] = bitcast i32 [[VAL]] to float
152 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[VAL_CASTED]], [[X:%.*]]
153 ; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[LOOP:%.*]]
155 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp ogt float [[VAL_CASTED]], 2.000000e+00
156 ; CHECK-NEXT: br i1 [[CMP2]], label [[IF:%.*]], label [[LOOP_END]]
158 ; CHECK-NEXT: [[VAL_INCR:%.*]] = fadd float [[VAL_CASTED]], 1.000000e+00
159 ; CHECK-NEXT: [[VAL_INCR_CASTED:%.*]] = bitcast float [[VAL_INCR]] to i32
160 ; CHECK-NEXT: br label [[LOOP_END]]
162 ; CHECK-NEXT: [[VAL2]] = phi i32 [ [[VAL]], [[LOOP]] ], [ [[VAL_INCR_CASTED]], [[IF]] ]
163 ; CHECK-NEXT: store volatile i32 [[VAL2]], ptr @global, align 4
164 ; CHECK-NEXT: br label [[LOOP_HEADER]]
166 ; CHECK-NEXT: ret i32 [[VAL]]
169 br label %loop_header
171 %val = phi i32 [ 0, %entry ], [ %val2, %loop_end ]
172 %val_casted = bitcast i32 %val to float
173 %cmp = fcmp ogt float %val_casted, %x
174 br i1 %cmp, label %end, label %loop
176 %cmp2 = fcmp ogt float %val_casted, 2.0
177 br i1 %cmp2, label %if, label %loop_end
179 %val_incr = fadd float %val_casted, 1.0
180 %val_incr_casted = bitcast float %val_incr to i32
183 %val2 = phi i32 [ %val, %loop ], [ %val_incr_casted, %if ]
184 store volatile i32 %val2, ptr @global ; the incompatible use
185 br label %loop_header