Skip to content
Commit 2622b2f4 authored by Noah Goldstein's avatar Noah Goldstein
Browse files

[ValueTracking] Use `select` condition to help determine if `select` is non-zero

In `select c, x, y` the condition `c` dominates the resulting `x` or
`y` chosen by the `select`. This adds logic to `isKnownNonZero` to try
and use the `icmp` for the `c` condition to see if it implies the
select `x` or `y` are known non-zero.

For example in:
    ```
    %c = icmp ugt i8 %x, %C
    %r = select i1 %c, i8 %x, i8 %y
    ```
    The true arm of select `%x` is non-zero (when "returned" by the
    `select`) because `%c` being true implies `%x` is non-zero.

Alive2 Links (with `x {pred} C`):
    - EQ  iff `C != 0`:
        - https://alive2.llvm.org/ce/z/umLabn
    - NE  iff `C == 0`:
        - https://alive2.llvm.org/ce/z/DQvy8Y
    - UGT [always]:
        - https://alive2.llvm.org/ce/z/HBkjgQ
    - UGE iff `C != 0`:
        - https://alive2.llvm.org/ce/z/LDNifB
    - SGT iff `C s>= 0`:
        - https://alive2.llvm.org/ce/z/QzWDj3
    - SGE iff `C s> 0`:
        - https://alive2.llvm.org/ce/z/rR4g3D
    - SLT iff `C s<= 0`:
        - https://alive2.llvm.org/ce/z/uysayx
    - SLE iff `C s< 0`:
        - https://alive2.llvm.org/ce/z/2jYc7e

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D147900
parent 530bbc8f
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment