xref: /aosp_15_r20/external/llvm/test/Transforms/InstCombine/exp2-1.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; Test that the exp2 library call simplifier works correctly.
2*9880d681SAndroid Build Coastguard Worker;
3*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -instcombine -S | FileCheck %s -check-prefix=CHECK -check-prefix=INTRINSIC -check-prefix=LDEXP -check-prefix=LDEXPF
4*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -instcombine -S -mtriple=i386-pc-win32 | FileCheck %s -check-prefix=INTRINSIC -check-prefix=LDEXP -check-prefix=NOLDEXPF
5*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -instcombine -S -mtriple=amdgcn-unknown-unknown | FileCheck %s -check-prefix=INTRINSIC -check-prefix=NOLDEXP -check-prefix=NOLDEXPF
6*9880d681SAndroid Build Coastguard Worker
7*9880d681SAndroid Build Coastguard Workertarget 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"
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Workerdeclare double @exp2(double)
10*9880d681SAndroid Build Coastguard Workerdeclare float @exp2f(float)
11*9880d681SAndroid Build Coastguard Worker
12*9880d681SAndroid Build Coastguard Worker; Check exp2(sitofp(x)) -> ldexp(1.0, sext(x)).
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Workerdefine double @test_simplify1(i32 %x) {
15*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test_simplify1(
16*9880d681SAndroid Build Coastguard Worker  %conv = sitofp i32 %x to double
17*9880d681SAndroid Build Coastguard Worker  %ret = call double @exp2(double %conv)
18*9880d681SAndroid Build Coastguard Worker; CHECK: call double @ldexp
19*9880d681SAndroid Build Coastguard Worker  ret double %ret
20*9880d681SAndroid Build Coastguard Worker}
21*9880d681SAndroid Build Coastguard Worker
22*9880d681SAndroid Build Coastguard Workerdefine double @test_simplify2(i16 signext %x) {
23*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test_simplify2(
24*9880d681SAndroid Build Coastguard Worker  %conv = sitofp i16 %x to double
25*9880d681SAndroid Build Coastguard Worker  %ret = call double @exp2(double %conv)
26*9880d681SAndroid Build Coastguard Worker; CHECK: call double @ldexp
27*9880d681SAndroid Build Coastguard Worker  ret double %ret
28*9880d681SAndroid Build Coastguard Worker}
29*9880d681SAndroid Build Coastguard Worker
30*9880d681SAndroid Build Coastguard Workerdefine double @test_simplify3(i8 signext %x) {
31*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test_simplify3(
32*9880d681SAndroid Build Coastguard Worker  %conv = sitofp i8 %x to double
33*9880d681SAndroid Build Coastguard Worker  %ret = call double @exp2(double %conv)
34*9880d681SAndroid Build Coastguard Worker; CHECK: call double @ldexp
35*9880d681SAndroid Build Coastguard Worker  ret double %ret
36*9880d681SAndroid Build Coastguard Worker}
37*9880d681SAndroid Build Coastguard Worker
38*9880d681SAndroid Build Coastguard Workerdefine float @test_simplify4(i32 %x) {
39*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test_simplify4(
40*9880d681SAndroid Build Coastguard Worker  %conv = sitofp i32 %x to float
41*9880d681SAndroid Build Coastguard Worker  %ret = call float @exp2f(float %conv)
42*9880d681SAndroid Build Coastguard Worker; CHECK: call float @ldexpf
43*9880d681SAndroid Build Coastguard Worker  ret float %ret
44*9880d681SAndroid Build Coastguard Worker}
45*9880d681SAndroid Build Coastguard Worker
46*9880d681SAndroid Build Coastguard Worker; Check exp2(uitofp(x)) -> ldexp(1.0, zext(x)).
47*9880d681SAndroid Build Coastguard Worker
48*9880d681SAndroid Build Coastguard Workerdefine double @test_no_simplify1(i32 %x) {
49*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test_no_simplify1(
50*9880d681SAndroid Build Coastguard Worker  %conv = uitofp i32 %x to double
51*9880d681SAndroid Build Coastguard Worker  %ret = call double @exp2(double %conv)
52*9880d681SAndroid Build Coastguard Worker; CHECK: call double @exp2
53*9880d681SAndroid Build Coastguard Worker  ret double %ret
54*9880d681SAndroid Build Coastguard Worker}
55*9880d681SAndroid Build Coastguard Worker
56*9880d681SAndroid Build Coastguard Workerdefine double @test_simplify6(i16 zeroext %x) {
57*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test_simplify6(
58*9880d681SAndroid Build Coastguard Worker  %conv = uitofp i16 %x to double
59*9880d681SAndroid Build Coastguard Worker  %ret = call double @exp2(double %conv)
60*9880d681SAndroid Build Coastguard Worker; CHECK: call double @ldexp
61*9880d681SAndroid Build Coastguard Worker  ret double %ret
62*9880d681SAndroid Build Coastguard Worker}
63*9880d681SAndroid Build Coastguard Worker
64*9880d681SAndroid Build Coastguard Workerdefine double @test_simplify7(i8 zeroext %x) {
65*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test_simplify7(
66*9880d681SAndroid Build Coastguard Worker  %conv = uitofp i8 %x to double
67*9880d681SAndroid Build Coastguard Worker  %ret = call double @exp2(double %conv)
68*9880d681SAndroid Build Coastguard Worker; CHECK: call double @ldexp
69*9880d681SAndroid Build Coastguard Worker  ret double %ret
70*9880d681SAndroid Build Coastguard Worker}
71*9880d681SAndroid Build Coastguard Worker
72*9880d681SAndroid Build Coastguard Workerdefine float @test_simplify8(i8 zeroext %x) {
73*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test_simplify8(
74*9880d681SAndroid Build Coastguard Worker  %conv = uitofp i8 %x to float
75*9880d681SAndroid Build Coastguard Worker  %ret = call float @exp2f(float %conv)
76*9880d681SAndroid Build Coastguard Worker; CHECK: call float @ldexpf
77*9880d681SAndroid Build Coastguard Worker  ret float %ret
78*9880d681SAndroid Build Coastguard Worker}
79*9880d681SAndroid Build Coastguard Worker
80*9880d681SAndroid Build Coastguard Workerdeclare double @llvm.exp2.f64(double)
81*9880d681SAndroid Build Coastguard Workerdeclare float @llvm.exp2.f32(float)
82*9880d681SAndroid Build Coastguard Worker
83*9880d681SAndroid Build Coastguard Workerdefine double @test_simplify9(i8 zeroext %x) {
84*9880d681SAndroid Build Coastguard Worker; INTRINSIC-LABEL: @test_simplify9(
85*9880d681SAndroid Build Coastguard Worker  %conv = uitofp i8 %x to double
86*9880d681SAndroid Build Coastguard Worker  %ret = call double @llvm.exp2.f64(double %conv)
87*9880d681SAndroid Build Coastguard Worker; LDEXP: call double @ldexp
88*9880d681SAndroid Build Coastguard Worker; NOLDEXP-NOT: call double @ldexp
89*9880d681SAndroid Build Coastguard Worker  ret double %ret
90*9880d681SAndroid Build Coastguard Worker}
91*9880d681SAndroid Build Coastguard Worker
92*9880d681SAndroid Build Coastguard Workerdefine float @test_simplify10(i8 zeroext %x) {
93*9880d681SAndroid Build Coastguard Worker; INTRINSIC-LABEL: @test_simplify10(
94*9880d681SAndroid Build Coastguard Worker  %conv = uitofp i8 %x to float
95*9880d681SAndroid Build Coastguard Worker  %ret = call float @llvm.exp2.f32(float %conv)
96*9880d681SAndroid Build Coastguard Worker; LDEXPF: call float @ldexpf
97*9880d681SAndroid Build Coastguard Worker; NOLDEXPF-NOT: call float @ldexpf
98*9880d681SAndroid Build Coastguard Worker  ret float %ret
99*9880d681SAndroid Build Coastguard Worker}
100