llvm-project
c596d30c - [InstSimplify] simplify `(x+C1)/C2 <= x` when `C1 < C2` (#246898)

Commit
2 days ago
[InstSimplify] simplify `(x+C1)/C2 <= x` when `C1 < C2` (#246898) The expression `(x+C1)/C2 <= x` is always true when `C1 < C2` ([alive2](https://alive2.llvm.org/ce/z/MFoBk8)). The `div_ceil` operation is an instance of the LHS, so this pattern naturally comes up when comparing the result of `div_ceil` with `x` or values known to be `>= x`. The original case I ran into (that currently does not eliminate the bounds check: https://godbolt.org/z/6hzzf6j9z) is: ```rust pub fn first_quarter(src: &[u8]) -> &[u8] { &src[..src.len().div_ceil(4)] } ``` The implementation is basically by analogy with the multiplication rule below.
Author
Parents
Loading