Skip to content

Conversation

@nikic
Copy link
Contributor

@nikic nikic commented Dec 9, 2025

This is a followup to #171114, removing the handling for most libcalls that are already canonicalized to intrinsics in the middle-end. The only remaining one is fabs, which has more test coverage than the others.

@llvmbot
Copy link
Member

llvmbot commented Dec 9, 2025

@llvm/pr-subscribers-backend-systemz
@llvm/pr-subscribers-backend-mips
@llvm/pr-subscribers-backend-powerpc
@llvm/pr-subscribers-backend-aarch64
@llvm/pr-subscribers-llvm-selectiondag

@llvm/pr-subscribers-backend-amdgpu

Author: Nikita Popov (nikic)

Changes

This is a followup to #171114, removing the handling for most libcalls that are already canonicalized to intrinsics in the middle-end. The only remaining one is fabs, which has more test coverage than the others.


Patch is 78.21 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/171288.diff

22 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (-63)
  • (modified) llvm/test/CodeGen/AArch64/arm64-rounding.ll (+18-38)
  • (modified) llvm/test/CodeGen/AArch64/floatdp_1source.ll (+8-20)
  • (modified) llvm/test/CodeGen/AArch64/round-conv.ll (+32-41)
  • (modified) llvm/test/CodeGen/AArch64/round-fptosi-sat-scalar.ll (+24-24)
  • (modified) llvm/test/CodeGen/AArch64/round-fptoui-sat-scalar.ll (+24-24)
  • (modified) llvm/test/CodeGen/AMDGPU/floor.ll (+2-2)
  • (modified) llvm/test/CodeGen/ARM/arm32-round-conv.ll (+16-18)
  • (modified) llvm/test/CodeGen/ARM/arm32-rounding.ll (+20-20)
  • (modified) llvm/test/CodeGen/ARM/floorf.ll (+6-6)
  • (modified) llvm/test/CodeGen/Mips/mips64-f128.ll (+3-9)
  • (modified) llvm/test/CodeGen/PowerPC/ctr-minmaxnum.ll (-97)
  • (modified) llvm/test/CodeGen/PowerPC/fminnum.ll (+32-32)
  • (modified) llvm/test/CodeGen/PowerPC/rounding-ops.ll (+16-16)
  • (modified) llvm/test/CodeGen/RISCV/double-zfa.ll (+10-10)
  • (modified) llvm/test/CodeGen/RISCV/float-zfa.ll (+10-10)
  • (modified) llvm/test/CodeGen/SystemZ/vec-max-05.ll (-36)
  • (modified) llvm/test/CodeGen/SystemZ/vec-min-05.ll (-36)
  • (modified) llvm/test/CodeGen/X86/fmaxnum.ll (+22-71)
  • (modified) llvm/test/CodeGen/X86/fminnum.ll (+22-71)
  • (modified) llvm/test/CodeGen/X86/pr31143.ll (+4-4)
  • (modified) llvm/test/CodeGen/X86/rounding-ops.ll (+20-20)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 71345509ea429..05aec6353f924 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -9590,34 +9590,6 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
         if (visitUnaryFloatCall(I, ISD::FABS))
           return;
         break;
-      case LibFunc_fmin:
-      case LibFunc_fminf:
-      case LibFunc_fminl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitBinaryFloatCall(I, ISD::FMINNUM))
-          return;
-        break;
-      case LibFunc_fmax:
-      case LibFunc_fmaxf:
-      case LibFunc_fmaxl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitBinaryFloatCall(I, ISD::FMAXNUM))
-          return;
-        break;
-      case LibFunc_fminimum_num:
-      case LibFunc_fminimum_numf:
-      case LibFunc_fminimum_numl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitBinaryFloatCall(I, ISD::FMINIMUMNUM))
-          return;
-        break;
-      case LibFunc_fmaximum_num:
-      case LibFunc_fmaximum_numf:
-      case LibFunc_fmaximum_numl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitBinaryFloatCall(I, ISD::FMAXIMUMNUM))
-          return;
-        break;
       case LibFunc_sin:
       case LibFunc_sinf:
       case LibFunc_sinl:
@@ -9687,41 +9659,6 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
         if (visitUnaryFloatCall(I, ISD::FSQRT))
           return;
         break;
-      case LibFunc_floor:
-      case LibFunc_floorf:
-      case LibFunc_floorl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FFLOOR))
-          return;
-        break;
-      case LibFunc_ceil:
-      case LibFunc_ceilf:
-      case LibFunc_ceill:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FCEIL))
-          return;
-        break;
-      case LibFunc_rint:
-      case LibFunc_rintf:
-      case LibFunc_rintl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FRINT))
-          return;
-        break;
-      case LibFunc_round:
-      case LibFunc_roundf:
-      case LibFunc_roundl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FROUND))
-          return;
-        break;
-      case LibFunc_trunc:
-      case LibFunc_truncf:
-      case LibFunc_truncl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FTRUNC))
-          return;
-        break;
       case LibFunc_log2:
       case LibFunc_log2f:
       case LibFunc_log2l:
diff --git a/llvm/test/CodeGen/AArch64/arm64-rounding.ll b/llvm/test/CodeGen/AArch64/arm64-rounding.ll
index 618731fb001ca..7ade2fd497746 100644
--- a/llvm/test/CodeGen/AArch64/arm64-rounding.ll
+++ b/llvm/test/CodeGen/AArch64/arm64-rounding.ll
@@ -5,23 +5,19 @@
 ; CHECK-NOT: frintx
 define float @test1(float %a) #0 {
 entry:
-  %call = tail call float @floorf(float %a) nounwind readnone
+  %call = tail call float @llvm.floor.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @floorf(float) nounwind readnone
-
 ; CHECK-LABEL: test2:
 ; CHECK: frintm
 ; CHECK-NOT: frintx
 define double @test2(double %a) #0 {
 entry:
-  %call = tail call double @floor(double %a) nounwind readnone
+  %call = tail call double @llvm.floor.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @floor(double) nounwind readnone
-
 ; CHECK-LABEL: test3:
 ; CHECK: frinti
 define float @test3(float %a) #0 {
@@ -43,93 +39,77 @@ entry:
 ; CHECK-NOT: frintx
 define float @test5(float %a) #0 {
 entry:
-  %call = tail call float @ceilf(float %a) nounwind readnone
+  %call = tail call float @llvm.ceil.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @ceilf(float) nounwind readnone
-
 ; CHECK-LABEL: test6:
 ; CHECK: frintp
 ; CHECK-NOT: frintx
 define double @test6(double %a) #0 {
 entry:
-  %call = tail call double @ceil(double %a) nounwind readnone
+  %call = tail call double @llvm.ceil.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @ceil(double) nounwind readnone
-
 ; CHECK-LABEL: test7:
 ; CHECK: frintx
 define float @test7(float %a) #0 {
 entry:
-  %call = tail call float @rintf(float %a) nounwind readnone
+  %call = tail call float @llvm.rint.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @rintf(float) nounwind readnone
-
 ; CHECK-LABEL: test8:
 ; CHECK: frintx
 define double @test8(double %a) #0 {
 entry:
-  %call = tail call double @rint(double %a) nounwind readnone
+  %call = tail call double @llvm.rint.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @rint(double) nounwind readnone
-
 ; CHECK-LABEL: test9:
 ; CHECK: frintz
 ; CHECK-NOT: frintx
 define float @test9(float %a) #0 {
 entry:
-  %call = tail call float @truncf(float %a) nounwind readnone
+  %call = tail call float @llvm.trunc.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @truncf(float) nounwind readnone
-
 ; CHECK-LABEL: test10:
 ; CHECK: frintz
 ; CHECK-NOT: frintx
 define double @test10(double %a) #0 {
 entry:
-  %call = tail call double @trunc(double %a) nounwind readnone
+  %call = tail call double @llvm.trunc.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @trunc(double) nounwind readnone
-
 ; CHECK-LABEL: test11:
 ; CHECK: frinta
 ; CHECK-NOT: frintx
 define float @test11(float %a) #0 {
 entry:
-  %call = tail call float @roundf(float %a) nounwind readnone
+  %call = tail call float @llvm.round.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @roundf(float %a) nounwind readnone
-
 ; CHECK-LABEL: test12:
 ; CHECK: frinta
 ; CHECK-NOT: frintx
 define double @test12(double %a) #0 {
 entry:
