[llvm] Simplify `(a % b) lt/ge (b-1)` into `(a % b) eq/ne (b-1)` (PR #72504)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 8 01:39:16 PST 2023


nikic wrote:

> what is the difference between `Constant`, `ConstantInt`, and `APInt`?

`m_Constant` matches any constant, including constant expressions. `m_ConstantInt` matches only `iN` constants. `m_APInt` matches `iN` constant or `<M x iN>` constant vector where all elements are the same (splat).

> when to use them?

`m_Constant`: Don't. Use `m_ImmConstant` if you just want "any constant" and don't have to perform operations on it.

`m_ConstantInt`: Don't.

`m_APInt`: What you usually want if you want to perform some kind of check on the value.

> and what is the use of `m_OneUse`? why I need to check for OneUse?

Transforms should not create more instructions than were originally there. If all instructions in the pattern are OneUse, then all of them will be removed and replaced by the new ones. But if they are not OneUse, then you might keep both some of the old instructions and some new. You have to add enough OneUse checks to make sure instruction could does not increase.

In this case OneUse should not be necessary, as you are replacing one icmp with another icmp, so that the number of instructions will always stay the same.

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


More information about the llvm-commits mailing list