[PATCH] D108165: [InstCombine] fold signed min/max intrinsics with negated operands

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 16 14:18:37 PDT 2021


spatel created this revision.
spatel added reviewers: lebedev.ri, nikic, RKSimon.
Herald added subscribers: hiraditya, mcrosier.
spatel requested review of this revision.
Herald added a project: LLVM.

If both operands are negated, we can invert the min/max and do the negation after:
smax (neg nsw X), (neg nsw Y) --> neg nsw (smin X, Y)
smin (neg nsw X), (neg nsw Y) --> neg nsw (smax X, Y)

This is visible as a remaining regression in D98152 <https://reviews.llvm.org/D98152>. I don't see a way to generalize this for 'unsigned' or adapt Negator to handle it. This only appears to be safe with 'nsw':
https://alive2.llvm.org/ce/z/GUy1zJ


https://reviews.llvm.org/D108165

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/test/Transforms/InstCombine/minmax-intrinsics.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108165.366741.patch
Type: text/x-patch
Size: 4187 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210816/28d5bb29/attachment.bin>


More information about the llvm-commits mailing list