-  %call = tail call double @round(double %a) nounwind readnone
+  %call = tail call double @llvm.round.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @round(double %a) nounwind readnone
-
 ; CHECK-LABEL: test13:
 ; CHECK-NOT: frintx
 ; CHECK: frintm
 define float @test13(float %a) #1 {
 entry:
-  %call = tail call float @floorf(float %a) nounwind readnone
+  %call = tail call float @llvm.floor.f32(float %a) nounwind readnone
   ret float %call
 }
 
@@ -138,7 +118,7 @@ entry:
 ; CHECK: frintm
 define double @test14(double %a) #1 {
 entry:
-  %call = tail call double @floor(double %a) nounwind readnone
+  %call = tail call double @llvm.floor.f64(double %a) nounwind readnone
   ret double %call
 }
 
@@ -147,7 +127,7 @@ entry:
 ; CHECK: frintp
 define float @test15(float %a) #1 {
 entry:
-  %call = tail call float @ceilf(float %a) nounwind readnone
+  %call = tail call float @llvm.ceil.f32(float %a) nounwind readnone
   ret float %call
 }
 
@@ -156,7 +136,7 @@ entry:
 ; CHECK: frintp
 define double @test16(double %a) #1 {
 entry:
-  %call = tail call double @ceil(double %a) nounwind readnone
+  %call = tail call double @llvm.ceil.f64(double %a) nounwind readnone
   ret double %call
 }
 
@@ -165,7 +145,7 @@ entry:
 ; CHECK: frintz
 define float @test17(float %a) #1 {
 entry:
-  %call = tail call float @truncf(float %a) nounwind readnone
+  %call = tail call float @llvm.trunc.f32(float %a) nounwind readnone
   ret float %call
 }
 
@@ -174,7 +154,7 @@ entry:
 ; CHECK: frintz
 define double @test18(double %a) #1 {
 entry:
-  %call = tail call double @trunc(double %a) nounwind readnone
+  %call = tail call double @llvm.trunc.f64(double %a) nounwind readnone
   ret double %call
 }
 
@@ -183,7 +163,7 @@ entry:
 ; CHECK: frinta
 define float @test19(float %a) #1 {
 entry:
-  %call = tail call float @roundf(float %a) nounwind readnone
+  %call = tail call float @llvm.round.f32(float %a) nounwind readnone
   ret float %call
 }
 
@@ -192,7 +172,7 @@ entry:
 ; CHECK: frinta
 define double @test20(double %a) #1 {
 entry:
-  %call = tail call double @round(double %a) nounwind readnone
+  %call = tail call double @llvm.round.f64(double %a) nounwind readnone
   ret double %call
 }
 
diff --git a/llvm/test/CodeGen/AArch64/floatdp_1source.ll b/llvm/test/CodeGen/AArch64/floatdp_1source.ll
index 8d1620d62ab01..32d73d9e830f8 100644
--- a/llvm/test/CodeGen/AArch64/floatdp_1source.ll
+++ b/llvm/test/CodeGen/AArch64/floatdp_1source.ll
@@ -7,18 +7,6 @@ declare double @fabs(double) readonly
 declare float @llvm.sqrt.f32(float %Val)
 declare double @llvm.sqrt.f64(double %Val)
 
