[llvm] 3a1df05 - [DAG] visitFP_ROUND - use FoldConstantArithmetic to attempt to constant fold
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 18 02:11:05 PDT 2024
Author: Simon Pilgrim
Date: 2024-10-18T10:10:43+01:00
New Revision: 3a1df05ca91fa6a0f893123ad08a46a443b0b486
URL: https://github.com/llvm/llvm-project/commit/3a1df05ca91fa6a0f893123ad08a46a443b0b486
DIFF: https://github.com/llvm/llvm-project/commit/3a1df05ca91fa6a0f893123ad08a46a443b0b486.diff
LOG: [DAG] visitFP_ROUND - 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.
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 b717847fc302df..c3bcd3bb936728 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -18167,10 +18167,10 @@ SDValue DAGCombiner::visitFP_ROUND(SDNode *N) {
SDValue N0 = N->getOperand(0);
SDValue N1 = N->getOperand(1);
EVT VT = N->getValueType(0);
+ SDLoc DL(N);
// fold (fp_round c1fp) -> c1fp
- if (SDValue C =
- DAG.FoldConstantArithmetic(ISD::FP_ROUND, SDLoc(N), VT, {N0, N1}))
+ if (SDValue C = DAG.FoldConstantArithmetic(ISD::FP_ROUND, DL, VT, {N0, N1}))
return C;
// fold (fp_round (fp_extend x)) -> x
@@ -18201,12 +18201,10 @@ SDValue DAGCombiner::visitFP_ROUND(SDNode *N) {
// single-step fp_round we want to fold to.
// In other words, double rounding isn't the same as rounding.
// Also, this is a value preserving truncation iff both fp_round's are.
- if (DAG.getTarget().Options.UnsafeFPMath || N0IsTrunc) {
- SDLoc DL(N);
+ if (DAG.getTarget().Options.UnsafeFPMath || N0IsTrunc)
return DAG.getNode(
ISD::FP_ROUND, DL, VT, N0.getOperand(0),
DAG.getIntPtrConstant(NIsTrunc && N0IsTrunc, DL, /*isTarget=*/true));
- }
}
// fold (fp_round (copysign X, Y)) -> (copysign (fp_round X), Y)
@@ -18220,8 +18218,7 @@ SDValue DAGCombiner::visitFP_ROUND(SDNode *N) {
SDValue Tmp = DAG.getNode(ISD::FP_ROUND, SDLoc(N0), VT,
N0.getOperand(0), N1);
AddToWorklist(Tmp.getNode());
- return DAG.getNode(ISD::FCOPYSIGN, SDLoc(N), VT,
- Tmp, N0.getOperand(1));
+ return DAG.getNode(ISD::FCOPYSIGN, DL, VT, Tmp, N0.getOperand(1));
}
if (SDValue NewVSel = matchVSelectOpSizesWithSetCC(N))
More information about the llvm-commits
mailing list