[all-commits] [llvm/llvm-project] ae2322: [InstSimplify] enhance simplifyWithOpReplaced() to...

Sanjay Patel via All-commits all-commits at lists.llvm.org
Tue Feb 21 14:03:54 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ae2322a0dca9f8c39b1db51756c7155610fe668a
      https://github.com/llvm/llvm-project/commit/ae2322a0dca9f8c39b1db51756c7155610fe668a
  Author: Sanjay Patel <spatel at rotateright.com>
  Date:   2023-02-21 (Tue, 21 Feb 2023)

  Changed paths:
    M llvm/lib/Analysis/InstructionSimplify.cpp
    M llvm/test/Transforms/InstSimplify/select.ll

  Log Message:
  -----------
  [InstSimplify] enhance simplifyWithOpReplaced() to allow more 'select' removal

This is a generalization of a suggestion from issue #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" on the false arm binop and the
original "Op" to be replaced 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/undef propagation:
https://alive2.llvm.org/ce/z/Sz5K-c

Differential Revision: https://reviews.llvm.org/D144493




More information about the All-commits mailing list