-declare float @ceilf(float) readonly
-declare double @ceil(double) readonly
-
-declare float @floorf(float) readonly
-declare double @floor(double) readonly
-
-declare float @truncf(float) readonly
-declare double @trunc(double) readonly
-
-declare float @rintf(float) readonly
-declare double @rint(double) readonly
-
 define float @fabs_f(float %v) {
 ; CHECK-LABEL: fabs_f:
 ; CHECK:       ; %bb.0:
@@ -51,7 +39,7 @@ define float @ceil_f(float %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintp s0, s0
 ; CHECK-NEXT:    ret
-  %r = call float @ceilf(float %v)
+  %r = call float @llvm.ceil.f32(float %v)
   ret float %r
 }
 
@@ -60,7 +48,7 @@ define float @floor_f(float %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintm s0, s0
 ; CHECK-NEXT:    ret
-  %r = call float @floorf(float %v)
+  %r = call float @llvm.floor.f32(float %v)
   ret float %r
 }
 
@@ -69,7 +57,7 @@ define float @trunc_f(float %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintz s0, s0
 ; CHECK-NEXT:    ret
-  %r = call float @truncf(float %v)
+  %r = call float @llvm.trunc.f32(float %v)
   ret float %r
 }
 
@@ -78,7 +66,7 @@ define float @rint_f(float %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintx s0, s0
 ; CHECK-NEXT:    ret
-  %r = call float @rintf(float %v)
+  %r = call float @llvm.rint.f32(float %v)
   ret float %r
 }
 
@@ -123,7 +111,7 @@ define double @ceil_d(double %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintp d0, d0
 ; CHECK-NEXT:    ret
-  %r = call double @ceil(double %v)
+  %r = call double @llvm.ceil.f64(double %v)
   ret double %r
 }
 
@@ -132,7 +120,7 @@ define double @floor_d(double %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintm d0, d0
 ; CHECK-NEXT:    ret
-  %r = call double @floor(double %v)
+  %r = call double @llvm.floor.f64(double %v)
   ret double %r
 }
 
@@ -141,7 +129,7 @@ define double @trunc_d(double %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintz d0, d0
 ; CHECK-NEXT:    ret
-  %r = call double @trunc(double %v)
+  %r = call double @llvm.trunc.f64(double %v)
   ret double %r
 }
 
@@ -150,7 +138,7 @@ define double @rint_d(double %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintx d0, d0
 ; CHECK-NEXT:    ret
-  %r = call double @rint(double %v)
+  %r = call double @llvm.rint.f64(double %v)
   ret double %r
 }
 
diff --git a/llvm/test/CodeGen/AArch64/round-conv.ll b/llvm/test/CodeGen/AArch64/round-conv.ll
index 5ed7d9409e3dd..d78aa207925a4 100644
--- a/llvm/test/CodeGen/AArch64/round-conv.ll
+++ b/llvm/test/CodeGen/AArch64/round-conv.ll
@@ -5,7 +5,7 @@
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testmsws(float %a) {
 entry:
-  %call = call float @floorf(float %a) nounwind readnone
+  %call = call float @llvm.floor.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i32
   ret i32 %conv
 }
@@ -15,7 +15,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testmsxs(float %a) {
 entry:
-  %call = call float @floorf(float %a) nounwind readnone
+  %call = call float @llvm.floor.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i64
   ret i64 %conv
 }
@@ -25,7 +25,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testmswd(double %a) {
 entry:
-  %call = call double @floor(double %a) nounwind readnone
+  %call = call double @llvm.floor.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i32
   ret i32 %conv
 }
@@ -35,7 +35,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testmsxd(double %a) {
 entry:
-  %call = call double @floor(double %a) nounwind readnone
+  %call = call double @llvm.floor.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i64
   ret i64 %conv
 }
@@ -45,7 +45,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testmuws(float %a) {
 entry:
-  %call = call float @floorf(float %a) nounwind readnone
+  %call = call float @llvm.floor.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i32
   ret i32 %conv
 }
@@ -55,7 +55,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testmuxs(float %a) {
 entry:
-  %call = call float @floorf(float %a) nounwind readnone
+  %call = call float @llvm.floor.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i64
   ret i64 %conv
 }
@@ -65,7 +65,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testmuwd(double %a) {
 entry:
-  %call = call double @floor(double %a) nounwind readnone
+  %call = call double @llvm.floor.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i32
   ret i32 %conv
 }
@@ -75,7 +75,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testmuxd(double %a) {
 entry:
-  %call = call double @floor(double %a) nounwind readnone
+  %call = call double @llvm.floor.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i64
   ret i64 %conv
 }
@@ -85,7 +85,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testpsws(float %a) {
 entry:
-  %call = call float @ceilf(float %a) nounwind readnone
+  %call = call float @llvm.ceil.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i32
   ret i32 %conv
 }
@@ -95,7 +95,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testpsxs(float %a) {
 entry:
-  %call = call float @ceilf(float %a) nounwind readnone
+  %call = call float @llvm.ceil.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i64
   ret i64 %conv
 }
@@ -105,7 +105,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testpswd(double %a) {
 entry:
-  %call = call double @ceil(double %a) nounwind readnone
+  %call = call double @llvm.ceil.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i32
   ret i32 %conv
 }
@@ -115,7 +115,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testpsxd(double %a) {
 entry:
-  %call = call double @ceil(double %a) nounwind readnone
+  %call = call double @llvm.ceil.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i64
   ret i64 %conv
 }
@@ -125,7 +125,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testpuws(float %a) {
 entry:
-  %call = call float @ceilf(float %a) nounwind readnone
+  %call = call float @llvm.ceil.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i32
   ret i32 %conv
 }
@@ -135,7 +135,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testpuxs(float %a) {
 entry:
-  %call = call float @ceilf(float %a) nounwind readnone
+  %call = call float @llvm.ceil.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i64
   ret i64 %conv
 }
@@ -145,7 +145,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testpuwd(double %a) {
 entry:
-  %call = call double @ceil(double %a) nounwind readnone
+  %call = call double @llvm.ceil.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i32
   ret i32 %conv
 }
@@ -155,7 +155,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testpuxd(double %a) {
 entry:
-  %call = call double @ceil(double %a) nounwind readnone
+  %call = call double @llvm.ceil.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i64
   ret i64 %conv
 }
@@ -165,7 +165,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testzsws(float %a) {
 entry:
-  %call = call float @truncf(float %a) nounwind readnone
+  %call = call float @llvm.trunc.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i32
   ret i32 %conv
 }
@@ -175,7 +175,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testzsxs(float %a) {
 entry:
-  %call = call float @truncf(float %a) nounwind readnone
+  %call = call float @llvm.trunc.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i64
   ret i64 %conv
 }
@@ -185,7 +185,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testzswd(double %a) {
 entry:
-  %call = call double @trunc(double %a) nounwind readnone
+  %call = call double @llvm.trunc.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i32
   ret i32 %conv
 }
@@ -195,7 +195,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testzsxd(double %a) {
 entry:
-  %call = call double @trunc(double %a) nounwind readnone
+  %call = call double @llvm.trunc.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i64
   ret i64 %conv
 }
@@ -205,7 +205,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testzuws(float %a) {
 entry:
-  %call = call float @truncf(float %a) nounwind readnone
+  %call = call float @llvm.trunc.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i32
   ret i32 %conv
 }
@@ -215,7 +215,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testzuxs(float %a) {
 entry:
-  %call = call float @truncf(float %a) nounwind readnone
+  %call = call float @llvm.trunc.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i64
   ret i64 %conv
 }
@@ -225,7 +225,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testzuwd(double %a) {
 entry:
-  %call = call double @trunc(double %a) nounwind readnone
+  %call = call double @llvm.trunc.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i32
   ret i32 %conv
 }
@@ -235,7 +235,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testzuxd(double %a) {
 entry:
-  %call = call double @trunc(double %a) nounwind readnone
+  %call = call double @llvm.trunc.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i64
   ret i64 %conv
 }
@@ -245,7 +245,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testasws(float %a) {
 entry:
-  %call = call float @roundf(float %a) nounwind readnone
+  %call = call float @llvm.round.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i32
   ret i32 %conv
 }
@@ -255,7 +255,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testasxs(float %a) {
 entry:
-  %call = call float @roundf(float %a) nounwind readnone
+  %call = call float @llvm.round.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i64
   ret i64 %conv
 }
@@ -265,7 +265,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testaswd(double %a) {
 entry:
-  %call = call double @round(double %a) nounwind readnone
+  %call = call double @llvm.round.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i32
   ret i32 %conv
 }
@@ -275,7 +275,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testasxd(double %a) {
 entry:
-  %call = call double @round(double %a) nounwind readnone
+  %call = call double @llvm.round.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i64
   ret i64 %conv
 }
@@ -285,7 +285,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testauws(float %a) {
 entry:
-  %call = call float @roundf(float %a) nounwind readnone
+  %call = call float @llvm.round.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i32
   ret i32 %conv
 }
@@ -295,7 +295,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testauxs(float %a) {
 entry:
-  %call = call float @roundf(float %a) nounwind readnone
+  %call = call float @llvm.round.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i64
   ret i64 %conv
 }
@@ -305,7 +305,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testauwd(double %a) {
 entry:
-  %call = call double @round(double %a) nounwind readnone
+  %call = call double @llvm.round.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i32
   ret i32 %conv
 }
@@ -315,16 +315,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testauxd(double %a) {
 entry:
-  %call = call double @round(double %a) nounwind readnone
+  %call = call double @llvm.round.f64(double %a) nounwind readnone
   %co...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Dec 9, 2025

@llvm/pr-subscribers-backend-arm

Author: Nikita Popov (nikic)

Changes

This is a followup to #171114, removing the handling for most libcalls that are already canonicalized to intrinsics in the middle-end. The only remaining one is fabs, which has more test coverage than the others.


Patch is 78.21 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/171288.diff

22 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (-63)
  • (modified) llvm/test/CodeGen/AArch64/arm64-rounding.ll (+18-38)
  • (modified) llvm/test/CodeGen/AArch64/floatdp_1source.ll (+8-20)
  • (modified) llvm/test/CodeGen/AArch64/round-conv.ll (+32-41)
  • (modified) llvm/test/CodeGen/AArch64/round-fptosi-sat-scalar.ll (+24-24)
  • (modified) llvm/test/CodeGen/AArch64/round-fptoui-sat-scalar.ll (+24-24)
  • (modified) llvm/test/CodeGen/AMDGPU/floor.ll (+2-2)
  • (modified) llvm/test/CodeGen/ARM/arm32-round-conv.ll (+16-18)
  • (modified) llvm/test/CodeGen/ARM/arm32-rounding.ll (+20-20)
  • (modified) llvm/test/CodeGen/ARM/floorf.ll (+6-6)
  • (modified) llvm/test/CodeGen/Mips/mips64-f128.ll (+3-9)
  • (modified) llvm/test/CodeGen/PowerPC/ctr-minmaxnum.ll (-97)
  • (modified) llvm/test/CodeGen/PowerPC/fminnum.ll (+32-32)
  • (modified) llvm/test/CodeGen/PowerPC/rounding-ops.ll (+16-16)
  • (modified) llvm/test/CodeGen/RISCV/double-zfa.ll (+10-10)
  • (modified) llvm/test/CodeGen/RISCV/float-zfa.ll (+10-10)
  • (modified) llvm/test/CodeGen/SystemZ/vec-max-05.ll (-36)
  • (modified) llvm/test/CodeGen/SystemZ/vec-min-05.ll (-36)
  • (modified) llvm/test/CodeGen/X86/fmaxnum.ll (+22-71)
  • (modified) llvm/test/CodeGen/X86/fminnum.ll (+22-71)
  • (modified) llvm/test/CodeGen/X86/pr31143.ll (+4-4)
  • (modified) llvm/test/CodeGen/X86/rounding-ops.ll (+20-20)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 71345509ea429..05aec6353f924 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -9590,34 +9590,6 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
         if (visitUnaryFloatCall(I, ISD::FABS))
           return;
         break;
-      case LibFunc_fmin:
-      case LibFunc_fminf:
-      case LibFunc_fminl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitBinaryFloatCall(I, ISD::FMINNUM))
-          return;
-        break;
-      case LibFunc_fmax:
-      case LibFunc_fmaxf:
-      case LibFunc_fmaxl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitBinaryFloatCall(I, ISD::FMAXNUM))
-          return;
-        break;
-      case LibFunc_fminimum_num:
-      case LibFunc_fminimum_numf:
-      case LibFunc_fminimum_numl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitBinaryFloatCall(I, ISD::FMINIMUMNUM))
-          return;
-        break;
-      case LibFunc_fmaximum_num:
-      case LibFunc_fmaximum_numf:
-      case LibFunc_fmaximum_numl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitBinaryFloatCall(I, ISD::FMAXIMUMNUM))
-          return;
-        break;
       case LibFunc_sin:
       case LibFunc_sinf:
       case LibFunc_sinl:
@@ -9687,41 +9659,6 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
         if (visitUnaryFloatCall(I, ISD::FSQRT))
           return;
         break;
