Skip to content

Commit

Permalink
[DAG] ExpandIntRes_ADDSUB - create UADDO/USUBO instead of ADDCARRY/SU…
Browse files Browse the repository at this point in the history
…BCARRY if overflow is known to be zero

As noticed on D127115, when splitting ADD/SUB nodes we often end up with cases where overflow from the lower bits is impossible - in such cases we're better off breaking the carry chain dependency as soon as possible.

This path is being exercised by llvm/test/CodeGen/ARM/dsp-mlal.ll, although I haven't been able to get any codegen diff without a topological worklist.
  • Loading branch information
RKSimon committed Jul 23, 2022
1 parent 2bfb0fc commit 2421a5a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
Expand Up @@ -2912,11 +2912,15 @@ void DAGTypeLegalizer::ExpandIntRes_ADDSUB(SDNode *N,
if (N->getOpcode() == ISD::ADD) {
Lo = DAG.getNode(ISD::UADDO, dl, VTList, LoOps);
HiOps[2] = Lo.getValue(1);
Hi = DAG.getNode(ISD::ADDCARRY, dl, VTList, HiOps);
Hi = DAG.computeKnownBits(HiOps[2]).isZero()
? DAG.getNode(ISD::UADDO, dl, VTList, makeArrayRef(HiOps, 2))
: DAG.getNode(ISD::ADDCARRY, dl, VTList, HiOps);
} else {
Lo = DAG.getNode(ISD::USUBO, dl, VTList, LoOps);
HiOps[2] = Lo.getValue(1);
Hi = DAG.getNode(ISD::SUBCARRY, dl, VTList, HiOps);
Hi = DAG.computeKnownBits(HiOps[2]).isZero()
? DAG.getNode(ISD::USUBO, dl, VTList, makeArrayRef(HiOps, 2))
: DAG.getNode(ISD::SUBCARRY, dl, VTList, HiOps);
}
return;
}
Expand Down

0 comments on commit 2421a5a

Please sign in to comment.