[PATCH] D124722: [InstCombine] extract(u[add|sub].with.overflow(X, C), 0) --> [add|sub](X, C)

Nicolas Abram via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 30 16:15:15 PDT 2022


nico-abram created this revision.
nico-abram added reviewers: majnemer, nikic.
Herald added a subscriber: hiraditya.
Herald added a project: All.
nico-abram requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Trying to fix https://github.com/llvm/llvm-project/issues/53978 I ran into something like this: https://alive2.llvm.org/ce/z/bduF3e (generalized here https://alive2.llvm.org/ce/z/HdrUXt ) which is not currently optimized.

@nikic mentioned on discord that it might make more sense to canonicalize the intrinsic into a simple add/sub instead of trying to match that specific pattern

> Yes, InstCombine would be the place. Though frankly, we should probably just canonicalize uadd/usub away from intrinsics. That should result in better mid-end optimization, and CGP can reform them

This patch does that, but only when the addition is by a constant. I added `@uadd_res_ugt_smaller_const_or_ov` and `@uadd_res_ult_const_five_and_ov` as a baseline (The baseline is in the second diff).

With this patch, the original case in https://github.com/llvm/llvm-project/issues/53978 gets optimized to a constant false.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124722

Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/with_overflow.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124722.426255.patch
Type: text/x-patch
Size: 4740 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220430/4bca6fd2/attachment.bin>


More information about the llvm-commits mailing list