[PATCH] D58644: [InstCombine] Optimize overflow check base on uadd.with.overflow result (PR40846)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 25 13:08:24 PST 2019


nikic created this revision.
nikic added reviewers: spatel, RKSimon.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Fix for https://bugs.llvm.org/show_bug.cgi?id=40846.

This adds a combine for cases where a `(a + b) < a` style overflow check is performed, but with `a + b` being the result of uadd.with.overflow, so the overflow result is also already available and we can just use it. Subsequently GVN/CSE will deduplicate the extracts.

We can run into this situation if you have both a uadd.with.overflow and a manual add + overflow check in the same function (on the same operands), in which case GVN will rewrite the add to the with.overflow result and leave you with this pattern.

The implementation is a bit ugly because I'm handling the various canonicalization edge cases. I'm wondering if we couldn't introduce something like `m_ICmpULT()` to match both ULT and the UGT commutation as well as the canonicalization edge-cases for constant operands.


Repository:
  rL LLVM

https://reviews.llvm.org/D58644

Files:
  lib/Transforms/InstCombine/InstCombineCompares.cpp
  test/Transforms/InstCombine/with_overflow.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58644.188246.patch
Type: text/x-patch
Size: 5584 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190225/163428d0/attachment.bin>


More information about the llvm-commits mailing list