Skip to content

Commit 3a1df05

Browse files
committed
[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.
1 parent 7a43be1 commit 3a1df05

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18167,10 +18167,10 @@ SDValue DAGCombiner::visitFP_ROUND(SDNode *N) {
1816718167
SDValue N0 = N->getOperand(0);
1816818168
SDValue N1 = N->getOperand(1);
1816918169
EVT VT = N->getValueType(0);
18170+
SDLoc DL(N);
1817018171

1817118172
// fold (fp_round c1fp) -> c1fp
18172-
if (SDValue C =
18173-
DAG.FoldConstantArithmetic(ISD::FP_ROUND, SDLoc(N), VT, {N0, N1}))
18173+
if (SDValue C = DAG.FoldConstantArithmetic(ISD::FP_ROUND, DL, VT, {N0, N1}))
1817418174
return C;
1817518175

1817618176
// fold (fp_round (fp_extend x)) -> x
@@ -18201,12 +18201,10 @@ SDValue DAGCombiner::visitFP_ROUND(SDNode *N) {
1820118201
// single-step fp_round we want to fold to.
1820218202
// In other words, double rounding isn't the same as rounding.
1820318203
// Also, this is a value preserving truncation iff both fp_round's are.
18204-
if (DAG.getTarget().Options.UnsafeFPMath || N0IsTrunc) {
18205-
SDLoc DL(N);
18204+
if (DAG.getTarget().Options.UnsafeFPMath || N0IsTrunc)
1820618205
return DAG.getNode(
1820718206
ISD::FP_ROUND, DL, VT, N0.getOperand(0),
1820818207
DAG.getIntPtrConstant(NIsTrunc && N0IsTrunc, DL, /*isTarget=*/true));
18209-
}
1821018208
}
1821118209

1821218210
// fold (fp_round (copysign X, Y)) -> (copysign (fp_round X), Y)
@@ -18220,8 +18218,7 @@ SDValue DAGCombiner::visitFP_ROUND(SDNode *N) {
1822018218
SDValue Tmp = DAG.getNode(ISD::FP_ROUND, SDLoc(N0), VT,
1822118219
N0.getOperand(0), N1);
1822218220
AddToWorklist(Tmp.getNode());
18223-
return DAG.getNode(ISD::FCOPYSIGN, SDLoc(N), VT,
18224-
Tmp, N0.getOperand(1));
18221+
return DAG.getNode(ISD::FCOPYSIGN, DL, VT, Tmp, N0.getOperand(1));
1822518222
}
1822618223

1822718224
if (SDValue NewVSel = matchVSelectOpSizesWithSetCC(N))

0 commit comments

Comments
 (0)