-      case LibFunc_floor:
-      case LibFunc_floorf:
-      case LibFunc_floorl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FFLOOR))
-          return;
-        break;
-      case LibFunc_ceil:
-      case LibFunc_ceilf:
-      case LibFunc_ceill:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FCEIL))
-          return;
-        break;
-      case LibFunc_rint:
-      case LibFunc_rintf:
-      case LibFunc_rintl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FRINT))
-          return;
-        break;
-      case LibFunc_round:
-      case LibFunc_roundf:
-      case LibFunc_roundl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FROUND))
-          return;
-        break;
-      case LibFunc_trunc:
-      case LibFunc_truncf:
-      case LibFunc_truncl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FTRUNC))
-          return;
-        break;
       case LibFunc_log2:
       case LibFunc_log2f:
       case LibFunc_log2l:
diff --git a/llvm/test/CodeGen/AArch64/arm64-rounding.ll b/llvm/test/CodeGen/AArch64/arm64-rounding.ll
index 618731fb001ca..7ade2fd497746 100644
--- a/llvm/test/CodeGen/AArch64/arm64-rounding.ll
+++ b/llvm/test/CodeGen/AArch64/arm64-rounding.ll
@@ -5,23 +5,19 @@
 ; CHECK-NOT: frintx
 define float @test1(float %a) #0 {
 entry:
-  %call = tail call float @floorf(float %a) nounwind readnone
+  %call = tail call float @llvm.floor.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @floorf(float) nounwind readnone
-
 ; CHECK-LABEL: test2:
 ; CHECK: frintm
 ; CHECK-NOT: frintx
 define double @test2(double %a) #0 {
 entry:
-  %call = tail call double @floor(double %a) nounwind readnone
+  %call = tail call double @llvm.floor.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @floor(double) nounwind readnone
-
 ; CHECK-LABEL: test3:
 ; CHECK: frinti
 define float @test3(float %a) #0 {
@@ -43,93 +39,77 @@ entry:
 ; CHECK-NOT: frintx
 define float @test5(float %a) #0 {
 entry:
-  %call = tail call float @ceilf(float %a) nounwind readnone
+  %call = tail call float @llvm.ceil.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @ceilf(float) nounwind readnone
-
 ; CHECK-LABEL: test6:
 ; CHECK: frintp
 ; CHECK-NOT: frintx
 define double @test6(double %a) #0 {
 entry:
-  %call = tail call double @ceil(double %a) nounwind readnone
+  %call = tail call double @llvm.ceil.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @ceil(double) nounwind readnone
-
 ; CHECK-LABEL: test7:
 ; CHECK: frintx
 define float @test7(float %a) #0 {
 entry:
-  %call = tail call float @rintf(float %a) nounwind readnone
+  %call = tail call float @llvm.rint.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @rintf(float) nounwind readnone
-
 ; CHECK-LABEL: test8:
 ; CHECK: frintx
 define double @test8(double %a) #0 {
 entry:
-  %call = tail call double @rint(double %a) nounwind readnone
+  %call = tail call double @llvm.rint.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @rint(double) nounwind readnone
-
 ; CHECK-LABEL: test9:
 ; CHECK: frintz
 ; CHECK-NOT: frintx
 define float @test9(float %a) #0 {
 entry:
-  %call = tail call float @truncf(float %a) nounwind readnone
+  %call = tail call float @llvm.trunc.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @truncf(float) nounwind readnone
-
 ; CHECK-LABEL: test10:
 ; CHECK: frintz
 ; CHECK-NOT: frintx
 define double @test10(double %a) #0 {
 entry:
-  %call = tail call double @trunc(double %a) nounwind readnone
+  %call = tail call double @llvm.trunc.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @trunc(double) nounwind readnone
-
 ; CHECK-LABEL: test11:
 ; CHECK: frinta
 ; CHECK-NOT: frintx
 define float @test11(float %a) #0 {
 entry:
-  %call = tail call float @roundf(float %a) nounwind readnone
+  %call = tail call float @llvm.round.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @roundf(float %a) nounwind readnone
-
 ; CHECK-LABEL: test12:
 ; CHECK: frinta
 ; CHECK-NOT: frintx
 define double @test12(double %a) #0 {
 entry:
-  %call = tail call double @round(double %a) nounwind readnone
+  %call = tail call double @llvm.round.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @round(double %a) nounwind readnone
-
 ; CHECK-LABEL: test13:
 ; CHECK-NOT: frintx
 ; CHECK: frintm
 define float @test13(float %a) #1 {
 entry:
-  %call = tail call float @floorf(float %a) nounwind readnone
+  %call = tail call float @llvm.floor.f32(float %a) nounwind readnone
   ret float %call
 }
 
@@ -138,7 +118,7 @@ entry:
 ; CHECK: frintm
 define double @test14(double %a) #1 {
 entry:
-  %call = tail call double @floor(double %a) nounwind readnone
+  %call = tail call double @llvm.floor.f64(double %a) nounwind readnone
   ret double %call
 }
 
@@ -147,7 +127,7 @@ entry:
 ; CHECK: frintp
 define float @test15(float %a) #1 {
 entry:
-  %call = tail call float @ceilf(float %a) nounwind readnone
+  %call = tail call float @llvm.ceil.f32(float %a) nounwind readnone
   ret float %call
 }
 
@@ -156,7 +136,7 @@ entry:
 ; CHECK: frintp
 define double @test16(double %a) #1 {
 entry:
-  %call = tail call double @ceil(double %a) nounwind readnone
+  %call = tail call double @llvm.ceil.f64(double %a) nounwind readnone
   ret double %call
 }
 
@@ -165,7 +145,7 @@ entry:
 ; CHECK: frintz
 define float @test17(float %a) #1 {
 entry:
-  %call = tail call float @truncf(float %a) nounwind readnone
+  %call = tail call float @llvm.trunc.f32(float %a) nounwind readnone
   ret float %call
 }
 
@@ -174,7 +154,7 @@ entry:
 ; CHECK: frintz
 define double @test18(double %a) #1 {
 entry:
-  %call = tail call double @trunc(double %a) nounwind readnone
+  %call = tail call double @llvm.trunc.f64(double %a) nounwind readnone
   ret double %call
 }
 
@@ -183,7 +163,7 @@ entry:
 ; CHECK: frinta
 define float @test19(float %a) #1 {
 entry:
-  %call = tail call float @roundf(float %a) nounwind readnone
+  %call = tail call float @llvm.round.f32(float %a) nounwind readnone
   ret float %call
 }
 
@@ -192,7 +172,7 @@ entry:
 ; CHECK: frinta
 define double @test20(double %a) #1 {
 entry:
-  %call = tail call double @round(double %a) nounwind readnone
+  %call = tail call double @llvm.round.f64(double %a) nounwind readnone
   ret double %call
 }
 
diff --git a/llvm/test/CodeGen/AArch64/floatdp_1source.ll b/llvm/test/CodeGen/AArch64/floatdp_1source.ll
index 8d1620d62ab01..32d73d9e830f8 100644
--- a/llvm/test/CodeGen/AArch64/floatdp_1source.ll
+++ b/llvm/test/CodeGen/AArch64/floatdp_1source.ll
@@ -7,18 +7,6 @@ declare double @fabs(double) readonly
 declare float @llvm.sqrt.f32(float %Val)
 declare double @llvm.sqrt.f64(double %Val)
 
