[llvm] 256bbdb - [DAG] visitFCEIL/FTRUNC/FFLOOR/FNEG - use FoldConstantArithmetic to attempt to constant fold
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 17 08:54:00 PDT 2024
Author: Simon Pilgrim
Date: 2024-10-17T16:53:44+01:00
New Revision: 256bbdb3f642c37268d6fa5dc35e01cd27a67b61
URL: https://github.com/llvm/llvm-project/commit/256bbdb3f642c37268d6fa5dc35e01cd27a67b61
DIFF: https://github.com/llvm/llvm-project/commit/256bbdb3f642c37268d6fa5dc35e01cd27a67b61.diff
LOG: [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
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 644054361dd3ee..18439b87a83b7d 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -18291,8 +18291,8 @@ SDValue DAGCombiner::visitFCEIL(SDNode *N) {
EVT VT = N->getValueType(0);
// fold (fceil c1) -> fceil(c1)
- if (DAG.isConstantFPBuildVectorOrConstantFP(N0))
- return DAG.getNode(ISD::FCEIL, SDLoc(N), VT, N0);
+ if (SDValue C = DAG.FoldConstantArithmetic(ISD::FCEIL, SDLoc(N), VT, {N0}))
+ return C;
return SDValue();
}
@@ -18302,8 +18302,8 @@ SDValue DAGCombiner::visitFTRUNC(SDNode *N) {
EVT VT = N->getValueType(0);
// fold (ftrunc c1) -> ftrunc(c1)
- if (DAG.isConstantFPBuildVectorOrConstantFP(N0))
- return DAG.getNode(ISD::FTRUNC, SDLoc(N), VT, N0);
+ if (SDValue C = DAG.FoldConstantArithmetic(ISD::FTRUNC, SDLoc(N), VT, {N0}))
+ return C;
// fold ftrunc (known rounded int x) -> x
// ftrunc is a part of fptosi/fptoui expansion on some targets, so this is
@@ -18336,8 +18336,8 @@ SDValue DAGCombiner::visitFFLOOR(SDNode *N) {
EVT VT = N->getValueType(0);
// fold (ffloor c1) -> ffloor(c1)
- if (DAG.isConstantFPBuildVectorOrConstantFP(N0))
- return DAG.getNode(ISD::FFLOOR, SDLoc(N), VT, N0);
+ if (SDValue C = DAG.FoldConstantArithmetic(ISD::FFLOOR, SDLoc(N), VT, {N0}))
+ return C;
return SDValue();
}
@@ -18348,8 +18348,8 @@ SDValue DAGCombiner::visitFNEG(SDNode *N) {
SelectionDAG::FlagInserter FlagsInserter(DAG, N);
// Constant fold FNEG.
- if (DAG.isConstantFPBuildVectorOrConstantFP(N0))
- return DAG.getNode(ISD::FNEG, SDLoc(N), VT, N0);
+ if (SDValue C = DAG.FoldConstantArithmetic(ISD::FNEG, SDLoc(N), VT, {N0}))
+ return C;
if (SDValue NegN0 =
TLI.getNegatedExpression(N0, DAG, LegalOperations, ForCodeSize))
More information about the llvm-commits
mailing list