[InstCombine] Discuss generalizing icmp eq/ne X, 0 to trunc X to i1 using KnownBits
Open
llvm:instcombine
missed-optimization
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
1. Previous State
InstCombine currently folds icmp ne (and X, 1), 0 to trunc X to i1 using strict syntactic pattern matching. It does not handle cases where the upper bits are known to be zero through other operations without an explicit and X, 1.
2. Purpose of Improvement
Generalize the conversion from icmp eq/ne X, 0 to trunc X to i1 (or not trunc) by utilizing KnownBits.
If Known.countMinLeadingZeros() >= BitWidth - 1 for X, all bits except the LSB are guaranteed to be zero. Therefore, comparing X with 0 is mathematically equivalent to truncating X to i1.
Is folding icmp ne X, 0 to trunc X to i1 using KnownBits desirable in InstCombine?
Contributor guide
Assessment
This issue has not been assessed yet.