-declare float @ceilf(float) readonly
-declare double @ceil(double) readonly
-
-declare float @floorf(float) readonly
-declare double @floor(double) readonly
-
-declare float @truncf(float) readonly
-declare double @trunc(double) readonly
-
-declare float @rintf(float) readonly
-declare double @rint(double) readonly
-
 define float @fabs_f(float %v) {
 ; CHECK-LABEL: fabs_f:
 ; CHECK:       ; %bb.0:
@@ -51,7 +39,7 @@ define float @ceil_f(float %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintp s0, s0
 ; CHECK-NEXT:    ret
-  %r = call float @ceilf(float %v)
+  %r = call float @llvm.ceil.f32(float %v)
   ret float %r
 }
 
@@ -60,7 +48,7 @@ define float @floor_f(float %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintm s0, s0
 ; CHECK-NEXT:    ret
-  %r = call float @floorf(float %v)
+  %r = call float @llvm.floor.f32(float %v)
   ret float %r
 }
 
@@ -69,7 +57,7 @@ define float @trunc_f(float %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintz s0, s0
 ; CHECK-NEXT:    ret
-  %r = call float @truncf(float %v)
+  %r = call float @llvm.trunc.f32(float %v)
   ret float %r
 }
 
@@ -78,7 +66,7 @@ define float @rint_f(float %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintx s0, s0
 ; CHECK-NEXT:    ret
-  %r = call float @rintf(float %v)
+  %r = call float @llvm.rint.f32(float %v)
   ret float %r
 }
 
@@ -123,7 +111,7 @@ define double @ceil_d(double %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintp d0, d0
 ; CHECK-NEXT:    ret
-  %r = call double @ceil(double %v)
+  %r = call double @llvm.ceil.f64(double %v)
   ret double %r
 }
 
@@ -132,7 +120,7 @@ define double @floor_d(double %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintm d0, d0
 ; CHECK-NEXT:    ret
-  %r = call double @floor(double %v)
+  %r = call double @llvm.floor.f64(double %v)
   ret double %r
 }
 
@@ -141,7 +129,7 @@ define double @trunc_d(double %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintz d0, d0
 ; CHECK-NEXT:    ret
-  %r = call double @trunc(double %v)
+  %r = call double @llvm.trunc.f64(double %v)
   ret double %r
 }
 
@@ -150,7 +138,7 @@ define double @rint_d(double %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintx d0, d0
 ; CHECK-NEXT:    ret
-  %r = call double @rint(double %v)
+  %r = call double @llvm.rint.f64(double %v)
   ret double %r
 }
 
diff --git a/llvm/test/CodeGen/AArch64/round-conv.ll b/llvm/test/CodeGen/AArch64/round-conv.ll
index 5ed7d9409e3dd..d78aa207925a4 100644
--- a/llvm/test/CodeGen/AArch64/round-conv.ll
+++ b/llvm/test/CodeGen/AArch64/round-conv.ll
@@ -5,7 +5,7 @@
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testmsws(float %a) {
 entry:
-  %call = call float @floorf(float %a) nounwind readnone
+  %call = call float @llvm.floor.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i32
   ret i32 %conv
 }
@@ -15,7 +15,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testmsxs(float %a) {
 entry:
-  %call = call float @floorf(float %a) nounwind readnone
+  %call = call float @llvm.floor.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i64
   ret i64 %conv
 }
@@ -25,7 +25,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testmswd(double %a) {
 entry:
-  %call = call double @floor(double %a) nounwind readnone
+  %call = call double @llvm.floor.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i32
   ret i32 %conv
 }
@@ -35,7 +35,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testmsxd(double %a) {
 entry:
-  %call = call double @floor(double %a) nounwind readnone
+  %call = call double @llvm.floor.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i64
   ret i64 %conv
 }
@@ -45,7 +45,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testmuws(float %a) {
 entry:
-  %call = call float @floorf(float %a) nounwind readnone
+  %call = call float @llvm.floor.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i32
   ret i32 %conv
 }
@@ -55,7 +55,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testmuxs(float %a) {
 entry:
-  %call = call float @floorf(float %a) nounwind readnone
+  %call = call float @llvm.floor.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i64
   ret i64 %conv
 }
@@ -65,7 +65,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testmuwd(double %a) {
 entry:
-  %call = call double @floor(double %a) nounwind readnone
+  %call = call double @llvm.floor.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i32
   ret i32 %conv
 }
@@ -75,7 +75,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testmuxd(double %a) {
 entry:
-  %call = call double @floor(double %a) nounwind readnone
+  %call = call double @llvm.floor.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i64
   ret i64 %conv
 }
@@ -85,7 +85,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testpsws(float %a) {
 entry:
-  %call = call float @ceilf(float %a) nounwind readnone
+  %call = call float @llvm.ceil.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i32
   ret i32 %conv
 }
@@ -95,7 +95,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testpsxs(float %a) {
 entry:
-  %call = call float @ceilf(float %a) nounwind readnone
+  %call = call float @llvm.ceil.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i64
   ret i64 %conv
 }
@@ -105,7 +105,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testpswd(double %a) {
 entry:
-  %call = call double @ceil(double %a) nounwind readnone
+  %call = call double @llvm.ceil.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i32
   ret i32 %conv
 }
@@ -115,7 +115,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testpsxd(double %a) {
 entry:
-  %call = call double @ceil(double %a) nounwind readnone
+  %call = call double @llvm.ceil.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i64
   ret i64 %conv
 }
@@ -125,7 +125,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testpuws(float %a) {
 entry:
-  %call = call float @ceilf(float %a) nounwind readnone
+  %call = call float @llvm.ceil.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i32
   ret i32 %conv
 }
@@ -135,7 +135,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testpuxs(float %a) {
 entry:
-  %call = call float @ceilf(float %a) nounwind readnone
+  %call = call float @llvm.ceil.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i64
   ret i64 %conv
 }
@@ -145,7 +145,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testpuwd(double %a) {
 entry:
-  %call = call double @ceil(double %a) nounwind readnone
+  %call = call double @llvm.ceil.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i32
   ret i32 %conv
 }
@@ -155,7 +155,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testpuxd(double %a) {
 entry:
-  %call = call double @ceil(double %a) nounwind readnone
+  %call = call double @llvm.ceil.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i64
   ret i64 %conv
 }
@@ -165,7 +165,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testzsws(float %a) {
 entry:
-  %call = call float @truncf(float %a) nounwind readnone
+  %call = call float @llvm.trunc.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i32
   ret i32 %conv
 }
@@ -175,7 +175,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testzsxs(float %a) {
 entry:
-  %call = call float @truncf(float %a) nounwind readnone
+  %call = call float @llvm.trunc.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i64
   ret i64 %conv
 }
@@ -185,7 +185,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testzswd(double %a) {
 entry:
-  %call = call double @trunc(double %a) nounwind readnone
+  %call = call double @llvm.trunc.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i32
   ret i32 %conv
 }
@@ -195,7 +195,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testzsxd(double %a) {
 entry:
-  %call = call double @trunc(double %a) nounwind readnone
+  %call = call double @llvm.trunc.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i64
   ret i64 %conv
 }
@@ -205,7 +205,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testzuws(float %a) {
 entry:
-  %call = call float @truncf(float %a) nounwind readnone
+  %call = call float @llvm.trunc.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i32
   ret i32 %conv
 }
@@ -215,7 +215,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testzuxs(float %a) {
 entry:
-  %call = call float @truncf(float %a) nounwind readnone
+  %call = call float @llvm.trunc.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i64
   ret i64 %conv
 }
@@ -225,7 +225,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testzuwd(double %a) {
 entry:
-  %call = call double @trunc(double %a) nounwind readnone
+  %call = call double @llvm.trunc.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i32
   ret i32 %conv
 }
@@ -235,7 +235,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testzuxd(double %a) {
 entry:
-  %call = call double @trunc(double %a) nounwind readnone
+  %call = call double @llvm.trunc.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i64
   ret i64 %conv
 }
@@ -245,7 +245,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testasws(float %a) {
 entry:
-  %call = call float @roundf(float %a) nounwind readnone
+  %call = call float @llvm.round.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i32
   ret i32 %conv
 }
@@ -255,7 +255,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testasxs(float %a) {
 entry:
-  %call = call float @roundf(float %a) nounwind readnone
+  %call = call float @llvm.round.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i64
   ret i64 %conv
 }
@@ -265,7 +265,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testaswd(double %a) {
 entry:
-  %call = call double @round(double %a) nounwind readnone
+  %call = call double @llvm.round.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i32
   ret i32 %conv
 }
@@ -275,7 +275,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testasxd(double %a) {
 entry:
-  %call = call double @round(double %a) nounwind readnone
+  %call = call double @llvm.round.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i64
   ret i64 %conv
 }
@@ -285,7 +285,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testauws(float %a) {
 entry:
-  %call = call float @roundf(float %a) nounwind readnone
+  %call = call float @llvm.round.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i32
   ret i32 %conv
 }
@@ -295,7 +295,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testauxs(float %a) {
 entry:
-  %call = call float @roundf(float %a) nounwind readnone
+  %call = call float @llvm.round.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i64
   ret i64 %conv
 }
@@ -305,7 +305,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testauwd(double %a) {
 entry:
-  %call = call double @round(double %a) nounwind readnone
+  %call = call double @llvm.round.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i32
   ret i32 %conv
 }
@@ -315,16 +315,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testauxd(double %a) {
 entry:
-  %call = call double @round(double %a) nounwind readnone
+  %call = call double @llvm.round.f64(double %a) nounwind readnone
   %co...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Dec 9, 2025

@llvm/pr-subscribers-backend-x86

Author: Nikita Popov (nikic)

Changes

This is a followup to #171114, removing the handling for most libcalls that are already canonicalized to intrinsics in the middle-end. The only remaining one is fabs, which has more test coverage than the others.


Patch is 78.21 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/171288.diff

22 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (-63)
  • (modified) llvm/test/CodeGen/AArch64/arm64-rounding.ll (+18-38)
  • (modified) llvm/test/CodeGen/AArch64/floatdp_1source.ll (+8-20)
  • (modified) llvm/test/CodeGen/AArch64/round-conv.ll (+32-41)
  • (modified) llvm/test/CodeGen/AArch64/round-fptosi-sat-scalar.ll (+24-24)
  • (modified) llvm/test/CodeGen/AArch64/round-fptoui-sat-scalar.ll (+24-24)
  • (modified) llvm/test/CodeGen/AMDGPU/floor.ll (+2-2)
  • (modified) llvm/test/CodeGen/ARM/arm32-round-conv.ll (+16-18)
  • (modified) llvm/test/CodeGen/ARM/arm32-rounding.ll (+20-20)
  • (modified) llvm/test/CodeGen/ARM/floorf.ll (+6-6)
  • (modified) llvm/test/CodeGen/Mips/mips64-f128.ll (+3-9)
  • (modified) llvm/test/CodeGen/PowerPC/ctr-minmaxnum.ll (-97)
  • (modified) llvm/test/CodeGen/PowerPC/fminnum.ll (+32-32)
  • (modified) llvm/test/CodeGen/PowerPC/rounding-ops.ll (+16-16)
  • (modified) llvm/test/CodeGen/RISCV/double-zfa.ll (+10-10)
  • (modified) llvm/test/CodeGen/RISCV/float-zfa.ll (+10-10)
  • (modified) llvm/test/CodeGen/SystemZ/vec-max-05.ll (-36)
  • (modified) llvm/test/CodeGen/SystemZ/vec-min-05.ll (-36)
  • (modified) llvm/test/CodeGen/X86/fmaxnum.ll (+22-71)
  • (modified) llvm/test/CodeGen/X86/fminnum.ll (+22-71)
  • (modified) llvm/test/CodeGen/X86/pr31143.ll (+4-4)
  • (modified) llvm/test/CodeGen/X86/rounding-ops.ll (+20-20)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 71345509ea429..05aec6353f924 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -9590,34 +9590,6 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
         if (visitUnaryFloatCall(I, ISD::FABS))
           return;
         break;
-      case LibFunc_fmin:
-      case LibFunc_fminf:
-      case LibFunc_fminl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitBinaryFloatCall(I, ISD::FMINNUM))
-          return;
-        break;
-      case LibFunc_fmax:
-      case LibFunc_fmaxf:
-      case LibFunc_fmaxl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitBinaryFloatCall(I, ISD::FMAXNUM))
-          return;
-        break;
-      case LibFunc_fminimum_num:
-      case LibFunc_fminimum_numf:
-      case LibFunc_fminimum_numl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitBinaryFloatCall(I, ISD::FMINIMUMNUM))
-          return;
-        break;
-      case LibFunc_fmaximum_num:
-      case LibFunc_fmaximum_numf:
-      case LibFunc_fmaximum_numl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitBinaryFloatCall(I, ISD::FMAXIMUMNUM))
-          return;
-        break;
       case LibFunc_sin:
       case LibFunc_sinf:
       case LibFunc_sinl:
