Skip to content

Commit 0eabe65

Browse files
committed
AMDGPU: Replace ldexp libcalls with intrinsic
1 parent f337a77 commit 0eabe65

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ bool AMDGPULibCalls::fold(CallInst *CI) {
585585

586586
// Specialized optimizations for each function call.
587587
//
588-
// TODO: Handle other simple intrinsic wrappers. Sqrt, ldexp log.
588+
// TODO: Handle other simple intrinsic wrappers. Sqrt, log.
589589
//
590590
// TODO: Handle native functions
591591
switch (FInfo.getId()) {
@@ -632,6 +632,14 @@ bool AMDGPULibCalls::fold(CallInst *CI) {
632632
case AMDGPULibFunc::EI_ROUND:
633633
return tryReplaceLibcallWithSimpleIntrinsic(CI, Intrinsic::round, true,
634634
true);
635+
case AMDGPULibFunc::EI_LDEXP: {
636+
if (!shouldReplaceLibcallWithIntrinsic(CI, true, true))
637+
return false;
638+
CI->setCalledFunction(Intrinsic::getDeclaration(
639+
CI->getModule(), Intrinsic::ldexp,
640+
{CI->getType(), CI->getArgOperand(1)->getType()}));
641+
return true;
642+
}
635643
case AMDGPULibFunc::EI_POW:
636644
case AMDGPULibFunc::EI_POWR:
637645
case AMDGPULibFunc::EI_POWN:

llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-ldexp.ll

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ declare <16 x half> @_Z5ldexpDv16_DhDv16_i(<16 x half>, <16 x i32>)
2525
define float @test_ldexp_f32(float %x, i32 %y) {
2626
; CHECK-LABEL: define float @test_ldexp_f32
2727
; CHECK-SAME: (float [[X:%.*]], i32 [[Y:%.*]]) {
28-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call float @_Z5ldexpfi(float [[X]], i32 [[Y]])
28+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call float @llvm.ldexp.f32.i32(float [[X]], i32 [[Y]])
2929
; CHECK-NEXT: ret float [[LDEXP]]
3030
;
3131
%ldexp = tail call float @_Z5ldexpfi(float %x, i32 %y)
@@ -35,7 +35,7 @@ define float @test_ldexp_f32(float %x, i32 %y) {
3535
define float @test_ldexp_f32_fast(float %x, i32 %y) {
3636
; CHECK-LABEL: define float @test_ldexp_f32_fast
3737
; CHECK-SAME: (float [[X:%.*]], i32 [[Y:%.*]]) {
38-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call fast float @_Z5ldexpfi(float [[X]], i32 [[Y]])
38+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call fast float @llvm.ldexp.f32.i32(float [[X]], i32 [[Y]])
3939
; CHECK-NEXT: ret float [[LDEXP]]
4040
;
4141
%ldexp = tail call fast float @_Z5ldexpfi(float %x, i32 %y)
@@ -45,7 +45,7 @@ define float @test_ldexp_f32_fast(float %x, i32 %y) {
4545
define <2 x float> @test_ldexp_v2f32(<2 x float> %x, <2 x i32> %y) {
4646
; CHECK-LABEL: define <2 x float> @test_ldexp_v2f32
4747
; CHECK-SAME: (<2 x float> [[X:%.*]], <2 x i32> [[Y:%.*]]) {
48-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <2 x float> @_Z5ldexpDv2_fDv2_i(<2 x float> [[X]], <2 x i32> [[Y]])
48+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <2 x float> @llvm.ldexp.v2f32.v2i32(<2 x float> [[X]], <2 x i32> [[Y]])
4949
; CHECK-NEXT: ret <2 x float> [[LDEXP]]
5050
;
5151
%ldexp = tail call <2 x float> @_Z5ldexpDv2_fDv2_i(<2 x float> %x, <2 x i32> %y)
@@ -55,7 +55,7 @@ define <2 x float> @test_ldexp_v2f32(<2 x float> %x, <2 x i32> %y) {
5555
define <3 x float> @test_ldexp_v3f32(<3 x float> %x, <3 x i32> %y) {
5656
; CHECK-LABEL: define <3 x float> @test_ldexp_v3f32
5757
; CHECK-SAME: (<3 x float> [[X:%.*]], <3 x i32> [[Y:%.*]]) {
58-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <3 x float> @_Z5ldexpDv3_fDv3_i(<3 x float> [[X]], <3 x i32> [[Y]])
58+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <3 x float> @llvm.ldexp.v3f32.v3i32(<3 x float> [[X]], <3 x i32> [[Y]])
5959
; CHECK-NEXT: ret <3 x float> [[LDEXP]]
6060
;
6161
%ldexp = tail call <3 x float> @_Z5ldexpDv3_fDv3_i(<3 x float> %x, <3 x i32> %y)
@@ -65,7 +65,7 @@ define <3 x float> @test_ldexp_v3f32(<3 x float> %x, <3 x i32> %y) {
6565
define <4 x float> @test_ldexp_v4f32(<4 x float> %x, <4 x i32> %y) {
6666
; CHECK-LABEL: define <4 x float> @test_ldexp_v4f32
6767
; CHECK-SAME: (<4 x float> [[X:%.*]], <4 x i32> [[Y:%.*]]) {
68-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <4 x float> @_Z5ldexpDv4_fDv4_i(<4 x float> [[X]], <4 x i32> [[Y]])
68+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <4 x float> @llvm.ldexp.v4f32.v4i32(<4 x float> [[X]], <4 x i32> [[Y]])
6969
; CHECK-NEXT: ret <4 x float> [[LDEXP]]
7070
;
7171
%ldexp = tail call <4 x float> @_Z5ldexpDv4_fDv4_i(<4 x float> %x, <4 x i32> %y)
@@ -75,7 +75,7 @@ define <4 x float> @test_ldexp_v4f32(<4 x float> %x, <4 x i32> %y) {
7575
define <8 x float> @test_ldexp_v8f32(<8 x float> %x, <8 x i32> %y) {
7676
; CHECK-LABEL: define <8 x float> @test_ldexp_v8f32
7777
; CHECK-SAME: (<8 x float> [[X:%.*]], <8 x i32> [[Y:%.*]]) {
78-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <8 x float> @_Z5ldexpDv8_fDv8_i(<8 x float> [[X]], <8 x i32> [[Y]])
78+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <8 x float> @llvm.ldexp.v8f32.v8i32(<8 x float> [[X]], <8 x i32> [[Y]])
7979
; CHECK-NEXT: ret <8 x float> [[LDEXP]]
8080
;
8181
%ldexp = tail call <8 x float> @_Z5ldexpDv8_fDv8_i(<8 x float> %x, <8 x i32> %y)
@@ -85,7 +85,7 @@ define <8 x float> @test_ldexp_v8f32(<8 x float> %x, <8 x i32> %y) {
8585
define <16 x float> @test_ldexp_v16f32(<16 x float> %x, <16 x i32> %y) {
8686
; CHECK-LABEL: define <16 x float> @test_ldexp_v16f32
8787
; CHECK-SAME: (<16 x float> [[X:%.*]], <16 x i32> [[Y:%.*]]) {
88-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <16 x float> @_Z5ldexpDv16_fDv16_i(<16 x float> [[X]], <16 x i32> [[Y]])
88+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <16 x float> @llvm.ldexp.v16f32.v16i32(<16 x float> [[X]], <16 x i32> [[Y]])
8989
; CHECK-NEXT: ret <16 x float> [[LDEXP]]
9090
;
9191
%ldexp = tail call <16 x float> @_Z5ldexpDv16_fDv16_i(<16 x float> %x, <16 x i32> %y)
@@ -95,7 +95,7 @@ define <16 x float> @test_ldexp_v16f32(<16 x float> %x, <16 x i32> %y) {
9595
define double @test_ldexp_f64(double %x, i32 %y) {
9696
; CHECK-LABEL: define double @test_ldexp_f64
9797
; CHECK-SAME: (double [[X:%.*]], i32 [[Y:%.*]]) {
98-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call double @_Z5ldexpdi(double [[X]], i32 [[Y]])
98+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call double @llvm.ldexp.f64.i32(double [[X]], i32 [[Y]])
9999
; CHECK-NEXT: ret double [[LDEXP]]
100100
;
101101
%ldexp = tail call double @_Z5ldexpdi(double %x, i32 %y)
@@ -105,7 +105,7 @@ define double @test_ldexp_f64(double %x, i32 %y) {
105105
define <2 x double> @test_ldexp_v2f64(<2 x double> %x, <2 x i32> %y) {
106106
; CHECK-LABEL: define <2 x double> @test_ldexp_v2f64
107107
; CHECK-SAME: (<2 x double> [[X:%.*]], <2 x i32> [[Y:%.*]]) {
108-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <2 x double> @_Z5ldexpDv2_dDv2_i(<2 x double> [[X]], <2 x i32> [[Y]])
108+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <2 x double> @llvm.ldexp.v2f64.v2i32(<2 x double> [[X]], <2 x i32> [[Y]])
109109
; CHECK-NEXT: ret <2 x double> [[LDEXP]]
110110
;
111111
%ldexp = tail call <2 x double> @_Z5ldexpDv2_dDv2_i(<2 x double> %x, <2 x i32> %y)
@@ -115,7 +115,7 @@ define <2 x double> @test_ldexp_v2f64(<2 x double> %x, <2 x i32> %y) {
115115
define <3 x double> @test_ldexp_v3f64(<3 x double> %x, <3 x i32> %y) {
116116
; CHECK-LABEL: define <3 x double> @test_ldexp_v3f64
117117
; CHECK-SAME: (<3 x double> [[X:%.*]], <3 x i32> [[Y:%.*]]) {
118-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <3 x double> @_Z5ldexpDv3_dDv3_i(<3 x double> [[X]], <3 x i32> [[Y]])
118+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <3 x double> @llvm.ldexp.v3f64.v3i32(<3 x double> [[X]], <3 x i32> [[Y]])
119119
; CHECK-NEXT: ret <3 x double> [[LDEXP]]
120120
;
121121
%ldexp = tail call <3 x double> @_Z5ldexpDv3_dDv3_i(<3 x double> %x, <3 x i32> %y)
@@ -125,7 +125,7 @@ define <3 x double> @test_ldexp_v3f64(<3 x double> %x, <3 x i32> %y) {
125125
define <4 x double> @test_ldexp_v4f64(<4 x double> %x, <4 x i32> %y) {
126126
; CHECK-LABEL: define <4 x double> @test_ldexp_v4f64
127127
; CHECK-SAME: (<4 x double> [[X:%.*]], <4 x i32> [[Y:%.*]]) {
128-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <4 x double> @_Z5ldexpDv4_dDv4_i(<4 x double> [[X]], <4 x i32> [[Y]])
128+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <4 x double> @llvm.ldexp.v4f64.v4i32(<4 x double> [[X]], <4 x i32> [[Y]])
129129
; CHECK-NEXT: ret <4 x double> [[LDEXP]]
130130
;
131131
%ldexp = tail call <4 x double> @_Z5ldexpDv4_dDv4_i(<4 x double> %x, <4 x i32> %y)
@@ -135,7 +135,7 @@ define <4 x double> @test_ldexp_v4f64(<4 x double> %x, <4 x i32> %y) {
135135
define <8 x double> @test_ldexp_v8f64(<8 x double> %x, <8 x i32> %y) {
136136
; CHECK-LABEL: define <8 x double> @test_ldexp_v8f64
137137
; CHECK-SAME: (<8 x double> [[X:%.*]], <8 x i32> [[Y:%.*]]) {
138-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <8 x double> @_Z5ldexpDv8_dDv8_i(<8 x double> [[X]], <8 x i32> [[Y]])
138+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <8 x double> @llvm.ldexp.v8f64.v8i32(<8 x double> [[X]], <8 x i32> [[Y]])
139139
; CHECK-NEXT: ret <8 x double> [[LDEXP]]
140140
;
141141
%ldexp = tail call <8 x double> @_Z5ldexpDv8_dDv8_i(<8 x double> %x, <8 x i32> %y)
@@ -145,7 +145,7 @@ define <8 x double> @test_ldexp_v8f64(<8 x double> %x, <8 x i32> %y) {
145145
define <16 x double> @test_ldexp_v16f64(<16 x double> %x, <16 x i32> %y) {
146146
; CHECK-LABEL: define <16 x double> @test_ldexp_v16f64
147147
; CHECK-SAME: (<16 x double> [[X:%.*]], <16 x i32> [[Y:%.*]]) {
148-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <16 x double> @_Z5ldexpDv16_dDv16_i(<16 x double> [[X]], <16 x i32> [[Y]])
148+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <16 x double> @llvm.ldexp.v16f64.v16i32(<16 x double> [[X]], <16 x i32> [[Y]])
149149
; CHECK-NEXT: ret <16 x double> [[LDEXP]]
150150
;
151151
%ldexp = tail call <16 x double> @_Z5ldexpDv16_dDv16_i(<16 x double> %x, <16 x i32> %y)
@@ -155,7 +155,7 @@ define <16 x double> @test_ldexp_v16f64(<16 x double> %x, <16 x i32> %y) {
155155
define half @test_ldexp_f16(half %x, i32 %y) {
156156
; CHECK-LABEL: define half @test_ldexp_f16
157157
; CHECK-SAME: (half [[X:%.*]], i32 [[Y:%.*]]) {
158-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call half @_Z5ldexpDhi(half [[X]], i32 [[Y]])
158+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call half @llvm.ldexp.f16.i32(half [[X]], i32 [[Y]])
159159
; CHECK-NEXT: ret half [[LDEXP]]
160160
;
161161
%ldexp = tail call half @_Z5ldexpDhi(half %x, i32 %y)
@@ -165,7 +165,7 @@ define half @test_ldexp_f16(half %x, i32 %y) {
165165
define <2 x half> @test_ldexp_v2f16(<2 x half> %x, <2 x i32> %y) {
166166
; CHECK-LABEL: define <2 x half> @test_ldexp_v2f16
167167
; CHECK-SAME: (<2 x half> [[X:%.*]], <2 x i32> [[Y:%.*]]) {
168-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <2 x half> @_Z5ldexpDv2_DhDv2_i(<2 x half> [[X]], <2 x i32> [[Y]])
168+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <2 x half> @llvm.ldexp.v2f16.v2i32(<2 x half> [[X]], <2 x i32> [[Y]])
169169
; CHECK-NEXT: ret <2 x half> [[LDEXP]]
170170
;
171171
%ldexp = tail call <2 x half> @_Z5ldexpDv2_DhDv2_i(<2 x half> %x, <2 x i32> %y)
@@ -175,7 +175,7 @@ define <2 x half> @test_ldexp_v2f16(<2 x half> %x, <2 x i32> %y) {
175175
define <3 x half> @test_ldexp_v3f16(<3 x half> %x, <3 x i32> %y) {
176176
; CHECK-LABEL: define <3 x half> @test_ldexp_v3f16
177177
; CHECK-SAME: (<3 x half> [[X:%.*]], <3 x i32> [[Y:%.*]]) {
178-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <3 x half> @_Z5ldexpDv3_DhDv3_i(<3 x half> [[X]], <3 x i32> [[Y]])
178+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <3 x half> @llvm.ldexp.v3f16.v3i32(<3 x half> [[X]], <3 x i32> [[Y]])
179179
; CHECK-NEXT: ret <3 x half> [[LDEXP]]
180180
;
181181
%ldexp = tail call <3 x half> @_Z5ldexpDv3_DhDv3_i(<3 x half> %x, <3 x i32> %y)
@@ -185,7 +185,7 @@ define <3 x half> @test_ldexp_v3f16(<3 x half> %x, <3 x i32> %y) {
185185
define <4 x half> @test_ldexp_v4f16(<4 x half> %x, <4 x i32> %y) {
186186
; CHECK-LABEL: define <4 x half> @test_ldexp_v4f16
187187
; CHECK-SAME: (<4 x half> [[X:%.*]], <4 x i32> [[Y:%.*]]) {
188-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <4 x half> @_Z5ldexpDv4_DhDv4_i(<4 x half> [[X]], <4 x i32> [[Y]])
188+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <4 x half> @llvm.ldexp.v4f16.v4i32(<4 x half> [[X]], <4 x i32> [[Y]])
189189
; CHECK-NEXT: ret <4 x half> [[LDEXP]]
190190
;
191191
%ldexp = tail call <4 x half> @_Z5ldexpDv4_DhDv4_i(<4 x half> %x, <4 x i32> %y)
@@ -195,7 +195,7 @@ define <4 x half> @test_ldexp_v4f16(<4 x half> %x, <4 x i32> %y) {
195195
define <8 x half> @test_ldexp_v8f16(<8 x half> %x, <8 x i32> %y) {
196196
; CHECK-LABEL: define <8 x half> @test_ldexp_v8f16
197197
; CHECK-SAME: (<8 x half> [[X:%.*]], <8 x i32> [[Y:%.*]]) {
198-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <8 x half> @_Z5ldexpDv8_DhDv8_i(<8 x half> [[X]], <8 x i32> [[Y]])
198+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <8 x half> @llvm.ldexp.v8f16.v8i32(<8 x half> [[X]], <8 x i32> [[Y]])
199199
; CHECK-NEXT: ret <8 x half> [[LDEXP]]
200200
;
201201
%ldexp = tail call <8 x half> @_Z5ldexpDv8_DhDv8_i(<8 x half> %x, <8 x i32> %y)
@@ -205,7 +205,7 @@ define <8 x half> @test_ldexp_v8f16(<8 x half> %x, <8 x i32> %y) {
205205
define <16 x half> @test_ldexp_v16f16(<16 x half> %x, <16 x i32> %y) {
206206
; CHECK-LABEL: define <16 x half> @test_ldexp_v16f16
207207
; CHECK-SAME: (<16 x half> [[X:%.*]], <16 x i32> [[Y:%.*]]) {
208-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <16 x half> @_Z5ldexpDv16_DhDv16_i(<16 x half> [[X]], <16 x i32> [[Y]])
208+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call <16 x half> @llvm.ldexp.v16f16.v16i32(<16 x half> [[X]], <16 x i32> [[Y]])
209209
; CHECK-NEXT: ret <16 x half> [[LDEXP]]
210210
;
211211
%ldexp = tail call <16 x half> @_Z5ldexpDv16_DhDv16_i(<16 x half> %x, <16 x i32> %y)
@@ -215,7 +215,7 @@ define <16 x half> @test_ldexp_v16f16(<16 x half> %x, <16 x i32> %y) {
215215
define float @test_ldexp_f32_minsize(float %x, i32 %y) #3 {
216216
; CHECK-LABEL: define float @test_ldexp_f32_minsize
217217
; CHECK-SAME: (float [[X:%.*]], i32 [[Y:%.*]]) #[[ATTR0:[0-9]+]] {
218-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call float @_Z5ldexpfi(float [[X]], i32 [[Y]])
218+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call float @llvm.ldexp.f32.i32(float [[X]], i32 [[Y]])
219219
; CHECK-NEXT: ret float [[LDEXP]]
220220
;
221221
%ldexp = tail call float @_Z5ldexpfi(float %x, i32 %y)
@@ -225,7 +225,7 @@ define float @test_ldexp_f32_minsize(float %x, i32 %y) #3 {
225225
define float @test_ldexp_f32_nobuiltin(float %x, i32 %y) {
226226
; CHECK-LABEL: define float @test_ldexp_f32_nobuiltin
227227
; CHECK-SAME: (float [[X:%.*]], i32 [[Y:%.*]]) {
228-
; CHECK-NEXT: [[LDEXP:%.*]] = tail call float @_Z5ldexpfi(float [[X]], i32 [[Y]]) #[[ATTR2:[0-9]+]]
228+
; CHECK-NEXT: [[LDEXP:%.*]] = tail call float @_Z5ldexpfi(float [[X]], i32 [[Y]]) #[[ATTR3:[0-9]+]]
229229
; CHECK-NEXT: ret float [[LDEXP]]
230230
;
231231
%ldexp = tail call float @_Z5ldexpfi(float %x, i32 %y) #0

0 commit comments

Comments
 (0)