[PATCH] D59071: [Transform] Improve saddo with mixed signs

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 9 13:42:17 PST 2019


nikic added a comment.

Moved constant range calculation into ValueTracking with rL355781 <https://reviews.llvm.org/rL355781>.

In D59071#1422370 <https://reviews.llvm.org/D59071#1422370>, @dlrobertson wrote:

> So do you mean update the `computeKnownBitsFromOperator` for `sadd_with_overflow` to also take into account the overflow flag?


Based on the previous commit, you can call `computeConstantRange()` on the LHS, and then check whether adding the RHS constant to that range can ever overflow. Assuming a range of Lo <= X <= Hi and constant C: If C >= 0 then an overflow cannot occur if Hi <= SignedMax - C and always occurs if Lo > SignedMax -C. If C < 0 then an overflow cannot occur if Lo >= SignedMin - C and always occurs if Hi < SignedMin - C.

To go one step further, rather than limiting this optimization to just the with.overflow intrinsics, this could be done in computeOverflowForSignedAdd (and friends), as this would also benefit saturated math intrinsics, as well as nsw/nuw inference on normal adds. (It might make sense to start with computeOverflowForUnsignedAdd, as the logic for unsigned is simpler.)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59071/new/

https://reviews.llvm.org/D59071





More information about the llvm-commits mailing list