[llvm] [X86] Avoid lowering `llrint` via x87 on non-x87 targets (PR #181339)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 13 01:39:23 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
Author: Abhishek Kaushik (abhishek-kaushik22)
<details>
<summary>Changes</summary>
Fixes https://github.com/llvm/llvm-project/issues/181265
---
Full diff: https://github.com/llvm/llvm-project/pull/181339.diff
2 Files Affected:
- (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+4)
- (modified) llvm/test/CodeGen/X86/llrint-conv.ll (+105)
``````````diff
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 88616e0f2a0c9..71b251066715a 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -22587,6 +22587,10 @@ SDValue X86TargetLowering::LowerLRINT_LLRINT(SDValue Op,
SDValue X86TargetLowering::LRINT_LLRINTHelper(SDNode *N,
SelectionDAG &DAG) const {
+ const X86Subtarget &Subtarget = DAG.getSubtarget<X86Subtarget>();
+ if (!Subtarget.hasX87())
+ return SDValue();
+
EVT DstVT = N->getValueType(0);
SDValue Src = N->getOperand(0);
EVT SrcVT = Src.getValueType();
diff --git a/llvm/test/CodeGen/X86/llrint-conv.ll b/llvm/test/CodeGen/X86/llrint-conv.ll
index 089bc187bab7d..01551030d938a 100644
--- a/llvm/test/CodeGen/X86/llrint-conv.ll
+++ b/llvm/test/CodeGen/X86/llrint-conv.ll
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=i686-unknown | FileCheck %s --check-prefixes=X86,X86-NOSSE
+; RUN: llc < %s -mtriple=i686-unknown -mattr=-x87 | FileCheck %s --check-prefixes=X86-NOX87
; RUN: llc < %s -mtriple=i686-unknown -mattr=sse2 | FileCheck %s --check-prefixes=X86,X86-SSE2
; RUN: llc < %s -mtriple=i686-unknown -mattr=avx | FileCheck %s --check-prefixes=X86,X86-AVX
; RUN: llc < %s -mtriple=i686-unknown -mattr=avx512f | FileCheck %s --check-prefixes=X86,X86-AVX
@@ -19,6 +20,17 @@ define i64 @test_llrint_i64_f16(half %x) nounwind {
; X86-NOSSE-NEXT: popl %ecx
; X86-NOSSE-NEXT: retl
;
+; X86-NOX87-LABEL: test_llrint_i64_f16:
+; X86-NOX87: # %bb.0: # %entry
+; X86-NOX87-NEXT: movzwl {{[0-9]+}}(%esp), %eax
+; X86-NOX87-NEXT: pushl %eax
+; X86-NOX87-NEXT: calll __extendhfsf2
+; X86-NOX87-NEXT: addl $4, %esp
+; X86-NOX87-NEXT: pushl %eax
+; X86-NOX87-NEXT: calll llrintf
+; X86-NOX87-NEXT: addl $4, %esp
+; X86-NOX87-NEXT: retl
+;
; X86-SSE2-LABEL: test_llrint_i64_f16:
; X86-SSE2: # %bb.0: # %entry
; X86-SSE2-NEXT: pushl %eax
@@ -61,6 +73,13 @@ define i64 @test_llrint_i64_f32(float %x) nounwind {
; X86-NOSSE-NEXT: popl %ebp
; X86-NOSSE-NEXT: retl
;
+; X86-NOX87-LABEL: test_llrint_i64_f32:
+; X86-NOX87: # %bb.0: # %entry
+; X86-NOX87-NEXT: pushl {{[0-9]+}}(%esp)
+; X86-NOX87-NEXT: calll llrintf
+; X86-NOX87-NEXT: addl $4, %esp
+; X86-NOX87-NEXT: retl
+;
; X86-SSE2-LABEL: test_llrint_i64_f32:
; X86-SSE2: # %bb.0: # %entry
; X86-SSE2-NEXT: pushl %ebp
@@ -122,6 +141,14 @@ define i64 @test_llrint_i64_f64(double %x) nounwind {
; X86-NOSSE-NEXT: popl %ebp
; X86-NOSSE-NEXT: retl
;
+; X86-NOX87-LABEL: test_llrint_i64_f64:
+; X86-NOX87: # %bb.0: # %entry
+; X86-NOX87-NEXT: pushl {{[0-9]+}}(%esp)
+; X86-NOX87-NEXT: pushl {{[0-9]+}}(%esp)
+; X86-NOX87-NEXT: calll llrint
+; X86-NOX87-NEXT: addl $8, %esp
+; X86-NOX87-NEXT: retl
+;
; X86-SSE2-LABEL: test_llrint_i64_f64:
; X86-SSE2: # %bb.0: # %entry
; X86-SSE2-NEXT: pushl %ebp
@@ -183,6 +210,16 @@ define i64 @test_llrint_i64_f80(x86_fp80 %x) nounwind {
; X86-NEXT: popl %ebp
; X86-NEXT: retl
;
+; X86-NOX87-LABEL: test_llrint_i64_f80:
+; X86-NOX87: # %bb.0: # %entry
+; X86-NOX87-NEXT: movswl {{[0-9]+}}(%esp), %eax
+; X86-NOX87-NEXT: pushl %eax
+; X86-NOX87-NEXT: pushl {{[0-9]+}}(%esp)
+; X86-NOX87-NEXT: pushl {{[0-9]+}}(%esp)
+; X86-NOX87-NEXT: calll llrintl
+; X86-NOX87-NEXT: addl $12, %esp
+; X86-NOX87-NEXT: retl
+;
; X64-LABEL: test_llrint_i64_f80:
; X64: # %bb.0: # %entry
; X64-NEXT: fldt {{[0-9]+}}(%rsp)
@@ -212,6 +249,22 @@ define i64 @test_llrint_i64_f128(fp128 %x) nounwind {
; X86-NOSSE-NEXT: popl %ebp
; X86-NOSSE-NEXT: retl
;
+; X86-NOX87-LABEL: test_llrint_i64_f128:
+; X86-NOX87: # %bb.0: # %entry
+; X86-NOX87-NEXT: pushl %ebp
+; X86-NOX87-NEXT: movl %esp, %ebp
+; X86-NOX87-NEXT: andl $-16, %esp
+; X86-NOX87-NEXT: subl $16, %esp
+; X86-NOX87-NEXT: pushl 20(%ebp)
+; X86-NOX87-NEXT: pushl 16(%ebp)
+; X86-NOX87-NEXT: pushl 12(%ebp)
+; X86-NOX87-NEXT: pushl 8(%ebp)
+; X86-NOX87-NEXT: calll llrintl
+; X86-NOX87-NEXT: addl $16, %esp
+; X86-NOX87-NEXT: movl %ebp, %esp
+; X86-NOX87-NEXT: popl %ebp
+; X86-NOX87-NEXT: retl
+;
; X86-SSE2-LABEL: test_llrint_i64_f128:
; X86-SSE2: # %bb.0: # %entry
; X86-SSE2-NEXT: pushl %ebp
@@ -262,6 +315,17 @@ define i64 @test_llrint_i64_f16_strict(half %x) nounwind strictfp {
; X86-NOSSE-NEXT: popl %ecx
; X86-NOSSE-NEXT: retl
;
+; X86-NOX87-LABEL: test_llrint_i64_f16_strict:
+; X86-NOX87: # %bb.0: # %entry
+; X86-NOX87-NEXT: movzwl {{[0-9]+}}(%esp), %eax
+; X86-NOX87-NEXT: pushl %eax
+; X86-NOX87-NEXT: calll __extendhfsf2
+; X86-NOX87-NEXT: addl $4, %esp
+; X86-NOX87-NEXT: pushl %eax
+; X86-NOX87-NEXT: calll llrintf
+; X86-NOX87-NEXT: addl $4, %esp
+; X86-NOX87-NEXT: retl
+;
; X86-SSE2-LABEL: test_llrint_i64_f16_strict:
; X86-SSE2: # %bb.0: # %entry
; X86-SSE2-NEXT: pushl %eax
@@ -299,6 +363,13 @@ define i64 @test_llrint_i64_f32_strict(float %x) nounwind strictfp {
; X86-NOSSE-NEXT: popl %ecx
; X86-NOSSE-NEXT: retl
;
+; X86-NOX87-LABEL: test_llrint_i64_f32_strict:
+; X86-NOX87: # %bb.0: # %entry
+; X86-NOX87-NEXT: pushl {{[0-9]+}}(%esp)
+; X86-NOX87-NEXT: calll llrintf
+; X86-NOX87-NEXT: addl $4, %esp
+; X86-NOX87-NEXT: retl
+;
; X86-SSE2-LABEL: test_llrint_i64_f32_strict:
; X86-SSE2: # %bb.0: # %entry
; X86-SSE2-NEXT: pushl %eax
@@ -339,6 +410,14 @@ define i64 @test_llrint_i64_f64_strict(double %x) nounwind strictfp {
; X86-NOSSE-NEXT: addl $8, %esp
; X86-NOSSE-NEXT: retl
;
+; X86-NOX87-LABEL: test_llrint_i64_f64_strict:
+; X86-NOX87: # %bb.0: # %entry
+; X86-NOX87-NEXT: pushl {{[0-9]+}}(%esp)
+; X86-NOX87-NEXT: pushl {{[0-9]+}}(%esp)
+; X86-NOX87-NEXT: calll llrint
+; X86-NOX87-NEXT: addl $8, %esp
+; X86-NOX87-NEXT: retl
+;
; X86-SSE2-LABEL: test_llrint_i64_f64_strict:
; X86-SSE2: # %bb.0: # %entry
; X86-SSE2-NEXT: subl $8, %esp
@@ -379,6 +458,16 @@ define i64 @test_llrint_i64_f80_strict(x86_fp80 %x) nounwind strictfp {
; X86-NEXT: addl $12, %esp
; X86-NEXT: retl
;
+; X86-NOX87-LABEL: test_llrint_i64_f80_strict:
+; X86-NOX87: # %bb.0: # %entry
+; X86-NOX87-NEXT: movswl {{[0-9]+}}(%esp), %eax
+; X86-NOX87-NEXT: pushl %eax
+; X86-NOX87-NEXT: pushl {{[0-9]+}}(%esp)
+; X86-NOX87-NEXT: pushl {{[0-9]+}}(%esp)
+; X86-NOX87-NEXT: calll llrintl
+; X86-NOX87-NEXT: addl $12, %esp
+; X86-NOX87-NEXT: retl
+;
; X64-LABEL: test_llrint_i64_f80_strict:
; X64: # %bb.0: # %entry
; X64-NEXT: subq $24, %rsp
@@ -411,6 +500,22 @@ define i64 @test_llrint_i64_f128_strict(fp128 %x) nounwind strictfp {
; X86-NOSSE-NEXT: popl %ebp
; X86-NOSSE-NEXT: retl
;
+; X86-NOX87-LABEL: test_llrint_i64_f128_strict:
+; X86-NOX87: # %bb.0: # %entry
+; X86-NOX87-NEXT: pushl %ebp
+; X86-NOX87-NEXT: movl %esp, %ebp
+; X86-NOX87-NEXT: andl $-16, %esp
+; X86-NOX87-NEXT: subl $16, %esp
+; X86-NOX87-NEXT: pushl 20(%ebp)
+; X86-NOX87-NEXT: pushl 16(%ebp)
+; X86-NOX87-NEXT: pushl 12(%ebp)
+; X86-NOX87-NEXT: pushl 8(%ebp)
+; X86-NOX87-NEXT: calll llrintl
+; X86-NOX87-NEXT: addl $16, %esp
+; X86-NOX87-NEXT: movl %ebp, %esp
+; X86-NOX87-NEXT: popl %ebp
+; X86-NOX87-NEXT: retl
+;
; X86-SSE2-LABEL: test_llrint_i64_f128_strict:
; X86-SSE2: # %bb.0: # %entry
; X86-SSE2-NEXT: pushl %ebp
``````````
</details>
https://github.com/llvm/llvm-project/pull/181339
More information about the llvm-commits
mailing list