[PATCH] D104932: [instcombine] Fold overflow check using overflow intrinsic to comparison

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 25 11:00:18 PDT 2021


reames created this revision.
reames added reviewers: spatel, craig.topper.
Herald added subscribers: pengfei, bollu, hiraditya, mcrosier.
reames requested review of this revision.
Herald added a project: LLVM.

This follows up to D104665 <https://reviews.llvm.org/D104665> (which added umulo handling alongside the existing uaddo case), and generalizes for the remaining overflow intrinsics.

I went to add analogous handling to LVI, and discovered that LVI already had a more general implementation.  Instead, we can port was LVI does to instcombine.  :)

A couple of points for review discussion:

- I could have just generated two compares, and let instcombine refold them into the sub form.  Not sure which is cleaner here.
- The profitability on the sadd and ssub cases is a bit debatable.  We trade a test of flags on a subtract for an add and cmp.  This might be slightly slower (if not refolded by backend), but exposes the logic more clearly for further optimization.  I'm tempted to do it, but thoughts?  (Note that the x86 backend currently does not refold this, but probably should.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104932

Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/saddo.ll
  llvm/test/Transforms/InstCombine/smulo.ll
  llvm/test/Transforms/InstCombine/ssubo.ll
  llvm/test/Transforms/InstCombine/usubo.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104932.354553.patch
Type: text/x-patch
Size: 14916 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210625/45fcf863/attachment.bin>


More information about the llvm-commits mailing list