Skip to content

Commit c72992b

Browse files
committed
[DAG] visitABS - 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 2f792f6 commit c72992b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18433,10 +18433,11 @@ SDValue DAGCombiner::visitFMinMax(SDNode *N) {
1843318433
SDValue DAGCombiner::visitFABS(SDNode *N) {
1843418434
SDValue N0 = N->getOperand(0);
1843518435
EVT VT = N->getValueType(0);
18436+
SDLoc DL(N);
1843618437

1843718438
// fold (fabs c1) -> fabs(c1)
18438-
if (DAG.isConstantFPBuildVectorOrConstantFP(N0))
18439-
return DAG.getNode(ISD::FABS, SDLoc(N), VT, N0);
18439+
if (SDValue C = DAG.FoldConstantArithmetic(ISD::FABS, DL, VT, {N0}))
18440+
return C;
1844018441

1844118442
// fold (fabs (fabs x)) -> (fabs x)
1844218443
if (N0.getOpcode() == ISD::FABS)
@@ -18445,7 +18446,7 @@ SDValue DAGCombiner::visitFABS(SDNode *N) {
1844518446
// fold (fabs (fneg x)) -> (fabs x)
1844618447
// fold (fabs (fcopysign x, y)) -> (fabs x)
1844718448
if (N0.getOpcode() == ISD::FNEG || N0.getOpcode() == ISD::FCOPYSIGN)
18448-
return DAG.getNode(ISD::FABS, SDLoc(N), VT, N0.getOperand(0));
18449+
return DAG.getNode(ISD::FABS, DL, VT, N0.getOperand(0));
1844918450

1845018451
if (SDValue Cast = foldSignChangeInBitcast(N))
1845118452
return Cast;

0 commit comments

Comments
 (0)