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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 06:57:51 PDT 2026


https://github.com/lukel97 commented:

Testing this out on SPEC, it looks like folding this early prevents InstCombine from constant folding away trip counts, e.g.

```c
void f(int *a, unsigned k) {
  unsigned n = (k << 6) + 5; // n % 64 == 5, known to InstCombine
  for (unsigned i = 0; i < n; i++)
    a[i] += 1;
}
// clang -O3 -march=x86-64-v3
```

This previously had the vector epilogue + scalar tail unrolled because their trip count was constant folded to one, but now with the new `and` form there's not enough information about the bits:

```
vector.ph:
  %0 = and i64 %wide.trip.count, 31
  %n.vec = sub i64 %wide.trip.count, %0
->
vector.ph:
  %0 = and i64 %wide.trip.count, -32
```

Not sure what the fix for this is yet

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


More information about the llvm-commits mailing list