Skip to content

Commit 256bbdb

Browse files
committed
[DAG] visitFCEIL/FTRUNC/FFLOOR/FNEG - use FoldConstantArithmetic to attempt to constant fold
Don't rely on isConstantFPBuildVectorOrConstantFP followed by getNode() will constant fold - FoldConstantArithmetic will do all of this for us. Cleanup for #112682
1 parent 76f3776 commit 256bbdb

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
@@ -18291,8 +18291,8 @@ SDValue DAGCombiner::visitFCEIL(SDNode *N) {
1829118291
EVT VT = N->getValueType(0);
1829218292

1829318293
// fold (fceil c1) -> fceil(c1)
18294-
if (DAG.isConstantFPBuildVectorOrConstantFP(N0))
18295-
return DAG.getNode(ISD::FCEIL, SDLoc(N), VT, N0);
18294+
if (SDValue C = DAG.FoldConstantArithmetic(ISD::FCEIL, SDLoc(N), VT, {N0}))
18295+
return C;
1829618296

1829718297
return SDValue();
1829818298
}
@@ -18302,8 +18302,8 @@ SDValue DAGCombiner::visitFTRUNC(SDNode *N) {
1830218302
EVT VT = N->getValueType(0);
1830318303

1830418304
// fold (ftrunc c1) -> ftrunc(c1)
18305-
if (DAG.isConstantFPBuildVectorOrConstantFP(N0))
18306-
return DAG.getNode(ISD::FTRUNC, SDLoc(N), VT, N0);
18305+
if (SDValue C = DAG.FoldConstantArithmetic(ISD::FTRUNC, SDLoc(N), VT, {N0}))
18306+
return C;
1830718307

1830818308
// fold ftrunc (known rounded int x) -> x
1830918309
// ftrunc is a part of fptosi/fptoui expansion on some targets, so this is
@@ -18336,8 +18336,8 @@ SDValue DAGCombiner::visitFFLOOR(SDNode *N) {
1833618336
EVT VT = N->getValueType(0);
1833718337

1833818338
// fold (ffloor c1) -> ffloor(c1)
18339-
if (DAG.isConstantFPBuildVectorOrConstantFP(N0))
18340-
return DAG.getNode(ISD::FFLOOR, SDLoc(N), VT, N0);
18339+
if (SDValue C = DAG.FoldConstantArithmetic(ISD::FFLOOR, SDLoc(N), VT, {N0}))
18340+
return C;
1834118341

1834218342
return SDValue();
1834318343
}
@@ -18348,8 +18348,8 @@ SDValue DAGCombiner::visitFNEG(SDNode *N) {
1834818348
SelectionDAG::FlagInserter FlagsInserter(DAG, N);
1834918349

1835018350
// Constant fold FNEG.
18351-
if (DAG.isConstantFPBuildVectorOrConstantFP(N0))
18352-
return DAG.getNode(ISD::FNEG, SDLoc(N), VT, N0);
18351+
if (SDValue C = DAG.FoldConstantArithmetic(ISD::FNEG, SDLoc(N), VT, {N0}))
18352+
return C;
1835318353

1835418354
if (SDValue NegN0 =
1835518355
TLI.getNegatedExpression(N0, DAG, LegalOperations, ForCodeSize))

0 commit comments

Comments
 (0)