Skip to content

Commit

Permalink
[DAG] reassociateOpsCommutative - pull out repeated getOperand() call…
Browse files Browse the repository at this point in the history
…s. NFC.
  • Loading branch information
RKSimon committed Nov 10, 2021
1 parent ea53a69 commit 381d147
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Expand Up @@ -1063,21 +1063,23 @@ SDValue DAGCombiner::reassociateOpsCommutative(unsigned Opc, const SDLoc &DL,
if (N0.getOpcode() != Opc)
return SDValue();

if (DAG.isConstantIntBuildVectorOrConstantInt(N0.getOperand(1))) {
SDValue N00 = N0.getOperand(0);
SDValue N01 = N0.getOperand(1);

if (DAG.isConstantIntBuildVectorOrConstantInt(N01)) {
if (DAG.isConstantIntBuildVectorOrConstantInt(N1)) {
// Reassociate: (op (op x, c1), c2) -> (op x, (op c1, c2))
if (SDValue OpNode =
DAG.FoldConstantArithmetic(Opc, DL, VT, {N0.getOperand(1), N1}))
return DAG.getNode(Opc, DL, VT, N0.getOperand(0), OpNode);
if (SDValue OpNode = DAG.FoldConstantArithmetic(Opc, DL, VT, {N01, N1}))
return DAG.getNode(Opc, DL, VT, N00, OpNode);
return SDValue();
}
if (N0.hasOneUse()) {
// Reassociate: (op (op x, c1), y) -> (op (op x, y), c1)
// iff (op x, c1) has one use
SDValue OpNode = DAG.getNode(Opc, SDLoc(N0), VT, N0.getOperand(0), N1);
SDValue OpNode = DAG.getNode(Opc, SDLoc(N0), VT, N00, N1);
if (!OpNode.getNode())
return SDValue();
return DAG.getNode(Opc, DL, VT, OpNode, N0.getOperand(1));
return DAG.getNode(Opc, DL, VT, OpNode, N01);
}
}
return SDValue();
Expand Down

0 comments on commit 381d147

Please sign in to comment.