Skip to content

Commit d5b3ba6

Browse files
authored
[SDAG] Don't handle non-canonical libcalls in SDAG lowering (#171114)
SDAG currently tries to lower certain libcalls to ISD opcodes. However, many of these are already canonicalized from libcalls to intrinsic in the middle-end (and often already emitted as intrinsics in the front-end). I believe that SDAG should not be doing anything for such libcalls. This PR just drops a single libcall to get consensus on the direction, as these changes need a non-trivial amount of test updates. A lot of the remaining libcalls *should* probably also be canonicalized to intrinsics in the middle-end when annotated with `memory(none)`, but that would require additional work in SimplifyLibCalls.
1 parent d040667 commit d5b3ba6

File tree

8 files changed

+23
-36
lines changed

8 files changed

+23
-36
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9559,6 +9559,8 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
95599559
// Check for well-known libc/libm calls. If the function is internal, it
95609560
// can't be a library call. Don't do the check if marked as nobuiltin for
95619561
// some reason.
9562+
// This code should not handle libcalls that are already canonicalized to
9563+
// intrinsics by the middle-end.
95629564
LibFunc Func;
95639565
if (!I.isNoBuiltin() && !F->hasLocalLinkage() && F->hasName() &&
95649566
LibInfo->getLibFunc(*F, Func) && LibInfo->hasOptimizedCodeGen(Func)) {
@@ -9584,30 +9586,35 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
95849586
case LibFunc_fabs:
95859587
case LibFunc_fabsf:
95869588
case LibFunc_fabsl:
9589+
// TODO: Remove this, already canonicalized by the middle-end.
95879590
if (visitUnaryFloatCall(I, ISD::FABS))
95889591
return;
95899592
break;
95909593
case LibFunc_fmin:
95919594
case LibFunc_fminf:
95929595
case LibFunc_fminl:
9596+
// TODO: Remove this, already canonicalized by the middle-end.
95939597
if (visitBinaryFloatCall(I, ISD::FMINNUM))
95949598
return;
95959599
break;
95969600
case LibFunc_fmax:
95979601
case LibFunc_fmaxf:
95989602
case LibFunc_fmaxl:
9603+
// TODO: Remove this, already canonicalized by the middle-end.
95999604
if (visitBinaryFloatCall(I, ISD::FMAXNUM))
96009605
return;
96019606
break;
96029607
case LibFunc_fminimum_num:
96039608
case LibFunc_fminimum_numf:
96049609
case LibFunc_fminimum_numl:
9610+
// TODO: Remove this, already canonicalized by the middle-end.
96059611
if (visitBinaryFloatCall(I, ISD::FMINIMUMNUM))
96069612
return;
96079613
break;
96089614
case LibFunc_fmaximum_num:
96099615
case LibFunc_fmaximum_numf:
96109616
case LibFunc_fmaximum_numl:
9617+
// TODO: Remove this, already canonicalized by the middle-end.
96119618
if (visitBinaryFloatCall(I, ISD::FMAXIMUMNUM))
96129619
return;
96139620
break;
@@ -9683,36 +9690,35 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
96839690
case LibFunc_floor:
96849691
case LibFunc_floorf:
96859692
case LibFunc_floorl:
9693+
// TODO: Remove this, already canonicalized by the middle-end.
96869694
if (visitUnaryFloatCall(I, ISD::FFLOOR))
96879695
return;
96889696
break;
9689-
case LibFunc_nearbyint:
9690-
case LibFunc_nearbyintf:
9691-
case LibFunc_nearbyintl:
9692-
if (visitUnaryFloatCall(I, ISD::FNEARBYINT))
9693-
return;
9694-
break;
96959697
case LibFunc_ceil:
96969698
case LibFunc_ceilf:
96979699
case LibFunc_ceill:
9700+
// TODO: Remove this, already canonicalized by the middle-end.
96989701
if (visitUnaryFloatCall(I, ISD::FCEIL))
96999702
return;
97009703
break;
97019704
case LibFunc_rint:
97029705
case LibFunc_rintf:
97039706
case LibFunc_rintl:
9707+
// TODO: Remove this, already canonicalized by the middle-end.
97049708
if (visitUnaryFloatCall(I, ISD::FRINT))
97059709
return;
97069710
break;
97079711
case LibFunc_round:
97089712
case LibFunc_roundf:
97099713
case LibFunc_roundl:
9714+
// TODO: Remove this, already canonicalized by the middle-end.
97109715
if (visitUnaryFloatCall(I, ISD::FROUND))
97119716
return;
97129717
break;
97139718
case LibFunc_trunc:
97149719
case LibFunc_truncf:
97159720
case LibFunc_truncl:
9721+
// TODO: Remove this, already canonicalized by the middle-end.
97169722
if (visitUnaryFloatCall(I, ISD::FTRUNC))
97179723
return;
97189724
break;

llvm/test/CodeGen/AArch64/arm64-rounding.ll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,18 @@ declare double @floor(double) nounwind readnone
2626
; CHECK: frinti
2727
define float @test3(float %a) #0 {
2828
entry:
29-
%call = tail call float @nearbyintf(float %a) nounwind readnone
29+
%call = tail call float @llvm.nearbyint.f32(float %a) nounwind readnone
3030
ret float %call
3131
}
3232

