[llvm] Add more cases for computeOverflowForSignedAdd (PR #99900)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 29 06:39:10 PDT 2024
================
@@ -4243,8 +4243,27 @@ SelectionDAG::computeOverflowForSignedAdd(SDValue N0, SDValue N1) const {
if (ComputeNumSignBits(N0) > 1 && ComputeNumSignBits(N1) > 1)
return OFK_Never;
- // TODO: Add ConstantRange::signedAddMayOverflow handling.
- return OFK_Sometime;
+ // smulhi + any value less than half of signed max
+ KnownBits N1Known = computeKnownBits(N1);
+ if (N0.getOpcode() == ISD::SMUL_LOHI && N0.getResNo() == 1) {
+ APInt Max = APInt::getSignedMaxValue(N1.getScalarValueSizeInBits());
+ Max.lshrInPlace(1);
+ if (N1Known.getMaxValue().sle(Max))
----------------
RKSimon wrote:
Do we have cases for SMUL_LOHI? The UMUL_LOHI equivalent patterns were pretty obscure and were to help fix a couple of specific UADDO+CARRY situations (see D29565\D29587).
You should be able to construct knownbits tests cases (although I expect many will already be caught by the signbits check above).
https://github.com/llvm/llvm-project/pull/99900
More information about the llvm-commits
mailing list