[llvm] [InstCombine] Add (A & B) - (A & ~B) --> B - (A ^ B) (PR #79717)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 08:50:35 PST 2024


nikic wrote:

> _Bytes = _Bytes & ~(_Align - 1); Is a common idiom for rounding up to the nearest alignment. Difference = Bytes & (_Align - 1) is used to get the modulo.
> 
> subtracting these values is useful if you want to know the difference if say, _Bytes were to be the size of a buffer for example.

`~(_Align - 1)` will become `-_Align` and your pattern will not match. If `_Align` is constant it will also not match.

Please don't invent hypothetical scenarios where it could apply -- provide positive proof where it *does* apply.

Besides, this pattern is not undef-safe. Your proof specified noundef, and if we drop it we get this: https://alive2.llvm.org/ce/z/-ajcoF It would be necessary to insert freeze instructions to make it correct.

Given that no real-world motivation was provided, I'm closing this.

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


More information about the llvm-commits mailing list