[llvm] [VectorCombine] Combine adjacent loads feeding as shuffle operands (PR #213007)
Sushant Gokhale via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 01:13:33 PDT 2026
sushgokh wrote:
> An earlier PR addressing an `!invariant.group` issue, [[#212473](https://github.com/llvm/llvm-project/pull/212473)](#212473), was merged. However, nikic commented there, “I don't think preserving invariant.group here is incorrect.” Could we get a definitive clarification on whether preserving `!invariant.group` in that case is correct?
My take on this is: Langref says
```
tells the optimizer that every load and store to the same pointer operand can be assumed to load or store the same value
```
It doesnt mention about the value types. But I think it must.
Consider your modified repo(hypothetical)
```
define void @insert_store_invariant_group(ptr %p, i16 %x, ptr %t) {
%v = load <8 x i16>, ptr %p, align 2
%v1 = insertelement <8 x i16> %v, i16 %x, i32 1
store <8 x i16> %v1, ptr %p, align 2, !invariant.group !0
%k = load <8 x i16>, ptr %p, align 2, !invariant.group !0
store <8 x i16> %k, ptr %t, align 2
ret void
}
```
Now if its modified to
```
define void @insert_store_invariant_group(ptr %p, i16 %x, %t) {
%gep = getelementptr inbounds <8 x i16>, ptr %p, i32 0, i32 1
store i16 %x, ptr %gep, align 2, !invariant.group !0 ; stmt 1
%k = load <8 x i16>, ptr %p, align 2, !invariant.group !0 ; stmt 2
store <8 x i16> %k, ptr %t, align 2
ret void
}
```
Does it really matter if we have `!invariant.group` metadata on the stmt 1? Perhaps no because the value types for stmt 1 and 2 are entirely different. But because the langref says that values loaded/stored from the pointer must be same for an invariant group, I would prefer dropping it.
Does that make sense ?
https://github.com/llvm/llvm-project/pull/213007
More information about the llvm-commits
mailing list