[llvm] [X86][NFC] - Add sitofp and fptosi tests for x87 mode (PR #136860)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 23 23:02:13 PDT 2025
================
@@ -0,0 +1,406 @@
+; 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=2 | 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 {
+; X64-LABEL: test_float_to_int8:
+; 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: movzbl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT: retq
+;
+; I686-LABEL: test_float_to_int8:
+; 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: movzbl {{[0-9]+}}(%esp), %eax
+; I686-NEXT: addl $8, %esp
+; I686-NEXT: retl
+entry:
+ %conv = fptosi float %input to i8
+ ret i8 %conv
+}
+
+define i8 @test_longdouble_to_int8(x86_fp80 %input) nounwind {
+; X64-LABEL: test_longdouble_to_int8:
+; 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: movzbl -{{[0-9]+}}(%rsp), %eax
+; X64-NEXT: retq
+;
+; I686-LABEL: test_longdouble_to_int8:
+; 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: movzbl {{[0-9]+}}(%esp), %eax
+; I686-NEXT: addl $8, %esp
+; 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
+;
+; I686-LABEL: test_float_to_int64:
+; I686: # %bb.0: # %entry
+; I686-NEXT: subl $20, %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: 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 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
+;
+; I686-LABEL: test_longdouble_to_int64:
+; I686: # %bb.0: # %entry
+; I686-NEXT: subl $20, %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: 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 x86_fp80 %input to i64
+ ret i64 %conv
+}
+
+define i8 @test_double_to_int8(double %input) nounwind {
+; X64-LABEL: test_double_to_int8:
+; 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: movzbl -{{[0-9]+}}(%rsp), %eax
+; 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
+}
----------------
JaydeepChauhan14 wrote:
Need to add below details.
```
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; GISEL-I686: {{.*}}
; GISEL-X64: {{.*}}
; SDAG-I686: {{.*}}
; SDAG-X64: {{.*}}
```
https://github.com/llvm/llvm-project/pull/136860
More information about the llvm-commits
mailing list