[llvm] [LV] Add vplan folds for (X - (X & Y)) -> (X & ~Y) (PR #226466)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 08:03:40 PDT 2026


david-arm wrote:

I think it comes down to IR like this:

```
define i64 @foo(i32 %a) {
  %shl = shl i32 %a, 6
  %or = or disjoint i32 %shl, 5
  %zext = zext i32 %or to i64
  %and = and i64 %zext, 31
  %res = sub i64 %and, %zext
  ret i64 %res
}
```

where instcombine transforms into:

```
define i64 @foo(i32 %a) {
  %shl = shl i32 %a, 6
  %or = or disjoint i32 %shl, 5
  %zext = zext i32 %or to i64
  %res = sub nsw i64 5, %zext
  ret i64 %res
}
```

It completely eliminates the `and`, presumably by pushing it through the `zext` and realising that the `shl` makes the `and` redundant?

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


More information about the llvm-commits mailing list