Skip to content

Commit 5f5a641

Browse files
committed
Revert "[DAGCombiner] Simplifying {si|ui}tofp when only signbit is needed"
This reverts commit 353fbeb. It crashes when it encounters an UINT_TO_FP. llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1618 in SDValue llvm::SelectionDAG::getConstant(const ConstantInt &, const SDLoc &, EVT, bool, bool): VT.isInteger() && "Cannot create FP integer constant!"
1 parent 1232964 commit 5f5a641

File tree

3 files changed

+16
-38
lines changed

3 files changed

+16
-38
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -611,25 +611,6 @@ bool TargetLowering::ShrinkDemandedOp(SDValue Op, unsigned BitWidth,
611611
return false;
612612
}
613613

614-
static SDValue simplifyUseOfIntToFP(SDValue Op, const APInt &DemandedBits,
615-
SelectionDAG &DAG) {
616-
unsigned Opc = Op.getOpcode();
617-
assert((Opc == ISD::SINT_TO_FP || Opc == ISD::UINT_TO_FP) &&
618-
"Invalid Int -> FP Opcode");
619-
if (!DemandedBits.isSignMask())
620-
return SDValue();
621-
622-
EVT VT = Op.getValueType();
623-
if (Opc == ISD::UINT_TO_FP)
624-
return DAG.getConstant(0, SDLoc(Op), VT);
625-
626-
EVT InnerVT = Op.getOperand(0).getValueType();
627-
if (VT.getScalarSizeInBits() == InnerVT.getScalarSizeInBits())
628-
return DAG.getBitcast(VT, Op.getOperand(0));
629-
630-
return SDValue();
631-
}
632-
633614
bool TargetLowering::SimplifyDemandedBits(SDValue Op, const APInt &DemandedBits,
634615
DAGCombinerInfo &DCI) const {
635616
SelectionDAG &DAG = DCI.DAG;
@@ -835,11 +816,6 @@ SDValue TargetLowering::SimplifyMultipleUseDemandedBits(
835816
}
836817
break;
837818
}
838-
case ISD::UINT_TO_FP:
839-
case ISD::SINT_TO_FP:
840-
if (SDValue R = simplifyUseOfIntToFP(Op, DemandedBits, DAG))
841-
return R;
842-
break;
843819
case ISD::SIGN_EXTEND_INREG: {
844820
// If none of the extended bits are demanded, eliminate the sextinreg.
845821
SDValue Op0 = Op.getOperand(0);
@@ -2337,12 +2313,6 @@ bool TargetLowering::SimplifyDemandedBits(
23372313
Known = TLO.DAG.computeKnownBits(Op, DemandedElts, Depth);
23382314
break;
23392315
}
2340-
case ISD::UINT_TO_FP:
2341-
case ISD::SINT_TO_FP:
2342-
if (SDValue R = simplifyUseOfIntToFP(Op, DemandedBits, TLO.DAG))
2343-
return TLO.CombineTo(Op, R);
2344-
Known = TLO.DAG.computeKnownBits(Op, DemandedElts, Depth);
2345-
break;
23462316
case ISD::SIGN_EXTEND_INREG: {
23472317
SDValue Op0 = Op.getOperand(0);
23482318
EVT ExVT = cast<VTSDNode>(Op.getOperand(1))->getVT();

llvm/test/CodeGen/X86/combine-sse41-intrinsics.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,14 @@ define <4 x float> @demandedbits_sitofp_blendvps(<4 x float> %a0, <4 x float> %a
164164
; SSE-LABEL: demandedbits_sitofp_blendvps:
165165
; SSE: # %bb.0:
166166
; SSE-NEXT: movaps %xmm0, %xmm3
167-
; SSE-NEXT: movaps %xmm2, %xmm0
167+
; SSE-NEXT: cvtdq2ps %xmm2, %xmm0
168168
; SSE-NEXT: blendvps %xmm0, %xmm1, %xmm3
169169
; SSE-NEXT: movaps %xmm3, %xmm0
170170
; SSE-NEXT: retq
171171
;
172172
; AVX-LABEL: demandedbits_sitofp_blendvps:
173173
; AVX: # %bb.0:
174+
; AVX-NEXT: vcvtdq2ps %xmm2, %xmm2
174175
; AVX-NEXT: vblendvps %xmm2, %xmm1, %xmm0, %xmm0
175176
; AVX-NEXT: retq
176177
%cvt = sitofp <4 x i32> %a2 to <4 x float>

llvm/test/CodeGen/X86/int-to-fp-demanded.ll

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ declare void @use.i32(i32)
77
define i32 @sitofp_signbit_only(i32 %i_in) nounwind {
88
; X86-LABEL: sitofp_signbit_only:
99
; X86: # %bb.0:
10+
; X86-NEXT: subl $8, %esp
11+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
12+
; X86-NEXT: movl %eax, (%esp)
13+
; X86-NEXT: fildl (%esp)
14+
; X86-NEXT: fstps {{[0-9]+}}(%esp)
1015
; X86-NEXT: movl $-2147483648, %eax # imm = 0x80000000
1116
; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
17+
; X86-NEXT: addl $8, %esp
1218
; X86-NEXT: retl
1319
;
1420
; X64-LABEL: sitofp_signbit_only:
1521
; X64: # %bb.0:
16-
; X64-NEXT: movd %edi, %xmm0
22+
; X64-NEXT: cvtsi2ss %edi, %xmm0
1723
; X64-NEXT: movmskps %xmm0, %eax
1824
; X64-NEXT: shll $31, %eax
1925
; X64-NEXT: retq
@@ -38,8 +44,8 @@ define i32 @sitofp_signbit_only_okay_width(i16 %i_in) nounwind {
3844
;
3945
; X64-LABEL: sitofp_signbit_only_okay_width:
4046
; X64: # %bb.0:
41-
; X64-NEXT: shll $16, %edi
42-
; X64-NEXT: movd %edi, %xmm0
47+
; X64-NEXT: movswl %di, %eax
48+
; X64-NEXT: cvtsi2ss %eax, %xmm0
4349
; X64-NEXT: movmskps %xmm0, %eax
4450
; X64-NEXT: shll $31, %eax
4551
; X64-NEXT: retq
@@ -76,14 +82,15 @@ define <2 x i16> @sitofp_signbit_only_fail_bad_width2(i32 %i_in) nounwind {
7682
; X86-LABEL: sitofp_signbit_only_fail_bad_width2:
7783
; X86: # %bb.0:
7884
; X86-NEXT: subl $8, %esp
79-
; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
80-
; X86-NEXT: movl %edx, (%esp)
85+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
86+
; X86-NEXT: movl %eax, (%esp)
8187
; X86-NEXT: fildl (%esp)
8288
; X86-NEXT: fstps {{[0-9]+}}(%esp)
89+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
90+
; X86-NEXT: movl %eax, %edx
8391
; X86-NEXT: shrl $16, %edx
92+
; X86-NEXT: andl $32768, %eax # imm = 0x8000
8493
; X86-NEXT: andl $32768, %edx # imm = 0x8000
85-
; X86-NEXT: movl $32768, %eax # imm = 0x8000
86-
; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
8794
; X86-NEXT: # kill: def $ax killed $ax killed $eax
8895
; X86-NEXT: # kill: def $dx killed $dx killed $edx
8996
; X86-NEXT: addl $8, %esp

0 commit comments

Comments
 (0)