Skip to content

Commit b4087fd

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

File tree

2 files changed

+214
-0
lines changed

2 files changed

+214
-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: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2+
; RUN: opt -S -passes=instcombine %s | FileCheck %s
3+
4+
define float @exp2_f32_sitofp_i8(i8 %x) {
5+
; CHECK-LABEL: define float @exp2_f32_sitofp_i8(
6+
; CHECK-SAME: i8 [[X:%.*]]) {
7+
; CHECK-NEXT: [[TMP1:%.*]] = sext i8 [[X]] to i32
8+
; CHECK-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 [[TMP1]])
9+
; CHECK-NEXT: ret float [[LDEXPF]]
10+
;
11+
%itofp = sitofp i8 %x to float
12+
%exp2 = call float @llvm.exp2.f32(float %itofp)
13+
ret float %exp2
14+
}
15+
16+
define float @exp2_f32_sitofp_i8_flags(i8 %x) {
17+
; CHECK-LABEL: define float @exp2_f32_sitofp_i8_flags(
18+
; CHECK-SAME: i8 [[X:%.*]]) {
19+
; CHECK-NEXT: [[TMP1:%.*]] = sext i8 [[X]] to i32
20+
; CHECK-NEXT: [[LDEXPF:%.*]] = call nnan ninf float @ldexpf(float 1.000000e+00, i32 [[TMP1]])
21+
; CHECK-NEXT: ret float [[LDEXPF]]
22+
;
23+
%itofp = sitofp i8 %x to float
24+
%exp2 = call nnan ninf float @llvm.exp2.f32(float %itofp)
25+
ret float %exp2
26+
}
27+
28+
define <2 x float> @exp2_v2f32_sitofp_v2i8(<2 x i8> %x) {
29+
; CHECK-LABEL: define <2 x float> @exp2_v2f32_sitofp_v2i8(
30+
; CHECK-SAME: <2 x i8> [[X:%.*]]) {
31+
; CHECK-NEXT: [[ITOFP:%.*]] = sitofp <2 x i8> [[X]] to <2 x float>
32+
; CHECK-NEXT: [[EXP2:%.*]] = call <2 x float> @llvm.exp2.v2f32(<2 x float> [[ITOFP]])
33+
; CHECK-NEXT: ret <2 x float> [[EXP2]]
34+
;
35+
%itofp = sitofp <2 x i8> %x to <2 x float>
36+
%exp2 = call <2 x float> @llvm.exp2.v2f32(<2 x float> %itofp)
37+
ret <2 x float> %exp2
38+
}
39+
40+
define float @exp2_f32_uitofp_i8(i8 %x) {
41+
; CHECK-LABEL: define float @exp2_f32_uitofp_i8(
42+
; CHECK-SAME: i8 [[X:%.*]]) {
43+
; CHECK-NEXT: [[TMP1:%.*]] = zext i8 [[X]] to i32
44+
; CHECK-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 [[TMP1]])
45+
; CHECK-NEXT: ret float [[LDEXPF]]
46+
;
47+
%itofp = uitofp i8 %x to float
48+
%exp2 = call float @llvm.exp2.f32(float %itofp)
49+
ret float %exp2
50+
}
51+
52+
define half @exp2_f16_sitofp_i8(i8 %x) {
53+
; CHECK-LABEL: define half @exp2_f16_sitofp_i8(
54+
; CHECK-SAME: i8 [[X:%.*]]) {
55+
; CHECK-NEXT: [[ITOFP:%.*]] = sitofp i8 [[X]] to half
56+
; CHECK-NEXT: [[EXP2:%.*]] = call half @llvm.exp2.f16(half [[ITOFP]])
57+
; CHECK-NEXT: ret half [[EXP2]]
58+
;
59+
%itofp = sitofp i8 %x to half
60+
%exp2 = call half @llvm.exp2.f16(half %itofp)
61+
ret half %exp2
62+
}
63+
64+
define double @exp2_f64_sitofp_i8(i8 %x) {
65+
; CHECK-LABEL: define double @exp2_f64_sitofp_i8(
66+
; CHECK-SAME: i8 [[X:%.*]]) {
67+
; CHECK-NEXT: [[TMP1:%.*]] = sext i8 [[X]] to i32
68+
; CHECK-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
69+
; CHECK-NEXT: ret double [[LDEXP]]
70+
;
71+
%itofp = sitofp i8 %x to double
72+
%exp2 = call double @llvm.exp2.f64(double %itofp)
73+
ret double %exp2
74+
}
75+
76+
define fp128 @exp2_fp128_sitofp_i8(i8 %x) {
77+
; CHECK-LABEL: define fp128 @exp2_fp128_sitofp_i8(
78+
; CHECK-SAME: i8 [[X:%.*]]) {
79+
; CHECK-NEXT: [[TMP1:%.*]] = sext i8 [[X]] to i32
80+
; CHECK-NEXT: [[LDEXPL:%.*]] = call fp128 @ldexpl(fp128 0xL00000000000000003FFF000000000000, i32 [[TMP1]])
81+
; CHECK-NEXT: ret fp128 [[LDEXPL]]
82+
;
83+
%itofp = sitofp i8 %x to fp128
84+
%exp2 = call fp128 @llvm.exp2.fp128(fp128 %itofp)
85+
ret fp128 %exp2
86+
}
87+
88+
define <vscale x 4 x float> @exp2_nxv4f32_sitofp_i8(<vscale x 4 x i8> %x) {
89+
; CHECK-LABEL: define <vscale x 4 x float> @exp2_nxv4f32_sitofp_i8(
90+
; CHECK-SAME: <vscale x 4 x i8> [[X:%.*]]) {
91+
; CHECK-NEXT: [[ITOFP:%.*]] = sitofp <vscale x 4 x i8> [[X]] to <vscale x 4 x float>
92+
; CHECK-NEXT: [[EXP2:%.*]] = call <vscale x 4 x float> @llvm.exp2.nxv4f32(<vscale x 4 x float> [[ITOFP]])
93+
; CHECK-NEXT: ret <vscale x 4 x float> [[EXP2]]
94+
;
95+
%itofp = sitofp <vscale x 4 x i8> %x to <vscale x 4 x float>
96+
%exp2 = call <vscale x 4 x float> @llvm.exp2.nxv4f32(<vscale x 4 x float> %itofp)
97+
ret <vscale x 4 x float> %exp2
98+
}
99+
100+
; FIXME: This asserts
101+
; define bfloat @exp2_bf16_sitofp_i8(i8 %x) {
102+
; %itofp = sitofp i8 %x to bfloat
103+
; %exp2 = call bfloat @llvm.exp2.bf16(bfloat %itofp)
104+
; ret bfloat %exp2
105+
; }
106+
107+
; FIXME: This asserts
108+
; define ppc_fp128 @exp2_ppc_fp128_sitofp_i8(i8 %x) {
109+
; %itofp = sitofp i8 %x to ppc_fp128
110+
; %exp2 = call ppc_fp128 @llvm.exp2.ppcf128(ppc_fp128 %itofp)
111+
; ret ppc_fp128 %exp2
112+
; }
113+
114+
; FIXME: This asserts
115+
; define x86_fp80 @exp2_x86_fp80_sitofp_i8(i8 %x) {
116+
; %itofp = sitofp i8 %x to x86_fp80
117+
; %exp2 = call x86_fp80 @llvm.exp2.f80(x86_fp80 %itofp)
118+
; ret x86_fp80 %exp2
119+
; }

0 commit comments

Comments
 (0)