[InstCombine] Canonicalize uadd.with.overflow to uadd.sat
authorDavid Green <david.green@arm.com>
Thu, 31 Oct 2019 12:42:36 +0000 (12:42 +0000)
committerDavid Green <david.green@arm.com>
Thu, 31 Oct 2019 12:45:38 +0000 (12:45 +0000)
commita5f7bc0de72f1c631ef13d2cccf2b77c9a030e7d
treec27ccfd23b13f4097f9d9b8bd39f70ca3ad9feae
parenta8db456b53a1783e2c8b3f3a6666dfa715a885d4
[InstCombine] Canonicalize uadd.with.overflow to uadd.sat

This adds some patterns to transform uadd.with.overflow to uadd.sat
(with usub.with.overflow to usub.sat too). The patterns selects from
UINTMAX (or 0 for subs) depending on whether the operation overflowed.

Signed patterns are a little more involved (they can wrap in two
directions), but can be added here in a followup patch too.

Differential Revision: https://reviews.llvm.org/D69245
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/overflow_to_sat.ll