[llvm] Fold (a % b) lt/ge (b-1) where b is a power of 2 (PR #72504)

Joshua Cranmer via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 16 14:14:06 PST 2023


jcranmer-intel wrote:

> Can you explain further please, I think I don't understand the code very well.

The srem result of `x % n` is between `-(abs(n) - 1)` and `(abs(n) - 1)`, exclusive. This means that `(x % n) >= (n - 1)` can be converted into `(x % n) == (n - 1)` and `(x % n) < (n - 1)` can be converted into `(x % n) != (n - 1)`, respectively. We already have transformations that convert the `(x % n) ==/!= (n - 1)` to the equivalent and expressions when `n` is a power of 2.

https://github.com/llvm/llvm-project/pull/72504


More information about the llvm-commits mailing list