[PATCH] D147900: [ValueTracking] Use `select` condition to help determine if `select` is non-zero
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 9 17:15:14 PDT 2023
goldstein.w.n created this revision.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147900
Files:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Analysis/ValueTracking/select-known-non-zero.ll
llvm/test/Transforms/InstSimplify/compare.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147900.512053.patch
Type: text/x-patch
Size: 12231 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230410/914a36d6/attachment.bin>
More information about the llvm-commits
mailing list