[PATCH] D144493: [InstSimplify] enhance simplifyWithOpReplaced() to allow more 'select' removal

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 21 07:52:22 PST 2023


spatel created this revision.
spatel added reviewers: nikic, kazu, goldstein.w.n, nlopes.
Herald added subscribers: StephenFan, hiraditya, kristof.beyls, mcrosier.
Herald added a project: All.
spatel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This is a generalization of a suggestion from issue #60799 <https://github.com/llvm/llvm-project/issues/60799> that allows removing a redundant guard of an input value via icmp+select. It should also solve issue #60801.

This only comes into play for a select with an equality condition where we are trying to substitute a constant into the false arm of a select. (A 'true' select arm substitution allows "refinement", so it is not on this code path.)

The constant must be the same in the compare and the select, and it must be a "binop absorber" (X op C = C). That query currently includes 'or', 'and', and 'mul', so there are tests for all of those opcodes.

We then use "impliesPoison" in both directions on the false arm binop to ensure that the select is not actually blocking poison from leaking. That could be potentially expensive as we recursively test each operand, but it is currently limited to a depth of 2. That's enough to catch our motivating cases, but probably nothing more complicated (although that seems unlikely).

I don't know how to generalize a proof for Alive2 for this, but here's a positive and negative test example to help illustrate the subtle logic differences of poison propagation:
https://alive2.llvm.org/ce/z/Sz5K-c


https://reviews.llvm.org/D144493

Files:
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/test/Transforms/InstSimplify/select.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144493.499170.patch
Type: text/x-patch
Size: 7165 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230221/1861049a/attachment.bin>


More information about the llvm-commits mailing list