Skip to content

Commit 1168316

Browse files
committed
InstCombine: Add baseline tests for exp2 to ldexp transform
1 parent 70e227a commit 1168316

File tree

2 files changed

+245
-0
lines changed

2 files changed

+245
-0
lines changed

llvm/test/Transforms/InstCombine/exp2-1.ll

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ declare float @exp2f(float)
1414
declare double @llvm.exp2.f64(double)
1515
declare float @llvm.exp2.f32(float)
1616
declare <2 x float> @llvm.exp2.v2f32(<2 x float>)
17+
declare fp128 @exp2l(fp128)
1718

1819

1920
; Check exp2(sitofp(x)) -> ldexp(1.0, sext(x)).
@@ -330,3 +331,97 @@ define <2 x float> @sitofp_vector_intrinsic_with_FMF(<2 x i8> %x) {
330331
%r = call nnan <2 x float> @llvm.exp2.v2f32(<2 x float> %s)
331332
ret <2 x float> %r
332333
}
334+
335+
define double @test_readonly_exp2_f64_of_sitofp(i32 %x) {
336+
; LDEXP32-LABEL: @test_readonly_exp2_f64_of_sitofp(
337+
; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[X:%.*]])
338+
; LDEXP32-NEXT: ret double [[LDEXP]]
339+
;
340+
; LDEXP16-LABEL: @test_readonly_exp2_f64_of_sitofp(
341+
; LDEXP16-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to double
342+
; LDEXP16-NEXT: [[RET:%.*]] = call double @exp2(double [[CONV]]) #[[ATTR2:[0-9]+]]
343+
; LDEXP16-NEXT: ret double [[RET]]
344+
;
345+
; NOLDEXPF-LABEL: @test_readonly_exp2_f64_of_sitofp(
346+
; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[X:%.*]])
347+
; NOLDEXPF-NEXT: ret double [[LDEXP]]
348+
;
349+
; NOLDEXP-LABEL: @test_readonly_exp2_f64_of_sitofp(
350+
; NOLDEXP-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to double
351+
; NOLDEXP-NEXT: [[RET:%.*]] = call double @exp2(double [[CONV]]) #[[ATTR1:[0-9]+]]
352+
; NOLDEXP-NEXT: ret double [[RET]]
353+
;
354+
%conv = sitofp i32 %x to double
355+
%ret = call double @exp2(double %conv) readonly
356+
ret double %ret
357+
}
358+
359+
define float @test_readonly_exp2f_f32_of_sitofp(i32 %x) {
360+
; LDEXP32-LABEL: @test_readonly_exp2f_f32_of_sitofp(
361+
; LDEXP32-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 [[X:%.*]])
362+
; LDEXP32-NEXT: ret float [[LDEXPF]]
363+
;
364+
; LDEXP16-LABEL: @test_readonly_exp2f_f32_of_sitofp(
365+
; LDEXP16-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to float
366+
; LDEXP16-NEXT: [[RET:%.*]] = call float @exp2f(float [[CONV]]) #[[ATTR2]]
367+
; LDEXP16-NEXT: ret float [[RET]]
368+
;
369+
; NOLDEXPF-LABEL: @test_readonly_exp2f_f32_of_sitofp(
370+
; NOLDEXPF-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to float
371+
; NOLDEXPF-NEXT: [[RET:%.*]] = call float @exp2f(float [[CONV]]) #[[ATTR2:[0-9]+]]
372+
; NOLDEXPF-NEXT: ret float [[RET]]
373+
;
374+
; NOLDEXP-LABEL: @test_readonly_exp2f_f32_of_sitofp(
375+
; NOLDEXP-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to float
376+
; NOLDEXP-NEXT: [[RET:%.*]] = call float @exp2f(float [[CONV]]) #[[ATTR1]]
377+
; NOLDEXP-NEXT: ret float [[RET]]
378+
;
379+
%conv = sitofp i32 %x to float
380+
%ret = call float @exp2f(float %conv) readonly
381+
ret float %ret
382+
}
383+
384+
define fp128 @test_readonly_exp2l_fp128_of_sitofp(i32 %x) {
385+
; LDEXP32-LABEL: @test_readonly_exp2l_fp128_of_sitofp(
386+
; LDEXP32-NEXT: [[LDEXPL:%.*]] = call fp128 @ldexpl(fp128 0xL00000000000000003FFF000000000000, i32 [[X:%.*]])
387+
; LDEXP32-NEXT: ret fp128 [[LDEXPL]]
388+
;
389+
; LDEXP16-LABEL: @test_readonly_exp2l_fp128_of_sitofp(
390+
; LDEXP16-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to fp128
391+
; LDEXP16-NEXT: [[RET:%.*]] = call fp128 @exp2l(fp128 [[CONV]]) #[[ATTR2]]
392+
; LDEXP16-NEXT: ret fp128 [[RET]]
393+
;
394+
; NOLDEXP-LABEL: @test_readonly_exp2l_fp128_of_sitofp(
395+
; NOLDEXP-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to fp128
396+
; NOLDEXP-NEXT: [[RET:%.*]] = call fp128 @exp2l(fp128 [[CONV]]) #[[ATTR1]]
397+
; NOLDEXP-NEXT: ret fp128 [[RET]]
398+
;
399+
%conv = sitofp i32 %x to fp128
400+
%ret = call fp128 @exp2l(fp128 %conv) readonly
401+
ret fp128 %ret
402+
}
403+
404+
define float @test_readonly_exp2f_f32_of_sitofp_flags(i32 %x) {
405+
; LDEXP32-LABEL: @test_readonly_exp2f_f32_of_sitofp_flags(
406+
; LDEXP32-NEXT: [[LDEXPF:%.*]] = call nnan ninf float @ldexpf(float 1.000000e+00, i32 [[X:%.*]])
407+
; LDEXP32-NEXT: ret float [[LDEXPF]]
408+
;
409+
; LDEXP16-LABEL: @test_readonly_exp2f_f32_of_sitofp_flags(
410+
; LDEXP16-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to float
411+
; LDEXP16-NEXT: [[RET:%.*]] = call nnan ninf float @exp2f(float [[CONV]]) #[[ATTR2]]
412+
; LDEXP16-NEXT: ret float [[RET]]
413+
;
414+
; NOLDEXPF-LABEL: @test_readonly_exp2f_f32_of_sitofp_flags(
415+
; NOLDEXPF-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to float
416+
; NOLDEXPF-NEXT: [[RET:%.*]] = call nnan ninf float @exp2f(float [[CONV]]) #[[ATTR2]]
417+
; NOLDEXPF-NEXT: ret float [[RET]]
418+
;
419+
; NOLDEXP-LABEL: @test_readonly_exp2f_f32_of_sitofp_flags(
420+
; NOLDEXP-NEXT: [[CONV:%.*]] = sitofp i32 [[X:%.*]] to float
421+
; NOLDEXP-NEXT: [[RET:%.*]] = call nnan ninf float @exp2f(float [[CONV]]) #[[ATTR1]]
422+
; NOLDEXP-NEXT: ret float [[RET]]
423+
;
424+
%conv = sitofp i32 %x to float
425+
%ret = call nnan ninf float @exp2f(float %conv) readonly
426+
ret float %ret
427+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2+
; RUN: opt -S -passes=instcombine %s | FileCheck -check-prefixes=CHECK,LDEXP %s
3+
; RUN: opt -S -passes=instcombine -disable-builtin=ldexpf -disable-builtin=ldexp -disable-builtin=ldexpl %s | FileCheck -check-prefixes=CHECK,NOLDEXP %s
4+
5+
define float @exp2_f32_sitofp_i8(i8 %x) {
6+
; LDEXP-LABEL: define float @exp2_f32_sitofp_i8(
7+
; LDEXP-SAME: i8 [[X:%.*]]) {
8+
; LDEXP-NEXT: [[TMP1:%.*]] = sext i8 [[X]] to i32
9+
; LDEXP-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 [[TMP1]])
10+
; LDEXP-NEXT: ret float [[LDEXPF]]
11+
;
12+
; NOLDEXP-LABEL: define float @exp2_f32_sitofp_i8(
13+
; NOLDEXP-SAME: i8 [[X:%.*]]) {
14+
; NOLDEXP-NEXT: [[ITOFP:%.*]] = sitofp i8 [[X]] to float
15+
; NOLDEXP-NEXT: [[EXP2:%.*]] = call float @llvm.exp2.f32(float [[ITOFP]])
16+
; NOLDEXP-NEXT: ret float [[EXP2]]
17+
;
18+
%itofp = sitofp i8 %x to float
19+
%exp2 = call float @llvm.exp2.f32(float %itofp)
20+
ret float %exp2
21+
}
22+
23+
define float @exp2_f32_sitofp_i8_flags(i8 %x) {
24+
; LDEXP-LABEL: define float @exp2_f32_sitofp_i8_flags(
25+
; LDEXP-SAME: i8 [[X:%.*]]) {
26+
; LDEXP-NEXT: [[TMP1:%.*]] = sext i8 [[X]] to i32
27+
; LDEXP-NEXT: [[LDEXPF:%.*]] = call nnan ninf float @ldexpf(float 1.000000e+00, i32 [[TMP1]])
28+
; LDEXP-NEXT: ret float [[LDEXPF]]
29+
;
30+
; NOLDEXP-LABEL: define float @exp2_f32_sitofp_i8_flags(
31+
; NOLDEXP-SAME: i8 [[X:%.*]]) {
32+
; NOLDEXP-NEXT: [[ITOFP:%.*]] = sitofp i8 [[X]] to float
33+
; NOLDEXP-NEXT: [[EXP2:%.*]] = call nnan ninf float @llvm.exp2.f32(float [[ITOFP]])
34+
; NOLDEXP-NEXT: ret float [[EXP2]]
35+
;
36+
%itofp = sitofp i8 %x to float
37+
%exp2 = call nnan ninf float @llvm.exp2.f32(float %itofp)
38+
ret float %exp2
39+
}
40+
41+
define <2 x float> @exp2_v2f32_sitofp_v2i8(<2 x i8> %x) {
42+
; CHECK-LABEL: define <2 x float> @exp2_v2f32_sitofp_v2i8(
43+
; CHECK-SAME: <2 x i8> [[X:%.*]]) {
44+
; CHECK-NEXT: [[ITOFP:%.*]] = sitofp <2 x i8> [[X]] to <2 x float>
45+
; CHECK-NEXT: [[EXP2:%.*]] = call <2 x float> @llvm.exp2.v2f32(<2 x float> [[ITOFP]])
46+
; CHECK-NEXT: ret <2 x float> [[EXP2]]
47+
;
48+
%itofp = sitofp <2 x i8> %x to <2 x float>
49+
%exp2 = call <2 x float> @llvm.exp2.v2f32(<2 x float> %itofp)
50+
ret <2 x float> %exp2
51+
}
52+
53+
define float @exp2_f32_uitofp_i8(i8 %x) {
54+
; LDEXP-LABEL: define float @exp2_f32_uitofp_i8(
55+
; LDEXP-SAME: i8 [[X:%.*]]) {
56+
; LDEXP-NEXT: [[TMP1:%.*]] = zext i8 [[X]] to i32
57+
; LDEXP-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 [[TMP1]])
58+
; LDEXP-NEXT: ret float [[LDEXPF]]
59+
;
60+
; NOLDEXP-LABEL: define float @exp2_f32_uitofp_i8(
61+
; NOLDEXP-SAME: i8 [[X:%.*]]) {
62+
; NOLDEXP-NEXT: [[ITOFP:%.*]] = uitofp i8 [[X]] to float
63+
; NOLDEXP-NEXT: [[EXP2:%.*]] = call float @llvm.exp2.f32(float [[ITOFP]])
64+
; NOLDEXP-NEXT: ret float [[EXP2]]
65+
;
66+
%itofp = uitofp i8 %x to float
67+
%exp2 = call float @llvm.exp2.f32(float %itofp)
68+
ret float %exp2
69+
}
70+
71+
define half @exp2_f16_sitofp_i8(i8 %x) {
72+
; CHECK-LABEL: define half @exp2_f16_sitofp_i8(
73+
; CHECK-SAME: i8 [[X:%.*]]) {
74+
; CHECK-NEXT: [[ITOFP:%.*]] = sitofp i8 [[X]] to half
75+
; CHECK-NEXT: [[EXP2:%.*]] = call half @llvm.exp2.f16(half [[ITOFP]])
76+
; CHECK-NEXT: ret half [[EXP2]]
77+
;
78+
%itofp = sitofp i8 %x to half
79+
%exp2 = call half @llvm.exp2.f16(half %itofp)
80+
ret half %exp2
81+
}
82+
83+
define double @exp2_f64_sitofp_i8(i8 %x) {
84+
; LDEXP-LABEL: define double @exp2_f64_sitofp_i8(
85+
; LDEXP-SAME: i8 [[X:%.*]]) {
86+
; LDEXP-NEXT: [[TMP1:%.*]] = sext i8 [[X]] to i32
87+
; LDEXP-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
88+
; LDEXP-NEXT: ret double [[LDEXP]]
89+
;
90+
; NOLDEXP-LABEL: define double @exp2_f64_sitofp_i8(
91+
; NOLDEXP-SAME: i8 [[X:%.*]]) {
92+
; NOLDEXP-NEXT: [[ITOFP:%.*]] = sitofp i8 [[X]] to double
93+
; NOLDEXP-NEXT: [[EXP2:%.*]] = call double @llvm.exp2.f64(double [[ITOFP]])
94+
; NOLDEXP-NEXT: ret double [[EXP2]]
95+
;
96+
%itofp = sitofp i8 %x to double
97+
%exp2 = call double @llvm.exp2.f64(double %itofp)
98+
ret double %exp2
99+
}
100+
101+
define fp128 @exp2_fp128_sitofp_i8(i8 %x) {
102+
; LDEXP-LABEL: define fp128 @exp2_fp128_sitofp_i8(
103+
; LDEXP-SAME: i8 [[X:%.*]]) {
104+
; LDEXP-NEXT: [[TMP1:%.*]] = sext i8 [[X]] to i32
105+
; LDEXP-NEXT: [[LDEXPL:%.*]] = call fp128 @ldexpl(fp128 0xL00000000000000003FFF000000000000, i32 [[TMP1]])
106+
; LDEXP-NEXT: ret fp128 [[LDEXPL]]
107+
;
108+
; NOLDEXP-LABEL: define fp128 @exp2_fp128_sitofp_i8(
109+
; NOLDEXP-SAME: i8 [[X:%.*]]) {
110+
; NOLDEXP-NEXT: [[ITOFP:%.*]] = sitofp i8 [[X]] to fp128
111+
; NOLDEXP-NEXT: [[EXP2:%.*]] = call fp128 @llvm.exp2.f128(fp128 [[ITOFP]])
112+
; NOLDEXP-NEXT: ret fp128 [[EXP2]]
113+
;
114+
%itofp = sitofp i8 %x to fp128
115+
%exp2 = call fp128 @llvm.exp2.fp128(fp128 %itofp)
116+
ret fp128 %exp2
117+
}
118+
119+
define <vscale x 4 x float> @exp2_nxv4f32_sitofp_i8(<vscale x 4 x i8> %x) {
120+
; CHECK-LABEL: define <vscale x 4 x float> @exp2_nxv4f32_sitofp_i8(
121+
; CHECK-SAME: <vscale x 4 x i8> [[X:%.*]]) {
122+
; CHECK-NEXT: [[ITOFP:%.*]] = sitofp <vscale x 4 x i8> [[X]] to <vscale x 4 x float>
123+
; CHECK-NEXT: [[EXP2:%.*]] = call <vscale x 4 x float> @llvm.exp2.nxv4f32(<vscale x 4 x float> [[ITOFP]])
124+
; CHECK-NEXT: ret <vscale x 4 x float> [[EXP2]]
125+
;
126+
%itofp = sitofp <vscale x 4 x i8> %x to <vscale x 4 x float>
127+
%exp2 = call <vscale x 4 x float> @llvm.exp2.nxv4f32(<vscale x 4 x float> %itofp)
128+
ret <vscale x 4 x float> %exp2
129+
}
130+
131+
; FIXME: This asserts
132+
; define bfloat @exp2_bf16_sitofp_i8(i8 %x) {
133+
; %itofp = sitofp i8 %x to bfloat
134+
; %exp2 = call bfloat @llvm.exp2.bf16(bfloat %itofp)
135+
; ret bfloat %exp2
136+
; }
137+
138+
; FIXME: This asserts
139+
; define ppc_fp128 @exp2_ppc_fp128_sitofp_i8(i8 %x) {
140+
; %itofp = sitofp i8 %x to ppc_fp128
141+
; %exp2 = call ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %itofp)
142+
; ret ppc_fp128 %exp2
143+
; }
144+
145+
; FIXME: This asserts
146+
; define x86_fp80 @exp2_x86_fp80_sitofp_i8(i8 %x) {
147+
; %itofp = sitofp i8 %x to x86_fp80
148+
; %exp2 = call x86_fp80 @llvm.exp2.f80(x86_fp80 %itofp)
149+
; ret x86_fp80 %exp2
150+
; }

0 commit comments

Comments
 (0)