@@ -9687,41 +9659,6 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
         if (visitUnaryFloatCall(I, ISD::FSQRT))
           return;
         break;
-      case LibFunc_floor:
-      case LibFunc_floorf:
-      case LibFunc_floorl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FFLOOR))
-          return;
-        break;
-      case LibFunc_ceil:
-      case LibFunc_ceilf:
-      case LibFunc_ceill:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FCEIL))
-          return;
-        break;
-      case LibFunc_rint:
-      case LibFunc_rintf:
-      case LibFunc_rintl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FRINT))
-          return;
-        break;
-      case LibFunc_round:
-      case LibFunc_roundf:
-      case LibFunc_roundl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FROUND))
-          return;
-        break;
-      case LibFunc_trunc:
-      case LibFunc_truncf:
-      case LibFunc_truncl:
-        // TODO: Remove this, already canonicalized by the middle-end.
-        if (visitUnaryFloatCall(I, ISD::FTRUNC))
-          return;
-        break;
       case LibFunc_log2:
       case LibFunc_log2f:
       case LibFunc_log2l:
diff --git a/llvm/test/CodeGen/AArch64/arm64-rounding.ll b/llvm/test/CodeGen/AArch64/arm64-rounding.ll
index 618731fb001ca..7ade2fd497746 100644
--- a/llvm/test/CodeGen/AArch64/arm64-rounding.ll
+++ b/llvm/test/CodeGen/AArch64/arm64-rounding.ll
@@ -5,23 +5,19 @@
 ; CHECK-NOT: frintx
 define float @test1(float %a) #0 {
 entry:
-  %call = tail call float @floorf(float %a) nounwind readnone
+  %call = tail call float @llvm.floor.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @floorf(float) nounwind readnone
-
 ; CHECK-LABEL: test2:
 ; CHECK: frintm
 ; CHECK-NOT: frintx
 define double @test2(double %a) #0 {
 entry:
-  %call = tail call double @floor(double %a) nounwind readnone
+  %call = tail call double @llvm.floor.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @floor(double) nounwind readnone
-
 ; CHECK-LABEL: test3:
 ; CHECK: frinti
 define float @test3(float %a) #0 {
@@ -43,93 +39,77 @@ entry:
 ; CHECK-NOT: frintx
 define float @test5(float %a) #0 {
 entry:
-  %call = tail call float @ceilf(float %a) nounwind readnone
+  %call = tail call float @llvm.ceil.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @ceilf(float) nounwind readnone
-
 ; CHECK-LABEL: test6:
 ; CHECK: frintp
 ; CHECK-NOT: frintx
 define double @test6(double %a) #0 {
 entry:
-  %call = tail call double @ceil(double %a) nounwind readnone
+  %call = tail call double @llvm.ceil.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @ceil(double) nounwind readnone
-
 ; CHECK-LABEL: test7:
 ; CHECK: frintx
 define float @test7(float %a) #0 {
 entry:
-  %call = tail call float @rintf(float %a) nounwind readnone
+  %call = tail call float @llvm.rint.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @rintf(float) nounwind readnone
-
 ; CHECK-LABEL: test8:
 ; CHECK: frintx
 define double @test8(double %a) #0 {
 entry:
-  %call = tail call double @rint(double %a) nounwind readnone
+  %call = tail call double @llvm.rint.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @rint(double) nounwind readnone
-
 ; CHECK-LABEL: test9:
 ; CHECK: frintz
 ; CHECK-NOT: frintx
 define float @test9(float %a) #0 {
 entry:
-  %call = tail call float @truncf(float %a) nounwind readnone
+  %call = tail call float @llvm.trunc.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @truncf(float) nounwind readnone
-
 ; CHECK-LABEL: test10:
 ; CHECK: frintz
 ; CHECK-NOT: frintx
 define double @test10(double %a) #0 {
 entry:
-  %call = tail call double @trunc(double %a) nounwind readnone
+  %call = tail call double @llvm.trunc.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @trunc(double) nounwind readnone
-
 ; CHECK-LABEL: test11:
 ; CHECK: frinta
 ; CHECK-NOT: frintx
 define float @test11(float %a) #0 {
 entry:
-  %call = tail call float @roundf(float %a) nounwind readnone
+  %call = tail call float @llvm.round.f32(float %a) nounwind readnone
   ret float %call
 }
 
-declare float @roundf(float %a) nounwind readnone
-
 ; CHECK-LABEL: test12:
 ; CHECK: frinta
 ; CHECK-NOT: frintx
 define double @test12(double %a) #0 {
 entry:
-  %call = tail call double @round(double %a) nounwind readnone
+  %call = tail call double @llvm.round.f64(double %a) nounwind readnone
   ret double %call
 }
 
-declare double @round(double %a) nounwind readnone
-
 ; CHECK-LABEL: test13:
 ; CHECK-NOT: frintx
 ; CHECK: frintm
 define float @test13(float %a) #1 {
 entry:
