Skip to content

[X86][NFC] - Add sitofp and fptosi tests for x87 mode #136860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 25, 2025

Conversation

pawan-nirpal-031
Copy link
Contributor

  • Add global-isel runs as precommit testcases for sitofp and fptosi in x87 mode.

@llvmbot
Copy link
Member

llvmbot commented Apr 23, 2025

@llvm/pr-subscribers-backend-x86

Author: Pawan Nirpal (pawan-nirpal-031)

Changes
  • Add global-isel runs as precommit testcases for sitofp and fptosi in x87 mode.

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

2 Files Affected:

  • (added) llvm/test/CodeGen/X86/isel-fp-to-sint-x87.ll (+514)
  • (added) llvm/test/CodeGen/X86/isel-int-to-fp-x87.ll (+367)
diff --git a/llvm/test/CodeGen/X86/isel-fp-to-sint-x87.ll b/llvm/test/CodeGen/X86/isel-fp-to-sint-x87.ll
new file mode 100644
index 0000000000000..7779722684206
--- /dev/null
+++ b/llvm/test/CodeGen/X86/isel-fp-to-sint-x87.ll
@@ -0,0 +1,514 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; NOTE: Fast Isel is not added because it does not support x87 stores.
+
+; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse,-sse2 -global-isel=0 | FileCheck %s --check-prefixes X64,SDAG-X64
+; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse,-sse2 -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes X64,GISEL-X64
+; RUN: llc < %s -mtriple=i686-linux-gnu -mattr=+x87,-sse,-sse2 -global-isel=0 | FileCheck %s --check-prefixes I686,SDAG-I686
+; RUN: llc < %s -mtriple=i686-linux-gnu -mattr=+x87,-sse,-sse2 -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes I686,GISEL-I686
+
+define i8 @test_float_to_int8(float %input) nounwind {
+; SDAG-X64-LABEL: test_float_to_int8:
+; SDAG-X64:       # %bb.0: # %entry
+; SDAG-X64-NEXT:    flds {{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; SDAG-X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; SDAG-X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    fistps -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    movzbl -{{[0-9]+}}(%rsp), %eax
+; SDAG-X64-NEXT:    retq
+;
+; GISEL-X64-LABEL: test_float_to_int8:
+; GISEL-X64:       # %bb.0: # %entry
+; GISEL-X64-NEXT:    flds {{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; GISEL-X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; GISEL-X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    fistps -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; GISEL-X64-NEXT:    # kill: def $al killed $al killed $ax
+; GISEL-X64-NEXT:    retq
+;
+; SDAG-I686-LABEL: test_float_to_int8:
+; SDAG-I686:       # %bb.0: # %entry
+; SDAG-I686-NEXT:    subl $8, %esp
+; SDAG-I686-NEXT:    flds {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fnstcw {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; SDAG-I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; SDAG-I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fistps {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    movzbl {{[0-9]+}}(%esp), %eax
+; SDAG-I686-NEXT:    addl $8, %esp
+; SDAG-I686-NEXT:    retl
+;
+; GISEL-I686-LABEL: test_float_to_int8:
+; GISEL-I686:       # %bb.0: # %entry
+; GISEL-I686-NEXT:    subl $8, %esp
+; GISEL-I686-NEXT:    flds {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    fnstcw {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; GISEL-I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; GISEL-I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    fistps {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; GISEL-I686-NEXT:    # kill: def $al killed $al killed $ax
+; GISEL-I686-NEXT:    addl $8, %esp
+; GISEL-I686-NEXT:    retl
+entry:
+    %conv = fptosi float %input to i8
+    ret i8 %conv
+}
+
+define i8 @test_longdouble_to_int8(x86_fp80 %input) nounwind {
+; SDAG-X64-LABEL: test_longdouble_to_int8:
+; SDAG-X64:       # %bb.0: # %entry
+; SDAG-X64-NEXT:    fldt {{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; SDAG-X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; SDAG-X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    fistps -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    movzbl -{{[0-9]+}}(%rsp), %eax
+; SDAG-X64-NEXT:    retq
+;
+; GISEL-X64-LABEL: test_longdouble_to_int8:
+; GISEL-X64:       # %bb.0: # %entry
+; GISEL-X64-NEXT:    fldt {{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; GISEL-X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; GISEL-X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    fistps -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; GISEL-X64-NEXT:    # kill: def $al killed $al killed $ax
+; GISEL-X64-NEXT:    retq
+;
+; SDAG-I686-LABEL: test_longdouble_to_int8:
+; SDAG-I686:       # %bb.0: # %entry
+; SDAG-I686-NEXT:    subl $8, %esp
+; SDAG-I686-NEXT:    fldt {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fnstcw {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; SDAG-I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; SDAG-I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fistps {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    movzbl {{[0-9]+}}(%esp), %eax
+; SDAG-I686-NEXT:    addl $8, %esp
+; SDAG-I686-NEXT:    retl
+;
+; GISEL-I686-LABEL: test_longdouble_to_int8:
+; GISEL-I686:       # %bb.0: # %entry
+; GISEL-I686-NEXT:    subl $8, %esp
+; GISEL-I686-NEXT:    fldt {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    fnstcw {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; GISEL-I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; GISEL-I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    fistps {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; GISEL-I686-NEXT:    # kill: def $al killed $al killed $ax
+; GISEL-I686-NEXT:    addl $8, %esp
+; GISEL-I686-NEXT:    retl
+entry:
+    %conv = fptosi x86_fp80 %input to i8
+    ret i8 %conv
+}
+
+define i16 @test_float_to_int16(float %input) nounwind {
+; X64-LABEL: test_float_to_int16:
+; X64:       # %bb.0: # %entry
+; X64-NEXT:    flds {{[0-9]+}}(%rsp)
+; X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fistps -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    retq
+;
+; I686-LABEL: test_float_to_int16:
+; I686:       # %bb.0: # %entry
+; I686-NEXT:    subl $8, %esp
+; I686-NEXT:    flds {{[0-9]+}}(%esp)
+; I686-NEXT:    fnstcw {{[0-9]+}}(%esp)
+; I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; I686-NEXT:    fistps {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; I686-NEXT:    addl $8, %esp
+; I686-NEXT:    retl
+entry:
+    %conv = fptosi float %input to i16
+    ret i16 %conv
+}
+
+define i16 @test_longdouble_to_int16(x86_fp80 %input) nounwind {
+; X64-LABEL: test_longdouble_to_int16:
+; X64:       # %bb.0: # %entry
+; X64-NEXT:    fldt {{[0-9]+}}(%rsp)
+; X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fistps -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    retq
+;
+; I686-LABEL: test_longdouble_to_int16:
+; I686:       # %bb.0: # %entry
+; I686-NEXT:    subl $8, %esp
+; I686-NEXT:    fldt {{[0-9]+}}(%esp)
+; I686-NEXT:    fnstcw {{[0-9]+}}(%esp)
+; I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; I686-NEXT:    fistps {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; I686-NEXT:    addl $8, %esp
+; I686-NEXT:    retl
+entry:
+    %conv = fptosi x86_fp80 %input to i16
+    ret i16 %conv
+}
+
+define i32 @test_float_to_int32(float %input) nounwind {
+; X64-LABEL: test_float_to_int32:
+; X64:       # %bb.0: # %entry
+; X64-NEXT:    flds {{[0-9]+}}(%rsp)
+; X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fistpl -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    retq
+;
+; I686-LABEL: test_float_to_int32:
+; I686:       # %bb.0: # %entry
+; I686-NEXT:    subl $8, %esp
+; I686-NEXT:    flds {{[0-9]+}}(%esp)
+; I686-NEXT:    fnstcw (%esp)
+; I686-NEXT:    movzwl (%esp), %eax
+; I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; I686-NEXT:    fistpl {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw (%esp)
+; I686-NEXT:    movl {{[0-9]+}}(%esp), %eax
+; I686-NEXT:    addl $8, %esp
+; I686-NEXT:    retl
+entry:
+    %conv = fptosi float %input to i32
+    ret i32 %conv
+}
+
+define i32 @test_longdouble_to_int32(x86_fp80 %input) nounwind {
+; X64-LABEL: test_longdouble_to_int32:
+; X64:       # %bb.0: # %entry
+; X64-NEXT:    fldt {{[0-9]+}}(%rsp)
+; X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fistpl -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    retq
+;
+; I686-LABEL: test_longdouble_to_int32:
+; I686:       # %bb.0: # %entry
+; I686-NEXT:    subl $8, %esp
+; I686-NEXT:    fldt {{[0-9]+}}(%esp)
+; I686-NEXT:    fnstcw (%esp)
+; I686-NEXT:    movzwl (%esp), %eax
+; I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; I686-NEXT:    fistpl {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw (%esp)
+; I686-NEXT:    movl {{[0-9]+}}(%esp), %eax
+; I686-NEXT:    addl $8, %esp
+; I686-NEXT:    retl
+entry:
+    %conv = fptosi x86_fp80 %input to i32
+    ret i32 %conv
+}
+
+define i64 @test_float_to_int64(float %input) nounwind {
+; X64-LABEL: test_float_to_int64:
+; X64:       # %bb.0: # %entry
+; X64-NEXT:    flds {{[0-9]+}}(%rsp)
+; X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fistpll -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movq -{{[0-9]+}}(%rsp), %rax
+; X64-NEXT:    retq
+;
+; SDAG-I686-LABEL: test_float_to_int64:
+; SDAG-I686:       # %bb.0: # %entry
+; SDAG-I686-NEXT:    subl $20, %esp
+; SDAG-I686-NEXT:    flds {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fnstcw {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; SDAG-I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; SDAG-I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fistpll {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    movl {{[0-9]+}}(%esp), %eax
+; SDAG-I686-NEXT:    movl {{[0-9]+}}(%esp), %edx
+; SDAG-I686-NEXT:    addl $20, %esp
+; SDAG-I686-NEXT:    retl
+;
+; GISEL-I686-LABEL: test_float_to_int64:
+; GISEL-I686:       # %bb.0: # %entry
+; GISEL-I686-NEXT:    subl $20, %esp
+; GISEL-I686-NEXT:    flds {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    leal {{[0-9]+}}(%esp), %ecx
+; GISEL-I686-NEXT:    fnstcw {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; GISEL-I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; GISEL-I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    fistpll {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    movl {{[0-9]+}}(%esp), %eax
+; GISEL-I686-NEXT:    movl 4(%ecx), %edx
+; GISEL-I686-NEXT:    addl $20, %esp
+; GISEL-I686-NEXT:    retl
+entry:
+    %conv = fptosi float %input to i64
+    ret i64 %conv
+}
+
+define i64 @test_longdouble_to_int64(x86_fp80 %input) nounwind {
+; X64-LABEL: test_longdouble_to_int64:
+; X64:       # %bb.0: # %entry
+; X64-NEXT:    fldt {{[0-9]+}}(%rsp)
+; X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fistpll -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movq -{{[0-9]+}}(%rsp), %rax
+; X64-NEXT:    retq
+;
+; SDAG-I686-LABEL: test_longdouble_to_int64:
+; SDAG-I686:       # %bb.0: # %entry
+; SDAG-I686-NEXT:    subl $20, %esp
+; SDAG-I686-NEXT:    fldt {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fnstcw {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; SDAG-I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; SDAG-I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fistpll {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; SDAG-I686-NEXT:    movl {{[0-9]+}}(%esp), %eax
+; SDAG-I686-NEXT:    movl {{[0-9]+}}(%esp), %edx
+; SDAG-I686-NEXT:    addl $20, %esp
+; SDAG-I686-NEXT:    retl
+;
+; GISEL-I686-LABEL: test_longdouble_to_int64:
+; GISEL-I686:       # %bb.0: # %entry
+; GISEL-I686-NEXT:    subl $20, %esp
+; GISEL-I686-NEXT:    fldt {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    leal {{[0-9]+}}(%esp), %ecx
+; GISEL-I686-NEXT:    fnstcw {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; GISEL-I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; GISEL-I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    fistpll {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; GISEL-I686-NEXT:    movl {{[0-9]+}}(%esp), %eax
+; GISEL-I686-NEXT:    movl 4(%ecx), %edx
+; GISEL-I686-NEXT:    addl $20, %esp
+; GISEL-I686-NEXT:    retl
+entry:
+    %conv = fptosi x86_fp80 %input to i64
+    ret i64 %conv
+}
+
+define i8 @test_double_to_int8(double %input) nounwind {
+; SDAG-X64-LABEL: test_double_to_int8:
+; SDAG-X64:       # %bb.0: # %entry
+; SDAG-X64-NEXT:    fldl {{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; SDAG-X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; SDAG-X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    fistps -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; SDAG-X64-NEXT:    movzbl -{{[0-9]+}}(%rsp), %eax
+; SDAG-X64-NEXT:    retq
+;
+; GISEL-X64-LABEL: test_double_to_int8:
+; GISEL-X64:       # %bb.0: # %entry
+; GISEL-X64-NEXT:    fldl {{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; GISEL-X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; GISEL-X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    fistps -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; GISEL-X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; GISEL-X64-NEXT:    # kill: def $al killed $al killed $ax
+; GISEL-X64-NEXT:    retq
+;
+; I686-LABEL: test_double_to_int8:
+; I686:       # %bb.0: # %entry
+; I686-NEXT:    subl $8, %esp
+; I686-NEXT:    fldl {{[0-9]+}}(%esp)
+; I686-NEXT:    fnstcw {{[0-9]+}}(%esp)
+; I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; I686-NEXT:    fistps {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; I686-NEXT:    movzbl {{[0-9]+}}(%esp), %eax
+; I686-NEXT:    addl $8, %esp
+; I686-NEXT:    retl
+entry:
+    %conv = fptosi double %input to i8
+    ret i8 %conv
+}
+
+define i16 @test_double_to_int16(double %input) nounwind {
+; X64-LABEL: test_double_to_int16:
+; X64:       # %bb.0: # %entry
+; X64-NEXT:    fldl {{[0-9]+}}(%rsp)
+; X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fistps -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    retq
+;
+; I686-LABEL: test_double_to_int16:
+; I686:       # %bb.0: # %entry
+; I686-NEXT:    subl $8, %esp
+; I686-NEXT:    fldl {{[0-9]+}}(%esp)
+; I686-NEXT:    fnstcw {{[0-9]+}}(%esp)
+; I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; I686-NEXT:    fistps {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; I686-NEXT:    addl $8, %esp
+; I686-NEXT:    retl
+entry:
+    %conv = fptosi double %input to i16
+    ret i16 %conv
+}
+
+define i32 @test_double_to_int32(double %input) nounwind {
+; X64-LABEL: test_double_to_int32:
+; X64:       # %bb.0: # %entry
+; X64-NEXT:    fldl {{[0-9]+}}(%rsp)
+; X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fistpl -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    retq
+;
+; I686-LABEL: test_double_to_int32:
+; I686:       # %bb.0: # %entry
+; I686-NEXT:    subl $8, %esp
+; I686-NEXT:    fldl {{[0-9]+}}(%esp)
+; I686-NEXT:    fnstcw (%esp)
+; I686-NEXT:    movzwl (%esp), %eax
+; I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; I686-NEXT:    fistpl {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw (%esp)
+; I686-NEXT:    movl {{[0-9]+}}(%esp), %eax
+; I686-NEXT:    addl $8, %esp
+; I686-NEXT:    retl
+entry:
+    %conv = fptosi double %input to i32
+    ret i32 %conv
+}
+
+define i64 @test_double_to_int64(double %input) nounwind {
+; X64-LABEL: test_double_to_int64:
+; X64:       # %bb.0: # %entry
+; X64-NEXT:    fldl {{[0-9]+}}(%rsp)
+; X64-NEXT:    fnstcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movzwl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT:    orl $3072, %eax # imm = 0xC00
+; X64-NEXT:    movw %ax, -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fistpll -{{[0-9]+}}(%rsp)
+; X64-NEXT:    fldcw -{{[0-9]+}}(%rsp)
+; X64-NEXT:    movq -{{[0-9]+}}(%rsp), %rax
+; X64-NEXT:    retq
+;
+; I686-LABEL: test_double_to_int64:
+; I686:       # %bb.0: # %entry
+; I686-NEXT:    subl $20, %esp
+; I686-NEXT:    fldl {{[0-9]+}}(%esp)
+; I686-NEXT:    fnstcw {{[0-9]+}}(%esp)
+; I686-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
+; I686-NEXT:    orl $3072, %eax # imm = 0xC00
+; I686-NEXT:    movw %ax, {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; I686-NEXT:    fistpll {{[0-9]+}}(%esp)
+; I686-NEXT:    fldcw {{[0-9]+}}(%esp)
+; I686-NEXT:    movl {{[0-9]+}}(%esp), %eax
+; I686-NEXT:    movl {{[0-9]+}}(%esp), %edx
+; I686-NEXT:    addl $20, %esp
+; I686-NEXT:    retl
+entry:
+    %conv = fptosi double %input to i64
+    ret i64 %conv
+}
diff --git a/llvm/test/CodeGen/X86/isel-int-to-fp-x87.ll b/llvm/test/CodeGen/X86/isel-int-to-fp-x87.ll
new file mode 100644
index 0000000000000..65eb3d8bbd401
--- /dev/null
+++ b/llvm/test/CodeGen/X86/isel-int-to-fp-x87.ll
@@ -0,0 +1,367 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; NOTE: Fast Isel is not added because it does not support x87 stores.
+
+; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse,-sse2 -global-isel=0 | FileCheck %s --check-prefixes X64,SDAG-X64
+; RUN: llc < %s -mtriple=x86_64-- -...
[truncated]

@pawan-nirpal-031
Copy link
Contributor Author

@e-kud @RKSimon can you please review.

@e-kud e-kud requested review from RKSimon and e-kud April 23, 2025 13:32
; NOTE: Fast Isel is not added because it does not support x87 stores.

; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse,-sse2 -global-isel=0 | FileCheck %s --check-prefixes X64,SDAG-X64
; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse,-sse2 -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes X64,GISEL-X64
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect that for precommit tests it should be abort=2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@e-kud e-kud requested a review from arsenm April 23, 2025 13:37
@@ -0,0 +1,272 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; NOTE: Fast Isel is not added because it does not support x87 stores.
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename[isel-sint-to-fp-x87.ll ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@pawan-nirpal-031
Copy link
Contributor Author

@arsenm Ping for review.

Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

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

LGTM with one minor


; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse,-sse2 -global-isel=0 | FileCheck %s --check-prefixes X64,SDAG-X64
; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse,-sse2 -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes X64,GISEL-X64
; RUN: llc < %s -mtriple=i686-- -mattr=+x87,-sse,-sse2 -global-isel=0 | FileCheck %s --check-prefixes I686,SDAG-I686
Copy link
Collaborator

Choose a reason for hiding this comment

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

(pedantic) Please can we use X86 instead of I686?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, Sure.

Copy link
Contributor

@e-kud e-kud left a comment

Choose a reason for hiding this comment

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

LGTM

; NOTE: Fast Isel is not added because it does not support x87 stores.

; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse,-sse2 -global-isel=0 | FileCheck %s --check-prefixes X64,SDAG-X64
; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse,-sse2 -global-isel -global-isel-abort=2 | FileCheck %s --check-prefixes X64,GISEL-X64
Copy link
Contributor

Choose a reason for hiding this comment

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

If none of these cases hit the fallback, it shouldn't be enabled

Copy link
Contributor

Choose a reason for hiding this comment

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

At this moment all cases hit the fallback to SDAG. In the next PR the support is going to be added, in this PR we change 2 to 1 illustrating which cases now are compiled completely by GlobalISel. Do you suggest to drop these lines as they in fact duplicate each other?

Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't matter if it's just going to be immediately changed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we'll change it in the following patch

@e-kud e-kud merged commit 1ff931e into llvm:main Apr 25, 2025
11 checks passed
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.

6 participants