33-
declare float @nearbyintf(float) nounwind readnone
34-
3533
; CHECK-LABEL: test4:
3634
; CHECK: frinti
3735
define double @test4(double %a) #0 {
3836
entry:
39-
%call = tail call double @nearbyint(double %a) nounwind readnone
37+
%call = tail call double @llvm.nearbyint.f64(double %a) nounwind readnone
4038
ret double %call
4139
}
4240

43-
declare double @nearbyint(double) nounwind readnone
44-
4541
; CHECK-LABEL: test5:
4642
; CHECK: frintp
4743
; CHECK-NOT: frintx

llvm/test/CodeGen/AArch64/floatdp_1source.ll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ declare double @trunc(double) readonly
1919
declare float @rintf(float) readonly
2020
declare double @rint(double) readonly
2121

22-
declare float @nearbyintf(float) readonly
23-
declare double @nearbyint(double) readonly
24-
2522
define float @fabs_f(float %v) {
2623
; CHECK-LABEL: fabs_f:
2724
; CHECK: ; %bb.0:
@@ -90,7 +87,7 @@ define float @nearbyint_f(float %v) {
9087
; CHECK: ; %bb.0:
9188
; CHECK-NEXT: frinti s0, s0
9289
; CHECK-NEXT: ret
93-
%r = call float @nearbyintf(float %v)
90+
%r = call float @llvm.nearbyint.f32(float %v)
9491
ret float %r
9592
}
9693

@@ -162,7 +159,7 @@ define double @nearbyint_d(double %v) {
162159
; CHECK: ; %bb.0:
163160
; CHECK-NEXT: frinti d0, d0
164161
; CHECK-NEXT: ret
165-
%r = call double @nearbyint(double %v)
162+
%r = call double @llvm.nearbyint.f64(double %v)
166163
ret double %r
167164
}
168165

llvm/test/CodeGen/ARM/arm32-rounding.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ entry:
7474
; CHECK: vrintr.f32
7575
define float @test9(float %a) {
7676
entry:
77-
%call = call float @nearbyintf(float %a) nounwind readnone
77+
%call = call float @llvm.nearbyint.f32(float %a) nounwind readnone
7878
ret float %call
7979
}
8080

@@ -83,7 +83,7 @@ entry:
8383
; DP: vrintr.f64
8484
define double @test10(double %a) {
8585
entry:
86-
%call = call double @nearbyint(double %a) nounwind readnone
86+
%call = call double @llvm.nearbyint.f64(double %a) nounwind readnone
8787
ret double %call
8888
}
8989

@@ -128,8 +128,6 @@ declare float @roundf(float) nounwind readnone
128128
declare double @round(double) nounwind readnone
129129
declare float @truncf(float) nounwind readnone
130130
declare double @trunc(double) nounwind readnone
131-
declare float @nearbyintf(float) nounwind readnone
132-
declare double @nearbyint(double) nounwind readnone
133131
declare float @rintf(float) nounwind readnone
134132
declare double @rint(double) nounwind readnone
135133
declare float @llvm.roundeven.f32(float)

llvm/test/CodeGen/Mips/mips64-f128.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,12 +1736,10 @@ define fp128 @libcall1_nearbyintl() {
17361736
; CMP_CC_FMT-NEXT: jrc $ra
17371737
entry:
17381738
%0 = load fp128, ptr @gld0, align 16
1739-
%call = tail call fp128 @nearbyintl(fp128 %0) nounwind readnone
1739+
%call = tail call fp128 @llvm.nearbyint.f128(fp128 %0) nounwind readnone
17401740
ret fp128 %call
17411741
}
17421742

1743-
declare fp128 @nearbyintl(fp128) #1
1744-
17451743
define fp128 @libcall1_floorl() {
17461744
; C_CC_FMT-LABEL: libcall1_floorl:
17471745
; C_CC_FMT: # %bb.0: # %entry

llvm/test/CodeGen/RISCV/double-zfa.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,10 @@ define double @fround_d_5(double %a) nounwind {
250250
; CHECK: # %bb.0:
251251
; CHECK-NEXT: fround.d fa0, fa0
252252
; CHECK-NEXT: ret
253-
%call = tail call double @nearbyint(double %a) nounwind readnone
253+
%call = tail call double @llvm.nearbyint.f64(double %a) nounwind readnone
254254
ret double %call
255255
}
256256

257-
declare double @nearbyint(double) nounwind readnone
258-
259257
define double @fround_d_6(double %a) nounwind {
260258
; CHECK-LABEL: fround_d_6:
261259
; CHECK: # %bb.0:

llvm/test/CodeGen/RISCV/float-zfa.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,10 @@ define float @fround_s_5(float %a) nounwind {
183183
; CHECK: # %bb.0:
184184
; CHECK-NEXT: fround.s fa0, fa0
185185
; CHECK-NEXT: ret
186-
%call = tail call float @nearbyintf(float %a) nounwind readnone
186+
%call = tail call float @llvm.nearbyint.f32(float %a) nounwind readnone
187187
ret float %call
188188
}
189189

190-
declare float @nearbyintf(float) nounwind readnone
191-
192190
define float @fround_s_6(float %a) nounwind {
193191
; CHECK-LABEL: fround_s_6:
194192
; CHECK: # %bb.0:

llvm/test/CodeGen/X86/rounding-ops.ll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,10 @@ define float @test3(float %x) nounwind {
6060
; CHECK-AVX512: ## %bb.0:
6161
; CHECK-AVX512-NEXT: vroundss $12, %xmm0, %xmm0, %xmm0
6262
; CHECK-AVX512-NEXT: retq
63-
%call = tail call float @nearbyintf(float %x) nounwind readnone
63+
%call = tail call float @llvm.nearbyint.f32(float %x) nounwind readnone
6464
ret float %call
6565
}
6666

67-
declare float @nearbyintf(float) nounwind readnone
68-
6967
define double @test4(double %x) nounwind {
7068
; CHECK-SSE-LABEL: test4:
7169
; CHECK-SSE: ## %bb.0:
@@ -81,12 +79,10 @@ define double @test4(double %x) nounwind {
8179
; CHECK-AVX512: ## %bb.0:
8280
; CHECK-AVX512-NEXT: vroundsd $12, %xmm0, %xmm0, %xmm0
8381
; CHECK-AVX512-NEXT: retq
84-
%call = tail call double @nearbyint(double %x) nounwind readnone
82+
%call = tail call double @llvm.nearbyint.f64(double %x) nounwind readnone
8583
ret double %call
8684
}
8785

88-
declare double @nearbyint(double) nounwind readnone
89-
9086
define float @test5(float %x) nounwind {
9187
; CHECK-SSE-LABEL: test5:
9288
; CHECK-SSE: ## %bb.0:

0 commit comments

Comments
 (0)