-  %call = tail call float @floorf(float %a) nounwind readnone
+  %call = tail call float @llvm.floor.f32(float %a) nounwind readnone
   ret float %call
 }
 
@@ -138,7 +118,7 @@ entry:
 ; CHECK: frintm
 define double @test14(double %a) #1 {
 entry:
-  %call = tail call double @floor(double %a) nounwind readnone
+  %call = tail call double @llvm.floor.f64(double %a) nounwind readnone
   ret double %call
 }
 
@@ -147,7 +127,7 @@ entry:
 ; CHECK: frintp
 define float @test15(float %a) #1 {
 entry:
-  %call = tail call float @ceilf(float %a) nounwind readnone
+  %call = tail call float @llvm.ceil.f32(float %a) nounwind readnone
   ret float %call
 }
 
@@ -156,7 +136,7 @@ entry:
 ; CHECK: frintp
 define double @test16(double %a) #1 {
 entry:
-  %call = tail call double @ceil(double %a) nounwind readnone
+  %call = tail call double @llvm.ceil.f64(double %a) nounwind readnone
   ret double %call
 }
 
@@ -165,7 +145,7 @@ entry:
 ; CHECK: frintz
 define float @test17(float %a) #1 {
 entry:
-  %call = tail call float @truncf(float %a) nounwind readnone
+  %call = tail call float @llvm.trunc.f32(float %a) nounwind readnone
   ret float %call
 }
 
@@ -174,7 +154,7 @@ entry:
 ; CHECK: frintz
 define double @test18(double %a) #1 {
 entry:
-  %call = tail call double @trunc(double %a) nounwind readnone
+  %call = tail call double @llvm.trunc.f64(double %a) nounwind readnone
   ret double %call
 }
 
@@ -183,7 +163,7 @@ entry:
 ; CHECK: frinta
 define float @test19(float %a) #1 {
 entry:
-  %call = tail call float @roundf(float %a) nounwind readnone
+  %call = tail call float @llvm.round.f32(float %a) nounwind readnone
   ret float %call
 }
 
@@ -192,7 +172,7 @@ entry:
 ; CHECK: frinta
 define double @test20(double %a) #1 {
 entry:
-  %call = tail call double @round(double %a) nounwind readnone
+  %call = tail call double @llvm.round.f64(double %a) nounwind readnone
   ret double %call
 }
 
diff --git a/llvm/test/CodeGen/AArch64/floatdp_1source.ll b/llvm/test/CodeGen/AArch64/floatdp_1source.ll
index 8d1620d62ab01..32d73d9e830f8 100644
--- a/llvm/test/CodeGen/AArch64/floatdp_1source.ll
+++ b/llvm/test/CodeGen/AArch64/floatdp_1source.ll
@@ -7,18 +7,6 @@ declare double @fabs(double) readonly
 declare float @llvm.sqrt.f32(float %Val)
 declare double @llvm.sqrt.f64(double %Val)
 
