Skip to content

Commit 784c15a

Browse files
committed
[DAG] visitSINT_TO_FP/UINT_TO_FP - use FoldConstantArithmetic to attempt to constant fold
Don't rely on isConstantIntBuildVectorOrConstantInt followed by getNode() will constant fold - FoldConstantArithmetic will do all of this for us. Cleanup for #112682
1 parent 8268bc4 commit 784c15a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18002,10 +18002,10 @@ SDValue DAGCombiner::visitSINT_TO_FP(SDNode *N) {
1800218002
return DAG.getConstantFP(0.0, DL, VT);
1800318003

1800418004
// fold (sint_to_fp c1) -> c1fp
18005-
if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
18006-
// ...but only if the target supports immediate floating-point values
18007-
(!LegalOperations || TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT)))
18008-
return DAG.getNode(ISD::SINT_TO_FP, DL, VT, N0);
18005+
// ...but only if the target supports immediate floating-point values
18006+
if ((!LegalOperations || TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT)))
18007+
if (SDValue C = DAG.FoldConstantArithmetic(ISD::SINT_TO_FP, DL, VT, {N0}))
18008+
return C;
1800918009

1801018010
// If the input is a legal type, and SINT_TO_FP is not legal on this target,
1801118011
// but UINT_TO_FP is legal on this target, try to convert.
@@ -18050,10 +18050,10 @@ SDValue DAGCombiner::visitUINT_TO_FP(SDNode *N) {
1805018050
return DAG.getConstantFP(0.0, DL, VT);
1805118051

1805218052
// fold (uint_to_fp c1) -> c1fp
18053-
if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
18054-
// ...but only if the target supports immediate floating-point values
18055-
(!LegalOperations || TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT)))
18056-
return DAG.getNode(ISD::UINT_TO_FP, DL, VT, N0);
18053+
// ...but only if the target supports immediate floating-point values
18054+
if ((!LegalOperations || TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT)))
18055+
if (SDValue C = DAG.FoldConstantArithmetic(ISD::UINT_TO_FP, DL, VT, {N0}))
18056+
return C;
1805718057

1805818058
// If the input is a legal type, and UINT_TO_FP is not legal on this target,
1805918059
// but SINT_TO_FP is legal on this target, try to convert.

0 commit comments

Comments
 (0)