Skip to content

Commit

Permalink
[DAG] foldBinOpIntoSelect - use FoldConstantArithmetic instead of get…
Browse files Browse the repository at this point in the history
…Node() + constant check.

This prevents unused nodes from being created if the constant check fails.

Noticed while triaging D127115 regressions
  • Loading branch information
RKSimon committed Mar 21, 2023
1 parent 0e9523e commit a6a788b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2483,16 +2483,14 @@ SDValue DAGCombiner::foldBinOpIntoSelect(SDNode *BO) {
// constant. Eliminate the binop by pulling the constant math into the
// select. Example: add (select Cond, CT, CF), CBO --> select Cond, CT +
// CBO, CF + CBO
NewCT = SelOpNo ? DAG.getNode(BinOpcode, DL, VT, CBO, CT)
: DAG.getNode(BinOpcode, DL, VT, CT, CBO);
if (!NewCT.isUndef() && !isConstantOrConstantVector(NewCT, true) &&
!DAG.isConstantFPBuildVectorOrConstantFP(NewCT))
NewCT = SelOpNo ? DAG.FoldConstantArithmetic(BinOpcode, DL, VT, {CBO, CT})
: DAG.FoldConstantArithmetic(BinOpcode, DL, VT, {CT, CBO});
if (!NewCT)
return SDValue();

NewCF = SelOpNo ? DAG.getNode(BinOpcode, DL, VT, CBO, CF)
: DAG.getNode(BinOpcode, DL, VT, CF, CBO);
if (!NewCF.isUndef() && !isConstantOrConstantVector(NewCF, true) &&
!DAG.isConstantFPBuildVectorOrConstantFP(NewCF))
NewCF = SelOpNo ? DAG.FoldConstantArithmetic(BinOpcode, DL, VT, {CBO, CF})
: DAG.FoldConstantArithmetic(BinOpcode, DL, VT, {CF, CBO});
if (!NewCF)
return SDValue();
}

Expand Down

0 comments on commit a6a788b

Please sign in to comment.