-declare float @ceilf(float) readonly
-declare double @ceil(double) readonly
-
-declare float @floorf(float) readonly
-declare double @floor(double) readonly
-
-declare float @truncf(float) readonly
-declare double @trunc(double) readonly
-
-declare float @rintf(float) readonly
-declare double @rint(double) readonly
-
 define float @fabs_f(float %v) {
 ; CHECK-LABEL: fabs_f:
 ; CHECK:       ; %bb.0:
@@ -51,7 +39,7 @@ define float @ceil_f(float %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintp s0, s0
 ; CHECK-NEXT:    ret
-  %r = call float @ceilf(float %v)
+  %r = call float @llvm.ceil.f32(float %v)
   ret float %r
 }
 
@@ -60,7 +48,7 @@ define float @floor_f(float %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintm s0, s0
 ; CHECK-NEXT:    ret
-  %r = call float @floorf(float %v)
+  %r = call float @llvm.floor.f32(float %v)
   ret float %r
 }
 
@@ -69,7 +57,7 @@ define float @trunc_f(float %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintz s0, s0
 ; CHECK-NEXT:    ret
-  %r = call float @truncf(float %v)
+  %r = call float @llvm.trunc.f32(float %v)
   ret float %r
 }
 
@@ -78,7 +66,7 @@ define float @rint_f(float %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintx s0, s0
 ; CHECK-NEXT:    ret
-  %r = call float @rintf(float %v)
+  %r = call float @llvm.rint.f32(float %v)
   ret float %r
 }
 
@@ -123,7 +111,7 @@ define double @ceil_d(double %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintp d0, d0
 ; CHECK-NEXT:    ret
-  %r = call double @ceil(double %v)
+  %r = call double @llvm.ceil.f64(double %v)
   ret double %r
 }
 
@@ -132,7 +120,7 @@ define double @floor_d(double %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintm d0, d0
 ; CHECK-NEXT:    ret
-  %r = call double @floor(double %v)
+  %r = call double @llvm.floor.f64(double %v)
   ret double %r
 }
 
@@ -141,7 +129,7 @@ define double @trunc_d(double %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintz d0, d0
 ; CHECK-NEXT:    ret
-  %r = call double @trunc(double %v)
+  %r = call double @llvm.trunc.f64(double %v)
   ret double %r
 }
 
@@ -150,7 +138,7 @@ define double @rint_d(double %v) {
 ; CHECK:       ; %bb.0:
 ; CHECK-NEXT:    frintx d0, d0
 ; CHECK-NEXT:    ret
-  %r = call double @rint(double %v)
+  %r = call double @llvm.rint.f64(double %v)
   ret double %r
 }
 
diff --git a/llvm/test/CodeGen/AArch64/round-conv.ll b/llvm/test/CodeGen/AArch64/round-conv.ll
index 5ed7d9409e3dd..d78aa207925a4 100644
--- a/llvm/test/CodeGen/AArch64/round-conv.ll
+++ b/llvm/test/CodeGen/AArch64/round-conv.ll
@@ -5,7 +5,7 @@
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testmsws(float %a) {
 entry:
-  %call = call float @floorf(float %a) nounwind readnone
+  %call = call float @llvm.floor.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i32
   ret i32 %conv
 }
@@ -15,7 +15,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testmsxs(float %a) {
 entry:
-  %call = call float @floorf(float %a) nounwind readnone
+  %call = call float @llvm.floor.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i64
   ret i64 %conv
 }
@@ -25,7 +25,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testmswd(double %a) {
 entry:
-  %call = call double @floor(double %a) nounwind readnone
+  %call = call double @llvm.floor.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i32
   ret i32 %conv
 }
@@ -35,7 +35,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testmsxd(double %a) {
 entry:
-  %call = call double @floor(double %a) nounwind readnone
+  %call = call double @llvm.floor.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i64
   ret i64 %conv
 }
@@ -45,7 +45,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testmuws(float %a) {
 entry:
-  %call = call float @floorf(float %a) nounwind readnone
+  %call = call float @llvm.floor.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i32
   ret i32 %conv
 }
@@ -55,7 +55,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testmuxs(float %a) {
 entry:
-  %call = call float @floorf(float %a) nounwind readnone
+  %call = call float @llvm.floor.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i64
   ret i64 %conv
 }
@@ -65,7 +65,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testmuwd(double %a) {
 entry:
-  %call = call double @floor(double %a) nounwind readnone
+  %call = call double @llvm.floor.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i32
   ret i32 %conv
 }
@@ -75,7 +75,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testmuxd(double %a) {
 entry:
-  %call = call double @floor(double %a) nounwind readnone
+  %call = call double @llvm.floor.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i64
   ret i64 %conv
 }
@@ -85,7 +85,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testpsws(float %a) {
 entry:
-  %call = call float @ceilf(float %a) nounwind readnone
+  %call = call float @llvm.ceil.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i32
   ret i32 %conv
 }
@@ -95,7 +95,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testpsxs(float %a) {
 entry:
-  %call = call float @ceilf(float %a) nounwind readnone
+  %call = call float @llvm.ceil.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i64
   ret i64 %conv
 }
@@ -105,7 +105,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testpswd(double %a) {
 entry:
-  %call = call double @ceil(double %a) nounwind readnone
+  %call = call double @llvm.ceil.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i32
   ret i32 %conv
 }
@@ -115,7 +115,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testpsxd(double %a) {
 entry:
-  %call = call double @ceil(double %a) nounwind readnone
+  %call = call double @llvm.ceil.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i64
   ret i64 %conv
 }
@@ -125,7 +125,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testpuws(float %a) {
 entry:
-  %call = call float @ceilf(float %a) nounwind readnone
+  %call = call float @llvm.ceil.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i32
   ret i32 %conv
 }
@@ -135,7 +135,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testpuxs(float %a) {
 entry:
-  %call = call float @ceilf(float %a) nounwind readnone
+  %call = call float @llvm.ceil.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i64
   ret i64 %conv
 }
@@ -145,7 +145,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testpuwd(double %a) {
 entry:
-  %call = call double @ceil(double %a) nounwind readnone
+  %call = call double @llvm.ceil.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i32
   ret i32 %conv
 }
@@ -155,7 +155,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testpuxd(double %a) {
 entry:
-  %call = call double @ceil(double %a) nounwind readnone
+  %call = call double @llvm.ceil.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i64
   ret i64 %conv
 }
@@ -165,7 +165,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testzsws(float %a) {
 entry:
-  %call = call float @truncf(float %a) nounwind readnone
+  %call = call float @llvm.trunc.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i32
   ret i32 %conv
 }
@@ -175,7 +175,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testzsxs(float %a) {
 entry:
-  %call = call float @truncf(float %a) nounwind readnone
+  %call = call float @llvm.trunc.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i64
   ret i64 %conv
 }
@@ -185,7 +185,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testzswd(double %a) {
 entry:
-  %call = call double @trunc(double %a) nounwind readnone
+  %call = call double @llvm.trunc.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i32
   ret i32 %conv
 }
@@ -195,7 +195,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testzsxd(double %a) {
 entry:
-  %call = call double @trunc(double %a) nounwind readnone
+  %call = call double @llvm.trunc.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i64
   ret i64 %conv
 }
@@ -205,7 +205,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testzuws(float %a) {
 entry:
-  %call = call float @truncf(float %a) nounwind readnone
+  %call = call float @llvm.trunc.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i32
   ret i32 %conv
 }
@@ -215,7 +215,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testzuxs(float %a) {
 entry:
-  %call = call float @truncf(float %a) nounwind readnone
+  %call = call float @llvm.trunc.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i64
   ret i64 %conv
 }
@@ -225,7 +225,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testzuwd(double %a) {
 entry:
-  %call = call double @trunc(double %a) nounwind readnone
+  %call = call double @llvm.trunc.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i32
   ret i32 %conv
 }
@@ -235,7 +235,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testzuxd(double %a) {
 entry:
-  %call = call double @trunc(double %a) nounwind readnone
+  %call = call double @llvm.trunc.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i64
   ret i64 %conv
 }
@@ -245,7 +245,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testasws(float %a) {
 entry:
-  %call = call float @roundf(float %a) nounwind readnone
+  %call = call float @llvm.round.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i32
   ret i32 %conv
 }
@@ -255,7 +255,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testasxs(float %a) {
 entry:
-  %call = call float @roundf(float %a) nounwind readnone
+  %call = call float @llvm.round.f32(float %a) nounwind readnone
   %conv = fptosi float %call to i64
   ret i64 %conv
 }
@@ -265,7 +265,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testaswd(double %a) {
 entry:
-  %call = call double @round(double %a) nounwind readnone
+  %call = call double @llvm.round.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i32
   ret i32 %conv
 }
@@ -275,7 +275,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testasxd(double %a) {
 entry:
-  %call = call double @round(double %a) nounwind readnone
+  %call = call double @llvm.round.f64(double %a) nounwind readnone
   %conv = fptosi double %call to i64
   ret i64 %conv
 }
@@ -285,7 +285,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i32 @testauws(float %a) {
 entry:
-  %call = call float @roundf(float %a) nounwind readnone
+  %call = call float @llvm.round.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i32
   ret i32 %conv
 }
@@ -295,7 +295,7 @@ entry:
 ; CHECK-NOT: frintx {{s[0-9]+}}, s0
 define i64 @testauxs(float %a) {
 entry:
-  %call = call float @roundf(float %a) nounwind readnone
+  %call = call float @llvm.round.f32(float %a) nounwind readnone
   %conv = fptoui float %call to i64
   ret i64 %conv
 }
@@ -305,7 +305,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i32 @testauwd(double %a) {
 entry:
-  %call = call double @round(double %a) nounwind readnone
+  %call = call double @llvm.round.f64(double %a) nounwind readnone
   %conv = fptoui double %call to i32
   ret i32 %conv
 }
@@ -315,16 +315,7 @@ entry:
 ; CHECK-NOT: frintx {{d[0-9]+}}, d0
 define i64 @testauxd(double %a) {
 entry:
-  %call = call double @round(double %a) nounwind readnone
+  %call = call double @llvm.round.f64(double %a) nounwind readnone
   %co...
[truncated]

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There

declare fp128 @llvm.maximum.f128(fp128, fp128)

; Test the fmax library function.
define double @f1(double %dummy, double %val1, double %val2) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing the background here, but why do we need to remove these tests? Shouldn't this still work as before, no matter where exactly the lowering of fmax etc takes place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test file already has separate tests for the intrinsics, so I did not convert the libcalls to intrinsics as in most other tests.

I have also left some libcalls in other tests (e.g. the see X86 ones below) to have some coverage for the "do nothing" libcall lowering, but I don't think we need those for each target.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the PR to keep these tests and show the new codegen instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so this means fmax is not actually handled at all anymore? I thought we'd still get the same codegen, just the handling is now done earlier? Where does the translation from the library call to the intrinsic happen now, and why don't we see it in this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It happens in the middle-end: https://llvm.godbolt.org/z/PczTGE6Pz

Backend tests do not run the middle-end pipeline, they expect to work on already canonical IR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got it now, thanks! That seem fine to me.

@nikic nikic force-pushed the sdag-libcalls-remove-2 branch from f2132ca to f596ebc Compare December 9, 2025 09:55
@nikic nikic merged commit 5a24dfa into llvm:main Dec 10, 2025
10 checks passed
@nikic nikic deleted the sdag-libcalls-remove-2 branch December 10, 2025 10:45
valadaptive added a commit to valadaptive/llvm-project that referenced this pull request Dec 10, 2025
llvm#171288 changed the tests to call into floating-point intrinsics instead
of libcalls, and these attributes are already implied.
boomanaiden154 added a commit to boomanaiden154/Halide that referenced this pull request Dec 11, 2025
llvm/llvm-project#171288 removed the SDAG
lowering for ceil/ceilf calls. This was causing some errors for us when
using webassembly:

Internal Error at third_party/halide/halide/src/WasmExecutor.cpp:2368 Condition failed: instance: Error initializing module: invalid import "env.ceilf"

Explicitly using the intrinsics is still covered by webassembly and
given the commenting out of these intrinsics mentions that they were not
used due to needing to support LLVM <3.3, I think we can safely enable
these now.
nikic added a commit that referenced this pull request Dec 11, 2025
The fast instruction selector should should not force an SDAG fallback
to potentially make use of optimized libcall implementations.

Looking at
3e6fa46,
part of the motivation was to avoid libcalls in unoptimized builds for
targets that don't have them, but I believe this should be handled by
Clang directly emitting intrinsics instead of libcalls (which it already
does). FastISel should not second guess this.

Followup to #171288.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Dec 11, 2025
The fast instruction selector should should not force an SDAG fallback
to potentially make use of optimized libcall implementations.

Looking at
llvm/llvm-project@3e6fa46,
part of the motivation was to avoid libcalls in unoptimized builds for
targets that don't have them, but I believe this should be handled by
Clang directly emitting intrinsics instead of libcalls (which it already
does). FastISel should not second guess this.

Followup to llvm/llvm-project#171288.
abadams pushed a commit to halide/Halide that referenced this pull request Dec 11, 2025
llvm/llvm-project#171288 removed the SDAG
lowering for ceil/ceilf calls. This was causing some errors for us when
using webassembly:

Internal Error at third_party/halide/halide/src/WasmExecutor.cpp:2368 Condition failed: instance: Error initializing module: invalid import "env.ceilf"

Explicitly using the intrinsics is still covered by webassembly and
given the commenting out of these intrinsics mentions that they were not
used due to needing to support LLVM <3.3, I think we can safely enable
these now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants