[llvm] [VectorCombine] Drop invariant.group from scalarized stores (PR #212473)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 28 04:37:56 PDT 2026
https://github.com/ParkHanbum created https://github.com/llvm/llvm-project/pull/212473
!invariant.group is tied to a pointer SSA value, so it cannot be copied
from a vector store to a scalar store that uses a newly created GEP.
Drop the metadata after copying the remaining store metadata and update
the regression expectations.
Fixes https://github.com/llvm/llvm-project/issues/212472
>From bd0d4ac9e7d3c407e8f4538bfd083c2d1fbfe98b Mon Sep 17 00:00:00 2001
From: hanbeom <kese111 at gmail.com>
Date: Tue, 28 Jul 2026 19:31:36 +0900
Subject: [PATCH 1/2] Add scalarized-store invariant.group coverage
---
.../VectorCombine/load-insert-store.ll | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/llvm/test/Transforms/VectorCombine/load-insert-store.ll b/llvm/test/Transforms/VectorCombine/load-insert-store.ll
index 897b113c197cf..563880d8c73a5 100644
--- a/llvm/test/Transforms/VectorCombine/load-insert-store.ll
+++ b/llvm/test/Transforms/VectorCombine/load-insert-store.ll
@@ -30,6 +30,20 @@ entry:
ret void
}
+; Record the current propagation of !invariant.group from the vector store to
+; the scalar store, even though the latter uses a new GEP.
+define void @insert_store_invariant_group(ptr %p, i16 %x) {
+; CHECK-LABEL: @insert_store_invariant_group(
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds <8 x i16>, ptr [[P:%.*]], i32 0, i32 1
+; CHECK-NEXT: store i16 [[X:%.*]], ptr [[GEP]], align 2, !invariant.group [[META0:![0-9]+]]
+; CHECK-NEXT: ret void
+;
+ %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
+ ret void
+}
+
; To verify case when index is out of bounds
define void @insert_store_outofbounds(ptr %q, i16 zeroext %s) {
; CHECK-LABEL: @insert_store_outofbounds(
@@ -847,3 +861,7 @@ bb:
declare i32 @bar(i32, i1) readonly
declare double @llvm.log2.f64(double)
+
+; CHECK: [[META0]] = !{}
+
+!0 = !{}
>From b3775a2cc4a005a9f9deb6948d2045987780d5c8 Mon Sep 17 00:00:00 2001
From: hanbeom <kese111 at gmail.com>
Date: Tue, 28 Jul 2026 19:32:49 +0900
Subject: [PATCH 2/2] [VectorCombine] Drop invariant.group from scalarized
stores
!invariant.group is tied to a pointer SSA value, so it cannot be copied
from a vector store to a scalar store that uses a newly created GEP.
Drop the metadata after copying the remaining store metadata and update
the regression expectations.
Fixes #212472
---
llvm/lib/Transforms/Vectorize/VectorCombine.cpp | 3 +++
llvm/test/Transforms/VectorCombine/load-insert-store.ll | 8 +++-----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 726f564b1aad9..38bebefa3bc79 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -2009,6 +2009,9 @@ bool VectorCombine::foldSingleElementStore(Instruction &I) {
{ConstantInt::get(Idx->getType(), 0), Idx});
StoreInst *NSI = Builder.CreateStore(NewElement, GEP);
NSI->copyMetadata(*SI);
+ // !invariant.group is tied to the pointer SSA value and cannot be
+ // transferred from the vector store to a scalar store through a new GEP.
+ NSI->setMetadata(LLVMContext::MD_invariant_group, nullptr);
Align ScalarOpAlignment = computeAlignmentAfterScalarization(
std::max(SI->getAlign(), Load->getAlign()), NewElement->getType(), Idx,
*DL);
diff --git a/llvm/test/Transforms/VectorCombine/load-insert-store.ll b/llvm/test/Transforms/VectorCombine/load-insert-store.ll
index 563880d8c73a5..fd5e78db5fa9a 100644
--- a/llvm/test/Transforms/VectorCombine/load-insert-store.ll
+++ b/llvm/test/Transforms/VectorCombine/load-insert-store.ll
@@ -30,12 +30,12 @@ entry:
ret void
}
-; Record the current propagation of !invariant.group from the vector store to
-; the scalar store, even though the latter uses a new GEP.
+; !invariant.group is tied to the pointer SSA value. The scalar store uses a
+; new GEP and must not inherit the metadata from the vector store.
define void @insert_store_invariant_group(ptr %p, i16 %x) {
; CHECK-LABEL: @insert_store_invariant_group(
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds <8 x i16>, ptr [[P:%.*]], i32 0, i32 1
-; CHECK-NEXT: store i16 [[X:%.*]], ptr [[GEP]], align 2, !invariant.group [[META0:![0-9]+]]
+; CHECK-NEXT: store i16 [[X:%.*]], ptr [[GEP]], align 2
; CHECK-NEXT: ret void
;
%v = load <8 x i16>, ptr %p, align 2
@@ -862,6 +862,4 @@ bb:
declare i32 @bar(i32, i1) readonly
declare double @llvm.log2.f64(double)
-; CHECK: [[META0]] = !{}
-
!0 = !{}
More information about the llvm-commits
mailing list