[llvm] [X86][GlobalIsel] Support G_INTRINSIC_TRUNC/G_FCEIL/G_FFLOOR (PR #156633)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 7 07:19:53 PDT 2025
https://github.com/mahesh-attarde updated https://github.com/llvm/llvm-project/pull/156633
>From c9b41e4724c93b9f4a259754b1a0ca4e3fbda3a6 Mon Sep 17 00:00:00 2001
From: mattarde <mattarde at intel.com>
Date: Wed, 3 Sep 2025 02:44:19 -0700
Subject: [PATCH 1/5] add gisel output
---
.../lib/Target/X86/GISel/X86LegalizerInfo.cpp | 3 +-
llvm/test/CodeGen/X86/isel-ceil.ll | 30 +++++-----------
llvm/test/CodeGen/X86/isel-floor.ll | 30 +++++-----------
llvm/test/CodeGen/X86/isel-ftrunc.ll | 34 ++++++-------------
4 files changed, 31 insertions(+), 66 deletions(-)
diff --git a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
index 7fe58539cd4ec..c27e6075c779f 100644
--- a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
+++ b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
@@ -580,7 +580,8 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
.lower();
// fp intrinsics
- getActionDefinitionsBuilder(G_INTRINSIC_ROUNDEVEN)
+ getActionDefinitionsBuilder(
+ {G_INTRINSIC_ROUNDEVEN, G_INTRINSIC_TRUNC, G_FCEIL, G_FFLOOR})
.scalarize(0)
.minScalar(0, LLT::scalar(32))
.libcall();
diff --git a/llvm/test/CodeGen/X86/isel-ceil.ll b/llvm/test/CodeGen/X86/isel-ceil.ll
index c82cfebd4814d..eecaa79f2ef70 100644
--- a/llvm/test/CodeGen/X86/isel-ceil.ll
+++ b/llvm/test/CodeGen/X86/isel-ceil.ll
@@ -18,18 +18,12 @@ define float @ceil_f32(float %a) nounwind readnone {
; FASTISEL-X64-NEXT: popq %rax
; FASTISEL-X64-NEXT: retq
;
-; X86-LABEL: ceil_f32:
-; X86: # %bb.0:
-; X86-NEXT: subl $12, %esp
-; X86-NEXT: flds {{[0-9]+}}(%esp)
-; X86-NEXT: fstps (%esp)
-; X86-NEXT: calll ceilf
-; X86-NEXT: addl $12, %esp
-; X86-NEXT: retl
-;
; GISEL-X64-LABEL: ceil_f32:
; GISEL-X64: # %bb.0:
-; GISEL-X64-NEXT: jmp ceilf at PLT # TAILCALL
+; GISEL-X64-NEXT: pushq %rax
+; GISEL-X64-NEXT: callq ceilf
+; GISEL-X64-NEXT: popq %rax
+; GISEL-X64-NEXT: retq
%c = call float @llvm.ceil.f32(float %a)
ret float %c
}
@@ -46,18 +40,12 @@ define double @ceil_f64(double %a) nounwind readnone {
; FASTISEL-X64-NEXT: popq %rax
; FASTISEL-X64-NEXT: retq
;
-; X86-LABEL: ceil_f64:
-; X86: # %bb.0:
-; X86-NEXT: subl $12, %esp
-; X86-NEXT: fldl {{[0-9]+}}(%esp)
-; X86-NEXT: fstpl (%esp)
-; X86-NEXT: calll ceil
-; X86-NEXT: addl $12, %esp
-; X86-NEXT: retl
-;
; GISEL-X64-LABEL: ceil_f64:
; GISEL-X64: # %bb.0:
-; GISEL-X64-NEXT: jmp ceil at PLT # TAILCALL
+; GISEL-X64-NEXT: pushq %rax
+; GISEL-X64-NEXT: callq ceil
+; GISEL-X64-NEXT: popq %rax
+; GISEL-X64-NEXT: retq
%c = call double @llvm.ceil.f64(double %a)
ret double %c
}
@@ -86,7 +74,7 @@ define x86_fp80 @ceil_f80(x86_fp80 %a) nounwind readnone {
; GISEL-X64-NEXT: subq $24, %rsp
; GISEL-X64-NEXT: fldt {{[0-9]+}}(%rsp)
; GISEL-X64-NEXT: fstpt (%rsp)
-; GISEL-X64-NEXT: callq ceill at PLT
+; GISEL-X64-NEXT: callq ceill
; GISEL-X64-NEXT: addq $24, %rsp
; GISEL-X64-NEXT: retq
%c = call x86_fp80 @llvm.ceil.f80(x86_fp80 %a)
diff --git a/llvm/test/CodeGen/X86/isel-floor.ll b/llvm/test/CodeGen/X86/isel-floor.ll
index 675925b611263..4d98a27e7eb2f 100644
--- a/llvm/test/CodeGen/X86/isel-floor.ll
+++ b/llvm/test/CodeGen/X86/isel-floor.ll
@@ -18,18 +18,12 @@ define float @floor_f32(float %a) nounwind readnone {
; FASTISEL-X64-NEXT: popq %rax
; FASTISEL-X64-NEXT: retq
;
-; X86-LABEL: floor_f32:
-; X86: # %bb.0:
-; X86-NEXT: subl $12, %esp
-; X86-NEXT: flds {{[0-9]+}}(%esp)
-; X86-NEXT: fstps (%esp)
-; X86-NEXT: calll floorf
-; X86-NEXT: addl $12, %esp
-; X86-NEXT: retl
-;
; GISEL-X64-LABEL: floor_f32:
; GISEL-X64: # %bb.0:
-; GISEL-X64-NEXT: jmp floorf at PLT # TAILCALL
+; GISEL-X64-NEXT: pushq %rax
+; GISEL-X64-NEXT: callq floorf
+; GISEL-X64-NEXT: popq %rax
+; GISEL-X64-NEXT: retq
%c = call float @llvm.floor.f32(float %a)
ret float %c
}
@@ -46,18 +40,12 @@ define double @floor_f64(double %a) nounwind readnone {
; FASTISEL-X64-NEXT: popq %rax
; FASTISEL-X64-NEXT: retq
;
-; X86-LABEL: floor_f64:
-; X86: # %bb.0:
-; X86-NEXT: subl $12, %esp
-; X86-NEXT: fldl {{[0-9]+}}(%esp)
-; X86-NEXT: fstpl (%esp)
-; X86-NEXT: calll floor
-; X86-NEXT: addl $12, %esp
-; X86-NEXT: retl
-;
; GISEL-X64-LABEL: floor_f64:
; GISEL-X64: # %bb.0:
-; GISEL-X64-NEXT: jmp floor at PLT # TAILCALL
+; GISEL-X64-NEXT: pushq %rax
+; GISEL-X64-NEXT: callq floor
+; GISEL-X64-NEXT: popq %rax
+; GISEL-X64-NEXT: retq
%c = call double @llvm.floor.f64(double %a)
ret double %c
}
@@ -86,7 +74,7 @@ define x86_fp80 @floor_f80(x86_fp80 %a) nounwind readnone {
; GISEL-X64-NEXT: subq $24, %rsp
; GISEL-X64-NEXT: fldt {{[0-9]+}}(%rsp)
; GISEL-X64-NEXT: fstpt (%rsp)
-; GISEL-X64-NEXT: callq floorl at PLT
+; GISEL-X64-NEXT: callq floorl
; GISEL-X64-NEXT: addq $24, %rsp
; GISEL-X64-NEXT: retq
%c = call x86_fp80 @llvm.floor.f80(x86_fp80 %a)
diff --git a/llvm/test/CodeGen/X86/isel-ftrunc.ll b/llvm/test/CodeGen/X86/isel-ftrunc.ll
index 9bf06193961a3..cc9a7f4127c8d 100644
--- a/llvm/test/CodeGen/X86/isel-ftrunc.ll
+++ b/llvm/test/CodeGen/X86/isel-ftrunc.ll
@@ -3,8 +3,8 @@
; RUN: llc < %s -mtriple=x86_64-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X64,FASTISEL-X64
; RUN: llc < %s -mtriple=i686-linux-gnu | FileCheck %s --check-prefixes=X86
; RUN: llc < %s -mtriple=i686-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X86
-; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=GISEL-X64
-; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=X86
+; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X64
+; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X86
define float @trunc_f32(float %a) nounwind readnone {
; DAG-X64-LABEL: trunc_f32:
@@ -18,18 +18,12 @@ define float @trunc_f32(float %a) nounwind readnone {
; FASTISEL-X64-NEXT: popq %rax
; FASTISEL-X64-NEXT: retq
;
-; X86-LABEL: trunc_f32:
-; X86: # %bb.0:
-; X86-NEXT: subl $12, %esp
-; X86-NEXT: flds {{[0-9]+}}(%esp)
-; X86-NEXT: fstps (%esp)
-; X86-NEXT: calll truncf
-; X86-NEXT: addl $12, %esp
-; X86-NEXT: retl
-;
; GISEL-X64-LABEL: trunc_f32:
; GISEL-X64: # %bb.0:
-; GISEL-X64-NEXT: jmp truncf at PLT # TAILCALL
+; GISEL-X64-NEXT: pushq %rax
+; GISEL-X64-NEXT: callq truncf
+; GISEL-X64-NEXT: popq %rax
+; GISEL-X64-NEXT: retq
%c = call float @llvm.trunc.f32(float %a)
ret float %c
}
@@ -46,18 +40,12 @@ define double @trunc_f64(double %a) nounwind readnone {
; FASTISEL-X64-NEXT: popq %rax
; FASTISEL-X64-NEXT: retq
;
-; X86-LABEL: trunc_f64:
-; X86: # %bb.0:
-; X86-NEXT: subl $12, %esp
-; X86-NEXT: fldl {{[0-9]+}}(%esp)
-; X86-NEXT: fstpl (%esp)
-; X86-NEXT: calll trunc
-; X86-NEXT: addl $12, %esp
-; X86-NEXT: retl
-;
; GISEL-X64-LABEL: trunc_f64:
; GISEL-X64: # %bb.0:
-; GISEL-X64-NEXT: jmp trunc at PLT # TAILCALL
+; GISEL-X64-NEXT: pushq %rax
+; GISEL-X64-NEXT: callq trunc
+; GISEL-X64-NEXT: popq %rax
+; GISEL-X64-NEXT: retq
%c = call double @llvm.trunc.f64(double %a)
ret double %c
}
@@ -86,7 +74,7 @@ define x86_fp80 @trunc_f80(x86_fp80 %a) nounwind readnone {
; GISEL-X64-NEXT: subq $24, %rsp
; GISEL-X64-NEXT: fldt {{[0-9]+}}(%rsp)
; GISEL-X64-NEXT: fstpt (%rsp)
-; GISEL-X64-NEXT: callq truncl at PLT
+; GISEL-X64-NEXT: callq truncl
; GISEL-X64-NEXT: addq $24, %rsp
; GISEL-X64-NEXT: retq
%c = call x86_fp80 @llvm.trunc.f80(x86_fp80 %a)
>From 7fa4c15c2225fa2631a093a5c63d08639827b3b5 Mon Sep 17 00:00:00 2001
From: mattarde <mattarde at intel.com>
Date: Wed, 3 Sep 2025 03:03:10 -0700
Subject: [PATCH 2/5] update gisel2
---
llvm/test/CodeGen/X86/isel-ceil.ll | 4 ++--
llvm/test/CodeGen/X86/isel-floor.ll | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/test/CodeGen/X86/isel-ceil.ll b/llvm/test/CodeGen/X86/isel-ceil.ll
index eecaa79f2ef70..bb37f7e86a4c8 100644
--- a/llvm/test/CodeGen/X86/isel-ceil.ll
+++ b/llvm/test/CodeGen/X86/isel-ceil.ll
@@ -3,8 +3,8 @@
; RUN: llc < %s -mtriple=x86_64-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X64,FASTISEL-X64
; RUN: llc < %s -mtriple=i686-linux-gnu | FileCheck %s --check-prefixes=X86
; RUN: llc < %s -mtriple=i686-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X86
-; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=GISEL-X64
-; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=X86
+; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X64
+; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X86
define float @ceil_f32(float %a) nounwind readnone {
; DAG-X64-LABEL: ceil_f32:
diff --git a/llvm/test/CodeGen/X86/isel-floor.ll b/llvm/test/CodeGen/X86/isel-floor.ll
index 4d98a27e7eb2f..c20b1264eac16 100644
--- a/llvm/test/CodeGen/X86/isel-floor.ll
+++ b/llvm/test/CodeGen/X86/isel-floor.ll
@@ -3,8 +3,8 @@
; RUN: llc < %s -mtriple=x86_64-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X64,FASTISEL-X64
; RUN: llc < %s -mtriple=i686-linux-gnu | FileCheck %s --check-prefixes=X86
; RUN: llc < %s -mtriple=i686-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X86
-; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=GISEL-X64
-; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes=X86
+; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X64
+; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X86
define float @floor_f32(float %a) nounwind readnone {
; DAG-X64-LABEL: floor_f32:
>From 193fb0bea03ffdfddee543c348febcc925f74d49 Mon Sep 17 00:00:00 2001
From: mattarde <mattarde at intel.com>
Date: Wed, 3 Sep 2025 03:28:40 -0700
Subject: [PATCH 3/5] update test
---
llvm/test/CodeGen/X86/isel-ceil.ll | 65 +++++++++++++++++++++++++++--
llvm/test/CodeGen/X86/isel-floor.ll | 65 +++++++++++++++++++++++++++--
2 files changed, 124 insertions(+), 6 deletions(-)
diff --git a/llvm/test/CodeGen/X86/isel-ceil.ll b/llvm/test/CodeGen/X86/isel-ceil.ll
index bb37f7e86a4c8..831da72a0aa96 100644
--- a/llvm/test/CodeGen/X86/isel-ceil.ll
+++ b/llvm/test/CodeGen/X86/isel-ceil.ll
@@ -1,10 +1,10 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc < %s -mtriple=x86_64-linux-gnu | FileCheck %s --check-prefixes=X64,DAG-X64
; RUN: llc < %s -mtriple=x86_64-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X64,FASTISEL-X64
-; RUN: llc < %s -mtriple=i686-linux-gnu | FileCheck %s --check-prefixes=X86
-; RUN: llc < %s -mtriple=i686-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X86
+; RUN: llc < %s -mtriple=i686-linux-gnu | FileCheck %s --check-prefixes=X86,DAG-X86
+; RUN: llc < %s -mtriple=i686-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X86,FASTISEL-X86
; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X64
-; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X86
+; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X86,GISEL-X86
define float @ceil_f32(float %a) nounwind readnone {
; DAG-X64-LABEL: ceil_f32:
@@ -18,12 +18,39 @@ define float @ceil_f32(float %a) nounwind readnone {
; FASTISEL-X64-NEXT: popq %rax
; FASTISEL-X64-NEXT: retq
;
+; DAG-X86-LABEL: ceil_f32:
+; DAG-X86: # %bb.0:
+; DAG-X86-NEXT: subl $12, %esp
+; DAG-X86-NEXT: flds {{[0-9]+}}(%esp)
+; DAG-X86-NEXT: fstps (%esp)
+; DAG-X86-NEXT: calll ceilf
+; DAG-X86-NEXT: addl $12, %esp
+; DAG-X86-NEXT: retl
+;
+; FASTISEL-X86-LABEL: ceil_f32:
+; FASTISEL-X86: # %bb.0:
+; FASTISEL-X86-NEXT: subl $12, %esp
+; FASTISEL-X86-NEXT: flds {{[0-9]+}}(%esp)
+; FASTISEL-X86-NEXT: fstps (%esp)
+; FASTISEL-X86-NEXT: calll ceilf
+; FASTISEL-X86-NEXT: addl $12, %esp
+; FASTISEL-X86-NEXT: retl
+;
; GISEL-X64-LABEL: ceil_f32:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: pushq %rax
; GISEL-X64-NEXT: callq ceilf
; GISEL-X64-NEXT: popq %rax
; GISEL-X64-NEXT: retq
+;
+; GISEL-X86-LABEL: ceil_f32:
+; GISEL-X86: # %bb.0:
+; GISEL-X86-NEXT: subl $12, %esp
+; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; GISEL-X86-NEXT: movl %eax, (%esp)
+; GISEL-X86-NEXT: calll ceilf
+; GISEL-X86-NEXT: addl $12, %esp
+; GISEL-X86-NEXT: retl
%c = call float @llvm.ceil.f32(float %a)
ret float %c
}
@@ -40,12 +67,44 @@ define double @ceil_f64(double %a) nounwind readnone {
; FASTISEL-X64-NEXT: popq %rax
; FASTISEL-X64-NEXT: retq
;
+; DAG-X86-LABEL: ceil_f64:
+; DAG-X86: # %bb.0:
+; DAG-X86-NEXT: subl $12, %esp
+; DAG-X86-NEXT: fldl {{[0-9]+}}(%esp)
+; DAG-X86-NEXT: fstpl (%esp)
+; DAG-X86-NEXT: calll ceil
+; DAG-X86-NEXT: addl $12, %esp
+; DAG-X86-NEXT: retl
+;
+; FASTISEL-X86-LABEL: ceil_f64:
+; FASTISEL-X86: # %bb.0:
+; FASTISEL-X86-NEXT: subl $12, %esp
+; FASTISEL-X86-NEXT: fldl {{[0-9]+}}(%esp)
+; FASTISEL-X86-NEXT: fstpl (%esp)
+; FASTISEL-X86-NEXT: calll ceil
+; FASTISEL-X86-NEXT: addl $12, %esp
+; FASTISEL-X86-NEXT: retl
+;
; GISEL-X64-LABEL: ceil_f64:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: pushq %rax
; GISEL-X64-NEXT: callq ceil
; GISEL-X64-NEXT: popq %rax
; GISEL-X64-NEXT: retq
+;
+; GISEL-X86-LABEL: ceil_f64:
+; GISEL-X86: # %bb.0:
+; GISEL-X86-NEXT: subl $12, %esp
+; GISEL-X86-NEXT: leal {{[0-9]+}}(%esp), %eax
+; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; GISEL-X86-NEXT: movl 4(%eax), %eax
+; GISEL-X86-NEXT: xorl %edx, %edx
+; GISEL-X86-NEXT: addl %esp, %edx
+; GISEL-X86-NEXT: movl %ecx, (%esp)
+; GISEL-X86-NEXT: movl %eax, 4(%edx)
+; GISEL-X86-NEXT: calll ceil
+; GISEL-X86-NEXT: addl $12, %esp
+; GISEL-X86-NEXT: retl
%c = call double @llvm.ceil.f64(double %a)
ret double %c
}
diff --git a/llvm/test/CodeGen/X86/isel-floor.ll b/llvm/test/CodeGen/X86/isel-floor.ll
index c20b1264eac16..312f1b4483faa 100644
--- a/llvm/test/CodeGen/X86/isel-floor.ll
+++ b/llvm/test/CodeGen/X86/isel-floor.ll
@@ -1,10 +1,10 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc < %s -mtriple=x86_64-linux-gnu | FileCheck %s --check-prefixes=X64,DAG-X64
; RUN: llc < %s -mtriple=x86_64-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X64,FASTISEL-X64
-; RUN: llc < %s -mtriple=i686-linux-gnu | FileCheck %s --check-prefixes=X86
-; RUN: llc < %s -mtriple=i686-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X86
+; RUN: llc < %s -mtriple=i686-linux-gnu | FileCheck %s --check-prefixes=X86,DAG-X86
+; RUN: llc < %s -mtriple=i686-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X86,FASTISEL-X86
; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X64
-; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X86
+; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X86,GISEL-X86
define float @floor_f32(float %a) nounwind readnone {
; DAG-X64-LABEL: floor_f32:
@@ -18,12 +18,39 @@ define float @floor_f32(float %a) nounwind readnone {
; FASTISEL-X64-NEXT: popq %rax
; FASTISEL-X64-NEXT: retq
;
+; DAG-X86-LABEL: floor_f32:
+; DAG-X86: # %bb.0:
+; DAG-X86-NEXT: subl $12, %esp
+; DAG-X86-NEXT: flds {{[0-9]+}}(%esp)
+; DAG-X86-NEXT: fstps (%esp)
+; DAG-X86-NEXT: calll floorf
+; DAG-X86-NEXT: addl $12, %esp
+; DAG-X86-NEXT: retl
+;
+; FASTISEL-X86-LABEL: floor_f32:
+; FASTISEL-X86: # %bb.0:
+; FASTISEL-X86-NEXT: subl $12, %esp
+; FASTISEL-X86-NEXT: flds {{[0-9]+}}(%esp)
+; FASTISEL-X86-NEXT: fstps (%esp)
+; FASTISEL-X86-NEXT: calll floorf
+; FASTISEL-X86-NEXT: addl $12, %esp
+; FASTISEL-X86-NEXT: retl
+;
; GISEL-X64-LABEL: floor_f32:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: pushq %rax
; GISEL-X64-NEXT: callq floorf
; GISEL-X64-NEXT: popq %rax
; GISEL-X64-NEXT: retq
+;
+; GISEL-X86-LABEL: floor_f32:
+; GISEL-X86: # %bb.0:
+; GISEL-X86-NEXT: subl $12, %esp
+; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; GISEL-X86-NEXT: movl %eax, (%esp)
+; GISEL-X86-NEXT: calll floorf
+; GISEL-X86-NEXT: addl $12, %esp
+; GISEL-X86-NEXT: retl
%c = call float @llvm.floor.f32(float %a)
ret float %c
}
@@ -40,12 +67,44 @@ define double @floor_f64(double %a) nounwind readnone {
; FASTISEL-X64-NEXT: popq %rax
; FASTISEL-X64-NEXT: retq
;
+; DAG-X86-LABEL: floor_f64:
+; DAG-X86: # %bb.0:
+; DAG-X86-NEXT: subl $12, %esp
+; DAG-X86-NEXT: fldl {{[0-9]+}}(%esp)
+; DAG-X86-NEXT: fstpl (%esp)
+; DAG-X86-NEXT: calll floor
+; DAG-X86-NEXT: addl $12, %esp
+; DAG-X86-NEXT: retl
+;
+; FASTISEL-X86-LABEL: floor_f64:
+; FASTISEL-X86: # %bb.0:
+; FASTISEL-X86-NEXT: subl $12, %esp
+; FASTISEL-X86-NEXT: fldl {{[0-9]+}}(%esp)
+; FASTISEL-X86-NEXT: fstpl (%esp)
+; FASTISEL-X86-NEXT: calll floor
+; FASTISEL-X86-NEXT: addl $12, %esp
+; FASTISEL-X86-NEXT: retl
+;
; GISEL-X64-LABEL: floor_f64:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: pushq %rax
; GISEL-X64-NEXT: callq floor
; GISEL-X64-NEXT: popq %rax
; GISEL-X64-NEXT: retq
+;
+; GISEL-X86-LABEL: floor_f64:
+; GISEL-X86: # %bb.0:
+; GISEL-X86-NEXT: subl $12, %esp
+; GISEL-X86-NEXT: leal {{[0-9]+}}(%esp), %eax
+; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; GISEL-X86-NEXT: movl 4(%eax), %eax
+; GISEL-X86-NEXT: xorl %edx, %edx
+; GISEL-X86-NEXT: addl %esp, %edx
+; GISEL-X86-NEXT: movl %ecx, (%esp)
+; GISEL-X86-NEXT: movl %eax, 4(%edx)
+; GISEL-X86-NEXT: calll floor
+; GISEL-X86-NEXT: addl $12, %esp
+; GISEL-X86-NEXT: retl
%c = call double @llvm.floor.f64(double %a)
ret double %c
}
>From 3cce02f3795351220eae924e503adddbaa5ca043 Mon Sep 17 00:00:00 2001
From: mattarde <mattarde at intel.com>
Date: Wed, 3 Sep 2025 08:16:42 -0700
Subject: [PATCH 4/5] fix tesT
---
llvm/test/CodeGen/X86/isel-floor.ll | 1 -
llvm/test/CodeGen/X86/isel-ftrunc.ll | 66 ++++++++++++++++++++++++++--
2 files changed, 62 insertions(+), 5 deletions(-)
diff --git a/llvm/test/CodeGen/X86/isel-floor.ll b/llvm/test/CodeGen/X86/isel-floor.ll
index 312f1b4483faa..acd47cb7d5b86 100644
--- a/llvm/test/CodeGen/X86/isel-floor.ll
+++ b/llvm/test/CodeGen/X86/isel-floor.ll
@@ -139,4 +139,3 @@ define x86_fp80 @floor_f80(x86_fp80 %a) nounwind readnone {
%c = call x86_fp80 @llvm.floor.f80(x86_fp80 %a)
ret x86_fp80 %c
}
-
diff --git a/llvm/test/CodeGen/X86/isel-ftrunc.ll b/llvm/test/CodeGen/X86/isel-ftrunc.ll
index cc9a7f4127c8d..797aef02a4939 100644
--- a/llvm/test/CodeGen/X86/isel-ftrunc.ll
+++ b/llvm/test/CodeGen/X86/isel-ftrunc.ll
@@ -1,10 +1,10 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc < %s -mtriple=x86_64-linux-gnu | FileCheck %s --check-prefixes=X64,DAG-X64
; RUN: llc < %s -mtriple=x86_64-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X64,FASTISEL-X64
-; RUN: llc < %s -mtriple=i686-linux-gnu | FileCheck %s --check-prefixes=X86
-; RUN: llc < %s -mtriple=i686-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X86
+; RUN: llc < %s -mtriple=i686-linux-gnu | FileCheck %s --check-prefixes=X86,DAG-X86
+; RUN: llc < %s -mtriple=i686-linux-gnu -fast-isel | FileCheck %s --check-prefixes=X86,FASTISEL-X86
; RUN: llc < %s -mtriple=x86_64-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=GISEL-X64
-; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X86
+; RUN: llc < %s -mtriple=i686-linux-gnu -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X86,GISEL-X86
define float @trunc_f32(float %a) nounwind readnone {
; DAG-X64-LABEL: trunc_f32:
@@ -18,12 +18,39 @@ define float @trunc_f32(float %a) nounwind readnone {
; FASTISEL-X64-NEXT: popq %rax
; FASTISEL-X64-NEXT: retq
;
+; DAG-X86-LABEL: trunc_f32:
+; DAG-X86: # %bb.0:
+; DAG-X86-NEXT: subl $12, %esp
+; DAG-X86-NEXT: flds {{[0-9]+}}(%esp)
+; DAG-X86-NEXT: fstps (%esp)
+; DAG-X86-NEXT: calll truncf
+; DAG-X86-NEXT: addl $12, %esp
+; DAG-X86-NEXT: retl
+;
+; FASTISEL-X86-LABEL: trunc_f32:
+; FASTISEL-X86: # %bb.0:
+; FASTISEL-X86-NEXT: subl $12, %esp
+; FASTISEL-X86-NEXT: flds {{[0-9]+}}(%esp)
+; FASTISEL-X86-NEXT: fstps (%esp)
+; FASTISEL-X86-NEXT: calll truncf
+; FASTISEL-X86-NEXT: addl $12, %esp
+; FASTISEL-X86-NEXT: retl
+;
; GISEL-X64-LABEL: trunc_f32:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: pushq %rax
; GISEL-X64-NEXT: callq truncf
; GISEL-X64-NEXT: popq %rax
; GISEL-X64-NEXT: retq
+;
+; GISEL-X86-LABEL: trunc_f32:
+; GISEL-X86: # %bb.0:
+; GISEL-X86-NEXT: subl $12, %esp
+; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; GISEL-X86-NEXT: movl %eax, (%esp)
+; GISEL-X86-NEXT: calll truncf
+; GISEL-X86-NEXT: addl $12, %esp
+; GISEL-X86-NEXT: retl
%c = call float @llvm.trunc.f32(float %a)
ret float %c
}
@@ -40,12 +67,44 @@ define double @trunc_f64(double %a) nounwind readnone {
; FASTISEL-X64-NEXT: popq %rax
; FASTISEL-X64-NEXT: retq
;
+; DAG-X86-LABEL: trunc_f64:
+; DAG-X86: # %bb.0:
+; DAG-X86-NEXT: subl $12, %esp
+; DAG-X86-NEXT: fldl {{[0-9]+}}(%esp)
+; DAG-X86-NEXT: fstpl (%esp)
+; DAG-X86-NEXT: calll trunc
+; DAG-X86-NEXT: addl $12, %esp
+; DAG-X86-NEXT: retl
+;
+; FASTISEL-X86-LABEL: trunc_f64:
+; FASTISEL-X86: # %bb.0:
+; FASTISEL-X86-NEXT: subl $12, %esp
+; FASTISEL-X86-NEXT: fldl {{[0-9]+}}(%esp)
+; FASTISEL-X86-NEXT: fstpl (%esp)
+; FASTISEL-X86-NEXT: calll trunc
+; FASTISEL-X86-NEXT: addl $12, %esp
+; FASTISEL-X86-NEXT: retl
+;
; GISEL-X64-LABEL: trunc_f64:
; GISEL-X64: # %bb.0:
; GISEL-X64-NEXT: pushq %rax
; GISEL-X64-NEXT: callq trunc
; GISEL-X64-NEXT: popq %rax
; GISEL-X64-NEXT: retq
+;
+; GISEL-X86-LABEL: trunc_f64:
+; GISEL-X86: # %bb.0:
+; GISEL-X86-NEXT: subl $12, %esp
+; GISEL-X86-NEXT: leal {{[0-9]+}}(%esp), %eax
+; GISEL-X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; GISEL-X86-NEXT: movl 4(%eax), %eax
+; GISEL-X86-NEXT: xorl %edx, %edx
+; GISEL-X86-NEXT: addl %esp, %edx
+; GISEL-X86-NEXT: movl %ecx, (%esp)
+; GISEL-X86-NEXT: movl %eax, 4(%edx)
+; GISEL-X86-NEXT: calll trunc
+; GISEL-X86-NEXT: addl $12, %esp
+; GISEL-X86-NEXT: retl
%c = call double @llvm.trunc.f64(double %a)
ret double %c
}
@@ -80,4 +139,3 @@ define x86_fp80 @trunc_f80(x86_fp80 %a) nounwind readnone {
%c = call x86_fp80 @llvm.trunc.f80(x86_fp80 %a)
ret x86_fp80 %c
}
-
>From 21d6ab9986b31aaee44ba6ea1a6b75ddaa07ac7e Mon Sep 17 00:00:00 2001
From: mattarde <mattarde at intel.com>
Date: Sun, 7 Sep 2025 07:19:30 -0700
Subject: [PATCH 5/5] address review comments
---
llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
index c27e6075c779f..2c752457d165e 100644
--- a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
+++ b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
@@ -98,10 +98,11 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
.widenScalarToNextPow2(0, /*Min=*/8)
.clampScalar(0, s8, sMaxScalar);
- getActionDefinitionsBuilder(
- {G_LROUND, G_LLROUND, G_FCOS, G_FCOSH, G_FACOS, G_FSIN, G_FSINH,
- G_FASIN, G_FTAN, G_FTANH, G_FATAN, G_FATAN2, G_FPOW, G_FEXP,
- G_FEXP2, G_FEXP10, G_FLOG, G_FLOG2, G_FLOG10, G_FPOWI, G_FSINCOS})
+ getActionDefinitionsBuilder({G_LROUND, G_LLROUND, G_FCOS, G_FCOSH, G_FACOS,
+ G_FSIN, G_FSINH, G_FASIN, G_FTAN, G_FTANH,
+ G_FATAN, G_FATAN2, G_FPOW, G_FEXP, G_FEXP2,
+ G_FEXP10, G_FLOG, G_FLOG2, G_FLOG10, G_FPOWI,
+ G_FSINCOS, G_FCEIL, G_FFLOOR})
.libcall();
getActionDefinitionsBuilder(G_FSQRT)
@@ -580,8 +581,7 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
.lower();
// fp intrinsics
- getActionDefinitionsBuilder(
- {G_INTRINSIC_ROUNDEVEN, G_INTRINSIC_TRUNC, G_FCEIL, G_FFLOOR})
+ getActionDefinitionsBuilder({G_INTRINSIC_ROUNDEVEN, G_INTRINSIC_TRUNC})
.scalarize(0)
.minScalar(0, LLT::scalar(32))
.libcall();
More information about the llvm-commits
mailing list