1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; Test that the exp2 library call simplifier works correctly.
4 ; RUN: opt < %s -instcombine -S -mtriple=unknown | FileCheck %s -check-prefixes=LDEXP32
5 ; RUN: opt < %s -instcombine -S -mtriple=msp430 | FileCheck %s -check-prefixes=LDEXP16
6 ; RUN: opt < %s -instcombine -S -mtriple=i386-pc-win32 | FileCheck %s -check-prefixes=NOLDEXPF
7 ; RUN: opt < %s -instcombine -S -mtriple=amdgcn-unknown-unknown | FileCheck %s -check-prefixes=NOLDEXP
9 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
11 declare double @exp2(double)
12 declare float @exp2f(float)
14 ; Check exp2(sitofp(x)) -> ldexp(1.0, sext(x)).
16 define double @test_simplify1(i32 %x) {
17 ; LDEXP32-LABEL: @test_simplify1(
18 ; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[X:%.*]])
19 ; LDEXP32-NEXT: ret double [[LDEXP]]
21 ; LDEXP16-LABEL: @test_simplify1(
22 ; LDEXP16-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to double
23 ; LDEXP16-NEXT: [[RET:%.*]] = call double @exp2(double [[CONV]])
24 ; LDEXP16-NEXT: ret double [[RET]]
26 ; NOLDEXPF-LABEL: @test_simplify1(
27 ; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[X:%.*]])
28 ; NOLDEXPF-NEXT: ret double [[LDEXP]]
30 ; NOLDEXP-LABEL: @test_simplify1(
31 ; NOLDEXP-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to double
32 ; NOLDEXP-NEXT: [[RET:%.*]] = call double @exp2(double [[CONV]])
33 ; NOLDEXP-NEXT: ret double [[RET]]
35 %conv = sitofp i32 %x to double
36 %ret = call double @exp2(double %conv)
40 define double @test_simplify2(i16 signext %x) {
41 ; LDEXP32-LABEL: @test_simplify2(
42 ; LDEXP32-NEXT: [[TMP1:%.*]] = sext i16 [[X:%.*]] to i32
43 ; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
44 ; LDEXP32-NEXT: ret double [[LDEXP]]
46 ; LDEXP16-LABEL: @test_simplify2(
47 ; LDEXP16-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 [[X:%.*]])
48 ; LDEXP16-NEXT: ret double [[LDEXP]]
50 ; NOLDEXPF-LABEL: @test_simplify2(
51 ; NOLDEXPF-NEXT: [[TMP1:%.*]] = sext i16 [[X:%.*]] to i32
52 ; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
53 ; NOLDEXPF-NEXT: ret double [[LDEXP]]
55 ; NOLDEXP-LABEL: @test_simplify2(
56 ; NOLDEXP-NEXT: [[CONV:%.*]] = sitofp i16 [[X:%.*]] to double
57 ; NOLDEXP-NEXT: [[RET:%.*]] = call double @exp2(double [[CONV]])
58 ; NOLDEXP-NEXT: ret double [[RET]]
60 %conv = sitofp i16 %x to double
61 %ret = call double @exp2(double %conv)
65 define double @test_simplify3(i8 signext %x) {
66 ; LDEXP32-LABEL: @test_simplify3(
67 ; LDEXP32-NEXT: [[TMP1:%.*]] = sext i8 [[X:%.*]] to i32
68 ; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
69 ; LDEXP32-NEXT: ret double [[LDEXP]]
71 ; LDEXP16-LABEL: @test_simplify3(
72 ; LDEXP16-NEXT: [[TMP1:%.*]] = sext i8 [[X:%.*]] to i16
73 ; LDEXP16-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 [[TMP1]])
74 ; LDEXP16-NEXT: ret double [[LDEXP]]
76 ; NOLDEXPF-LABEL: @test_simplify3(
77 ; NOLDEXPF-NEXT: [[TMP1:%.*]] = sext i8 [[X:%.*]] to i32
78 ; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
79 ; NOLDEXPF-NEXT: ret double [[LDEXP]]
81 ; NOLDEXP-LABEL: @test_simplify3(
82 ; NOLDEXP-NEXT: [[CONV:%.*]] = sitofp i8 [[X:%.*]] to double
83 ; NOLDEXP-NEXT: [[RET:%.*]] = call double @exp2(double [[CONV]])
84 ; NOLDEXP-NEXT: ret double [[RET]]
86 %conv = sitofp i8 %x to double
87 %ret = call double @exp2(double %conv)
91 define float @test_simplify4(i32 %x) {
92 ; LDEXP32-LABEL: @test_simplify4(
93 ; LDEXP32-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 [[X:%.*]])
94 ; LDEXP32-NEXT: ret float [[LDEXPF]]
96 ; LDEXP16-LABEL: @test_simplify4(
97 ; LDEXP16-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to float
98 ; LDEXP16-NEXT: [[RET:%.*]] = call float @exp2f(float [[CONV]])
99 ; LDEXP16-NEXT: ret float [[RET]]
101 ; NOLDEXPF-LABEL: @test_simplify4(
102 ; NOLDEXPF-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to float
103 ; NOLDEXPF-NEXT: [[RET:%.*]] = call float @exp2f(float [[CONV]])
104 ; NOLDEXPF-NEXT: ret float [[RET]]
106 ; NOLDEXP-LABEL: @test_simplify4(
107 ; NOLDEXP-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to float
108 ; NOLDEXP-NEXT: [[RET:%.*]] = call float @exp2f(float [[CONV]])
109 ; NOLDEXP-NEXT: ret float [[RET]]
111 %conv = sitofp i32 %x to float
112 %ret = call float @exp2f(float %conv)
116 ; Check exp2(uitofp(x)) -> ldexp(1.0, zext(x)).
118 define double @test_no_simplify1(i32 %x) {
119 ; LDEXP32-LABEL: @test_no_simplify1(
120 ; LDEXP32-NEXT: [[CONV:%.*]] = uitofp i32 [[X:%.*]] to double
121 ; LDEXP32-NEXT: [[RET:%.*]] = call double @exp2(double [[CONV]])
122 ; LDEXP32-NEXT: ret double [[RET]]
124 ; LDEXP16-LABEL: @test_no_simplify1(
125 ; LDEXP16-NEXT: [[CONV:%.*]] = uitofp i32 [[X:%.*]] to double
126 ; LDEXP16-NEXT: [[RET:%.*]] = call double @exp2(double [[CONV]])
127 ; LDEXP16-NEXT: ret double [[RET]]
129 ; NOLDEXPF-LABEL: @test_no_simplify1(
130 ; NOLDEXPF-NEXT: [[CONV:%.*]] = uitofp i32 [[X:%.*]] to double
131 ; NOLDEXPF-NEXT: [[RET:%.*]] = call double @exp2(double [[CONV]])
132 ; NOLDEXPF-NEXT: ret double [[RET]]
134 ; NOLDEXP-LABEL: @test_no_simplify1(
135 ; NOLDEXP-NEXT: [[CONV:%.*]] = uitofp i32 [[X:%.*]] to double
136 ; NOLDEXP-NEXT: [[RET:%.*]] = call double @exp2(double [[CONV]])
137 ; NOLDEXP-NEXT: ret double [[RET]]
139 %conv = uitofp i32 %x to double
140 %ret = call double @exp2(double %conv)
144 define double @test_simplify6(i16 zeroext %x) {
145 ; LDEXP32-LABEL: @test_simplify6(
146 ; LDEXP32-NEXT: [[TMP1:%.*]] = zext i16 [[X:%.*]] to i32
147 ; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
148 ; LDEXP32-NEXT: ret double [[LDEXP]]
150 ; LDEXP16-LABEL: @test_simplify6(
151 ; LDEXP16-NEXT: [[CONV:%.*]] = uitofp i16 [[X:%.*]] to double
152 ; LDEXP16-NEXT: [[RET:%.*]] = call double @exp2(double [[CONV]])
153 ; LDEXP16-NEXT: ret double [[RET]]
155 ; NOLDEXPF-LABEL: @test_simplify6(
156 ; NOLDEXPF-NEXT: [[TMP1:%.*]] = zext i16 [[X:%.*]] to i32
157 ; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
158 ; NOLDEXPF-NEXT: ret double [[LDEXP]]
160 ; NOLDEXP-LABEL: @test_simplify6(
161 ; NOLDEXP-NEXT: [[CONV:%.*]] = uitofp i16 [[X:%.*]] to double
162 ; NOLDEXP-NEXT: [[RET:%.*]] = call double @exp2(double [[CONV]])
163 ; NOLDEXP-NEXT: ret double [[RET]]
165 %conv = uitofp i16 %x to double
166 %ret = call double @exp2(double %conv)
170 define double @test_simplify7(i8 zeroext %x) {
171 ; LDEXP32-LABEL: @test_simplify7(
172 ; LDEXP32-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i32
173 ; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
174 ; LDEXP32-NEXT: ret double [[LDEXP]]
176 ; LDEXP16-LABEL: @test_simplify7(
177 ; LDEXP16-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i16
178 ; LDEXP16-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 [[TMP1]])
179 ; LDEXP16-NEXT: ret double [[LDEXP]]
181 ; NOLDEXPF-LABEL: @test_simplify7(
182 ; NOLDEXPF-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i32
183 ; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
184 ; NOLDEXPF-NEXT: ret double [[LDEXP]]
186 ; NOLDEXP-LABEL: @test_simplify7(
187 ; NOLDEXP-NEXT: [[CONV:%.*]] = uitofp i8 [[X:%.*]] to double
188 ; NOLDEXP-NEXT: [[RET:%.*]] = call double @exp2(double [[CONV]])
189 ; NOLDEXP-NEXT: ret double [[RET]]
191 %conv = uitofp i8 %x to double
192 %ret = call double @exp2(double %conv)
196 define float @test_simplify8(i8 zeroext %x) {
197 ; LDEXP32-LABEL: @test_simplify8(
198 ; LDEXP32-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i32
199 ; LDEXP32-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 [[TMP1]])
200 ; LDEXP32-NEXT: ret float [[LDEXPF]]
202 ; LDEXP16-LABEL: @test_simplify8(
203 ; LDEXP16-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i16
204 ; LDEXP16-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i16 [[TMP1]])
205 ; LDEXP16-NEXT: ret float [[LDEXPF]]
207 ; NOLDEXPF-LABEL: @test_simplify8(
208 ; NOLDEXPF-NEXT: [[CONV:%.*]] = uitofp i8 [[X:%.*]] to float
209 ; NOLDEXPF-NEXT: [[RET:%.*]] = call float @exp2f(float [[CONV]])
210 ; NOLDEXPF-NEXT: ret float [[RET]]
212 ; NOLDEXP-LABEL: @test_simplify8(
213 ; NOLDEXP-NEXT: [[CONV:%.*]] = uitofp i8 [[X:%.*]] to float
214 ; NOLDEXP-NEXT: [[RET:%.*]] = call float @exp2f(float [[CONV]])
215 ; NOLDEXP-NEXT: ret float [[RET]]
217 %conv = uitofp i8 %x to float
218 %ret = call float @exp2f(float %conv)
222 declare double @llvm.exp2.f64(double)
223 declare float @llvm.exp2.f32(float)
225 define double @test_simplify9(i8 zeroext %x) {
226 ; LDEXP32-LABEL: @test_simplify9(
227 ; LDEXP32-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i32
228 ; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
229 ; LDEXP32-NEXT: ret double [[LDEXP]]
231 ; LDEXP16-LABEL: @test_simplify9(
232 ; LDEXP16-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i16
233 ; LDEXP16-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 [[TMP1]])
234 ; LDEXP16-NEXT: ret double [[LDEXP]]
236 ; NOLDEXPF-LABEL: @test_simplify9(
237 ; NOLDEXPF-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i32
238 ; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
239 ; NOLDEXPF-NEXT: ret double [[LDEXP]]
241 ; NOLDEXP-LABEL: @test_simplify9(
242 ; NOLDEXP-NEXT: [[CONV:%.*]] = uitofp i8 [[X:%.*]] to double
243 ; NOLDEXP-NEXT: [[RET:%.*]] = call double @llvm.exp2.f64(double [[CONV]])
244 ; NOLDEXP-NEXT: ret double [[RET]]
246 %conv = uitofp i8 %x to double
247 %ret = call double @llvm.exp2.f64(double %conv)
251 define float @test_simplify10(i8 zeroext %x) {
252 ; LDEXP32-LABEL: @test_simplify10(
253 ; LDEXP32-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i32
254 ; LDEXP32-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 [[TMP1]])
255 ; LDEXP32-NEXT: ret float [[LDEXPF]]
257 ; LDEXP16-LABEL: @test_simplify10(
258 ; LDEXP16-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i16
259 ; LDEXP16-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i16 [[TMP1]])
260 ; LDEXP16-NEXT: ret float [[LDEXPF]]
262 ; NOLDEXPF-LABEL: @test_simplify10(
263 ; NOLDEXPF-NEXT: [[CONV:%.*]] = uitofp i8 [[X:%.*]] to float
264 ; NOLDEXPF-NEXT: [[RET:%.*]] = call float @llvm.exp2.f32(float [[CONV]])
265 ; NOLDEXPF-NEXT: ret float [[RET]]
267 ; NOLDEXP-LABEL: @test_simplify10(
268 ; NOLDEXP-NEXT: [[CONV:%.*]] = uitofp i8 [[X:%.*]] to float
269 ; NOLDEXP-NEXT: [[RET:%.*]] = call float @llvm.exp2.f32(float [[CONV]])
270 ; NOLDEXP-NEXT: ret float [[RET]]
272 %conv = uitofp i8 %x to float
273 %ret = call float @llvm.exp2.f32(float %conv)