[PATCH] D124771: [SDAG] fix miscompile when casting int->FP->int
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 2 11:57:40 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG747c6a0c734e: [SDAG] fix miscompile when casting int->FP->int (authored by spatel).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124771/new/
https://reviews.llvm.org/D124771
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/AArch64/float-conv-elim.ll
llvm/test/CodeGen/X86/float-conv-elim.ll
Index: llvm/test/CodeGen/X86/float-conv-elim.ll
===================================================================
--- llvm/test/CodeGen/X86/float-conv-elim.ll
+++ llvm/test/CodeGen/X86/float-conv-elim.ll
@@ -82,12 +82,13 @@
ret i32 %r
}
+; This requires converting to FP and back.
+
define i32 @s32_f32_s25_s32(i32 %a) {
; CHECK-LABEL: s32_f32_s25_s32:
; CHECK: # %bb.0:
-; CHECK-NEXT: movl %edi, %eax
-; CHECK-NEXT: shll $7, %eax
-; CHECK-NEXT: sarl $7, %eax
+; CHECK-NEXT: cvtsi2ss %edi, %xmm0
+; CHECK-NEXT: cvttss2si %xmm0, %eax
; CHECK-NEXT: retq
%f = sitofp i32 %a to float
%i = fptosi float %f to i25
@@ -107,12 +108,14 @@
ret i32 %r
}
+; TODO: This could avoid converting to FP.
+
define i32 @u32_f32_s25_s32(i32 %a) {
; CHECK-LABEL: u32_f32_s25_s32:
; CHECK: # %bb.0:
; CHECK-NEXT: movl %edi, %eax
-; CHECK-NEXT: shll $7, %eax
-; CHECK-NEXT: sarl $7, %eax
+; CHECK-NEXT: cvtsi2ss %rax, %xmm0
+; CHECK-NEXT: cvttss2si %xmm0, %eax
; CHECK-NEXT: retq
%f = uitofp i32 %a to float
%i = fptosi float %f to i25
Index: llvm/test/CodeGen/AArch64/float-conv-elim.ll
===================================================================
--- llvm/test/CodeGen/AArch64/float-conv-elim.ll
+++ llvm/test/CodeGen/AArch64/float-conv-elim.ll
@@ -45,10 +45,13 @@
ret i32 %r
}
+; This requires converting to FP and back.
+
define i32 @s32_f32_s25_s32(i32 %a) {
; CHECK-LABEL: s32_f32_s25_s32:
; CHECK: // %bb.0:
-; CHECK-NEXT: sbfx w0, w0, #0, #25
+; CHECK-NEXT: scvtf s0, w0
+; CHECK-NEXT: fcvtzs w0, s0
; CHECK-NEXT: ret
%f = sitofp i32 %a to float
%i = fptosi float %f to i25
@@ -68,10 +71,13 @@
ret i32 %r
}
+; TODO: This could avoid converting to FP.
+
define i32 @u32_f32_s25_s32(i32 %a) {
; CHECK-LABEL: u32_f32_s25_s32:
; CHECK: // %bb.0:
-; CHECK-NEXT: sbfx w0, w0, #0, #25
+; CHECK-NEXT: ucvtf s0, w0
+; CHECK-NEXT: fcvtzs w0, s0
; CHECK-NEXT: ret
%f = uitofp i32 %a to float
%i = fptosi float %f to i25
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -15527,7 +15527,7 @@
// This means this is also safe for a signed input and unsigned output, since
// a negative input would lead to undefined behavior.
unsigned InputSize = (int)SrcVT.getScalarSizeInBits() - IsInputSigned;
- unsigned OutputSize = (int)VT.getScalarSizeInBits() - IsOutputSigned;
+ unsigned OutputSize = (int)VT.getScalarSizeInBits();
unsigned ActualSize = std::min(InputSize, OutputSize);
const fltSemantics &sem = DAG.EVTToAPFloatSemantics(N0.getValueType());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124771.426472.patch
Type: text/x-patch
Size: 2773 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220502/18b76825/attachment.bin>
More information about the llvm-commits
mailing list