[llvm-branch-commits] [llvm] [VectorCombine] Use shared memory metadata propagation (PR #243674)

Yonah Goldberg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Nov 18 01:13:35 PST 2026


https://github.com/YonahGoldberg updated https://github.com/llvm/llvm-project/pull/243674

>From 8255603c7d858e9a49e1c15f049d168a7da9544e Mon Sep 17 00:00:00 2001
From: Yonah Goldberg <ygoldberg at nvidia.com>
Date: Wed, 18 Nov 2026 01:04:22 +0000
Subject: [PATCH 1/2] [VectorCombine] Add memory metadata tests

---
 .../vector-combine/store.ll                   |  93 +++++++
 .../VectorCombine/RISCV/memory-metadata.ll    |  49 ++++
 .../VectorCombine/X86/memory-metadata.ll      |  76 ++++++
 .../VectorCombine/load-bitcast-metadata.ll    |  90 +++++++
 .../VectorCombine/memory-metadata.ll          | 250 ++++++++++++++++++
 5 files changed, 558 insertions(+)
 create mode 100644 llvm/test/DebugInfo/Generic/assignment-tracking/vector-combine/store.ll
 create mode 100644 llvm/test/Transforms/VectorCombine/RISCV/memory-metadata.ll
 create mode 100644 llvm/test/Transforms/VectorCombine/X86/memory-metadata.ll
 create mode 100644 llvm/test/Transforms/VectorCombine/load-bitcast-metadata.ll
 create mode 100644 llvm/test/Transforms/VectorCombine/memory-metadata.ll

diff --git a/llvm/test/DebugInfo/Generic/assignment-tracking/vector-combine/store.ll b/llvm/test/DebugInfo/Generic/assignment-tracking/vector-combine/store.ll
new file mode 100644
index 00000000000000..236d49eb4de57e
--- /dev/null
+++ b/llvm/test/DebugInfo/Generic/assignment-tracking/vector-combine/store.ll
@@ -0,0 +1,93 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -passes=vector-combine < %s | FileCheck %s
+
+declare void @init(ptr)
+declare void @observe(ptr)
+
+; The replacement scalar store stays linked to the original dbg.assign.
+define void @scalar_store(i8 %x) !dbg !6 {
+;
+; CHECK-LABEL: define void @scalar_store(
+; CHECK-SAME: i8 [[X:%.*]]) !dbg [[DBG4:![0-9]+]] {
+; CHECK-NEXT:    [[P:%.*]] = alloca <16 x i8>, align 16
+; CHECK-NEXT:    call void @init(ptr [[P]]), !dbg [[DBG7:![0-9]+]]
+; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 3, !dbg [[DBG7]]
+; CHECK-NEXT:    store i8 [[X]], ptr [[TMP1]], align 1, !dbg [[DBG7]], !DIAssignID [[DIASSIGNID8:![0-9]+]]
+; CHECK-NEXT:      #dbg_assign(<16 x i8> poison, [[META9:![0-9]+]], !DIExpression(), [[DIASSIGNID8]], ptr [[P]], !DIExpression(), [[DBG7]])
+; CHECK-NEXT:    call void @observe(ptr [[P]]), !dbg [[DBG7]]
+; CHECK-NEXT:    ret void, !dbg [[DBG7]]
+;
+  %p = alloca <16 x i8>, align 16
+  call void @init(ptr %p), !dbg !10
+  %v = load <16 x i8>, ptr %p, align 16, !dbg !10
+  %i = insertelement <16 x i8> %v, i8 %x, i32 3, !dbg !10
+  store <16 x i8> %i, ptr %p, align 16, !DIAssignID !0, !dbg !10
+    #dbg_assign(<16 x i8> %i, !11, !DIExpression(), !0, ptr %p, !DIExpression(), !10)
+  call void @observe(ptr %p), !dbg !10
+  ret void, !dbg !10
+}
+
+; Both replacement scalar stores share the original dbg.assign's assignment ID.
+define void @two_updates(i8 %x, i8 %y) !dbg !17 {
+;
+; CHECK-LABEL: define void @two_updates(
+; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) !dbg [[DBG14:![0-9]+]] {
+; CHECK-NEXT:    [[P:%.*]] = alloca <16 x i8>, align 16
+; CHECK-NEXT:    call void @init(ptr [[P]]), !dbg [[DBG15:![0-9]+]]
+; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 3, !dbg [[DBG15]]
+; CHECK-NEXT:    store i8 [[X]], ptr [[TMP1]], align 1, !dbg [[DBG15]], !DIAssignID [[DIASSIGNID16:![0-9]+]]
+; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 7, !dbg [[DBG15]]
+; CHECK-NEXT:    store i8 [[Y]], ptr [[TMP2]], align 1, !dbg [[DBG15]], !DIAssignID [[DIASSIGNID16]]
+; CHECK-NEXT:      #dbg_assign(<16 x i8> poison, [[META17:![0-9]+]], !DIExpression(), [[DIASSIGNID16]], ptr [[P]], !DIExpression(), [[DBG15]])
+; CHECK-NEXT:    call void @observe(ptr [[P]]), !dbg [[DBG15]]
+; CHECK-NEXT:    ret void, !dbg [[DBG15]]
+;
+  %p = alloca <16 x i8>, align 16
+  call void @init(ptr %p), !dbg !18
+  %v = load <16 x i8>, ptr %p, align 16, !dbg !18
+  %i = insertelement <16 x i8> %v, i8 %x, i32 3, !dbg !18
+  %j = insertelement <16 x i8> %i, i8 %y, i32 7, !dbg !18
+  store <16 x i8> %j, ptr %p, align 16, !DIAssignID !20, !dbg !18
+    #dbg_assign(<16 x i8> %j, !19, !DIExpression(), !20, ptr %p, !DIExpression(), !18)
+  call void @observe(ptr %p), !dbg !18
+  ret void, !dbg !18
+}
+!llvm.module.flags = !{!4, !5}
+!llvm.dbg.cu = !{!7}
+!0 = distinct !DIAssignID()
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
+!6 = distinct !DISubprogram(name: "scalar_store", scope: !8, file: !8, line: 1, type: !9, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !7)
+!7 = distinct !DICompileUnit(language: DW_LANG_C, file: !8, producer: "audit", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+!8 = !DIFile(filename: "audit.c", directory: "/")
+!9 = !DISubroutineType(types: !13)
+!10 = !DILocation(line: 2, column: 1, scope: !6)
+!11 = !DILocalVariable(name: "buffer", scope: !6, file: !8, line: 1, type: !12)
+!12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !14, size: 128, elements: !15)
+!13 = !{}
+!14 = !DIBasicType(name: "byte", size: 8, encoding: DW_ATE_unsigned_char)
+!15 = !{!16}
+!16 = !DISubrange(count: 16)
+
+!17 = distinct !DISubprogram(name: "two_updates", scope: !8, file: !8, line: 1, type: !9, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !7)
+!18 = !DILocation(line: 2, column: 1, scope: !17)
+!19 = !DILocalVariable(name: "buffer2", scope: !17, file: !8, line: 1, type: !12)
+!20 = distinct !DIAssignID()
+;.
+; CHECK: [[META2:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C, file: [[META3:![0-9]+]], producer: "audit", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+; CHECK: [[META3]] = !DIFile(filename: "{{.*}}audit.c", directory: {{.*}})
+; CHECK: [[DBG4]] = distinct !DISubprogram(name: "scalar_store", scope: [[META3]], file: [[META3]], line: 1, type: [[META5:![0-9]+]], scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META2]])
+; CHECK: [[META5]] = !DISubroutineType(types: [[META6:![0-9]+]])
+; CHECK: [[META6]] = !{}
+; CHECK: [[DBG7]] = !DILocation(line: 2, column: 1, scope: [[DBG4]])
+; CHECK: [[DIASSIGNID8]] = distinct !DIAssignID()
+; CHECK: [[META9]] = !DILocalVariable(name: "buffer", scope: [[DBG4]], file: [[META3]], line: 1, type: [[META10:![0-9]+]])
+; CHECK: [[META10]] = !DICompositeType(tag: DW_TAG_array_type, baseType: [[META11:![0-9]+]], size: 128, elements: [[META12:![0-9]+]])
+; CHECK: [[META11]] = !DIBasicType(name: "byte", size: 8, encoding: DW_ATE_unsigned_char)
+; CHECK: [[META12]] = !{[[META13:![0-9]+]]}
+; CHECK: [[META13]] = !DISubrange(count: 16)
+; CHECK: [[DBG14]] = distinct !DISubprogram(name: "two_updates", scope: [[META3]], file: [[META3]], line: 1, type: [[META5]], scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META2]])
+; CHECK: [[DBG15]] = !DILocation(line: 2, column: 1, scope: [[DBG14]])
+; CHECK: [[DIASSIGNID16]] = distinct !DIAssignID()
+; CHECK: [[META17]] = !DILocalVariable(name: "buffer2", scope: [[DBG14]], file: [[META3]], line: 1, type: [[META10]])
+;.
diff --git a/llvm/test/Transforms/VectorCombine/RISCV/memory-metadata.ll b/llvm/test/Transforms/VectorCombine/RISCV/memory-metadata.ll
new file mode 100644
index 00000000000000..3583f538688032
--- /dev/null
+++ b/llvm/test/Transforms/VectorCombine/RISCV/memory-metadata.ll
@@ -0,0 +1,49 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -passes=vector-combine -mtriple=riscv64 -mattr=+v < %s | FileCheck %s
+
+define <8 x i16> @vp_bitcast_fixed(ptr %p, i32 %evl) {
+;
+; CHECK-LABEL: define <8 x i16> @vp_bitcast_fixed(
+; CHECK-SAME: ptr [[P:%.*]], i32 [[EVL:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:    [[TMP1:%.*]] = mul nuw i32 [[EVL]], 2
+; CHECK-NEXT:    [[R:%.*]] = call <8 x i16> @llvm.vp.load.v8i16.p0(ptr align 4 [[P]], <8 x i1> splat (i1 true), i32 [[TMP1]])
+; CHECK-NEXT:    ret <8 x i16> [[R]]
+;
+  %v = call <4 x i32> @llvm.vp.load(ptr align 4 %p, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, i32 %evl), !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !range !11, !invariant.load !3
+  %r = bitcast <4 x i32> %v to <8 x i16>
+  ret <8 x i16> %r
+}
+
+define <vscale x 8 x i16> @vp_bitcast_scalable(ptr %p, i32 %evl) {
+;
+; CHECK-LABEL: define <vscale x 8 x i16> @vp_bitcast_scalable(
+; CHECK-SAME: ptr [[P:%.*]], i32 [[EVL:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:    [[TMP1:%.*]] = mul nuw i32 [[EVL]], 2
+; CHECK-NEXT:    [[R:%.*]] = call <vscale x 8 x i16> @llvm.vp.load.nxv8i16.p0(ptr align 4 [[P]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP1]])
+; CHECK-NEXT:    ret <vscale x 8 x i16> [[R]]
+;
+  %v = call <vscale x 4 x i32> @llvm.vp.load(ptr align 4 %p, <vscale x 4 x i1> splat (i1 true), i32 %evl), !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !range !11, !invariant.load !3
+  %r = bitcast <vscale x 4 x i32> %v to <vscale x 8 x i16>
+  ret <vscale x 8 x i16> %r
+}
+
+
+!0 = !{i32 1}
+!1 = !{i32 0, !2}
+!2 = !{!"nvvm.l1_eviction", !"last"}
+!3 = !{}
+!4 = !{!"original access"}
+!5 = !{!"test", !"tag"}
+!6 = !{i32 5, i32 6}
+!7 = !{!8}
+!8 = distinct !{!8, !9, !"scope"}
+!9 = distinct !{!9, i1 false, !"domain"}
+!10 = distinct !{}
+!11 = !{i32 0, i32 100}
+!12 = !{i32 3}
+!13 = !{float 2.5}
+!14 = !{i64 0, i64 4, !15, i64 4, i64 4, !15, i64 8, i64 4, !15, i64 12, i64 4, !15}
+!15 = !{!16, !16, i64 0}
+!16 = !{!"omnipotent char", !17, i64 0}
+!17 = !{!"root"}
+!18 = !{i32 1, !2}
diff --git a/llvm/test/Transforms/VectorCombine/X86/memory-metadata.ll b/llvm/test/Transforms/VectorCombine/X86/memory-metadata.ll
new file mode 100644
index 00000000000000..3226bcf5ca668d
--- /dev/null
+++ b/llvm/test/Transforms/VectorCombine/X86/memory-metadata.ll
@@ -0,0 +1,76 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -passes=vector-combine -mtriple=x86_64-unknown-linux-gnu -mcpu=x86-64 < %s | FileCheck %s
+
+define <4 x float> @widen_scalar(ptr align 16 dereferenceable(16) %p) {
+;
+; CHECK-LABEL: define <4 x float> @widen_scalar(
+; CHECK-SAME: ptr align 16 dereferenceable(16) [[P:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:    [[R:%.*]] = load <4 x float>, ptr [[P]], align 16
+; CHECK-NEXT:    ret <4 x float> [[R]]
+;
+  %v = load float, ptr %p, align 4, !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !nofpclass !12, !fpmath !13, !noundef !3, !invariant.load !3, !invariant.group !3, !tbaa !15
+  %r = insertelement <4 x float> poison, float %v, i32 0
+  ret <4 x float> %r
+}
+
+define <4 x float> @widen_shifted_scalar(ptr align 16 dereferenceable(16) %p) {
+;
+; CHECK-LABEL: define <4 x float> @widen_shifted_scalar(
+; CHECK-SAME: ptr align 16 dereferenceable(16) [[P:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:    [[TMP1:%.*]] = load <4 x float>, ptr [[P]], align 16
+; CHECK-NEXT:    [[R:%.*]] = shufflevector <4 x float> [[TMP1]], <4 x float> poison, <4 x i32> <i32 3, i32 poison, i32 poison, i32 poison>
+; CHECK-NEXT:    ret <4 x float> [[R]]
+;
+  %q = getelementptr inbounds float, ptr %p, i64 3
+  %v = load float, ptr %q, align 4, !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !nofpclass !12, !fpmath !13, !noundef !3, !invariant.load !3, !invariant.group !3, !tbaa !15
+  %r = insertelement <4 x float> poison, float %v, i32 0
+  ret <4 x float> %r
+}
+
+define <4 x i32> @widen_subvector(ptr align 16 dereferenceable(16) %p) {
+;
+; CHECK-LABEL: define <4 x i32> @widen_subvector(
+; CHECK-SAME: ptr align 16 dereferenceable(16) [[P:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:    [[R:%.*]] = load <4 x i32>, ptr [[P]], align 16
+; CHECK-NEXT:    ret <4 x i32> [[R]]
+;
+  %v = load <2 x i32>, ptr %p, align 4, !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !range !11, !noundef !3, !invariant.load !3, !invariant.group !3, !tbaa !15
+  %r = shufflevector <2 x i32> %v, <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
+  ret <4 x i32> %r
+}
+
+
+; The load-insert fold can also shrink a load. Facts about all original
+; elements remain valid for this subset.
+define <4 x i32> @shrink_load_insert(ptr align 16 dereferenceable(32) %p) {
+;
+; CHECK-LABEL: define <4 x i32> @shrink_load_insert(
+; CHECK-SAME: ptr align 16 dereferenceable(32) [[P:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:    [[R:%.*]] = load <4 x i32>, ptr [[P]], align 16
+; CHECK-NEXT:    ret <4 x i32> [[R]]
+;
+  %v = load <8 x i32>, ptr %p, align 16, !nontemporal !0, !mem.cache_hint !1, !range !11, !noundef !3, !invariant.load !3, !alias.scope !7
+  %e = extractelement <8 x i32> %v, i32 0
+  %r = insertelement <4 x i32> poison, i32 %e, i32 0
+  ret <4 x i32> %r
+}
+
+!0 = !{i32 1}
+!1 = !{i32 0, !2}
+!2 = !{!"nvvm.l1_eviction", !"last"}
+!3 = !{}
+!4 = !{!"original access"}
+!5 = !{!"test", !"tag"}
+!6 = !{i32 5, i32 6}
+!7 = !{!8}
+!8 = distinct !{!8, !9, !"scope"}
+!9 = distinct !{!9, i1 false, !"domain"}
+!10 = distinct !{}
+!11 = !{i32 0, i32 100}
+!12 = !{i32 3}
+!13 = !{float 2.5}
+!14 = !{i64 0, i64 4, !15, i64 4, i64 4, !15, i64 8, i64 4, !15, i64 12, i64 4, !15}
+!15 = !{!16, !16, i64 0}
+!16 = !{!"omnipotent char", !17, i64 0}
+!17 = !{!"root"}
+!18 = !{i32 1, !2}
diff --git a/llvm/test/Transforms/VectorCombine/load-bitcast-metadata.ll b/llvm/test/Transforms/VectorCombine/load-bitcast-metadata.ll
new file mode 100644
index 00000000000000..f08435fab24fec
--- /dev/null
+++ b/llvm/test/Transforms/VectorCombine/load-bitcast-metadata.ll
@@ -0,0 +1,90 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; Verification is disabled only to record invalid metadata produced before the fix.
+; RUN: opt -disable-verify -S -passes=vector-combine -data-layout=e-p:64:64 < %s | FileCheck %s
+; RUN: opt -disable-verify -S -passes=instcombine -data-layout=e-p:64:64 < %s | FileCheck %s --check-prefix=IC
+; RUN: opt -disable-verify -S -passes=vector-combine -data-layout=E-p:64:64 < %s | FileCheck %s
+
+; The old element range does not describe the reinterpreted i32 value.
+define i32 @bitcast_integer_range(ptr %p) {
+;
+; CHECK-LABEL: define i32 @bitcast_integer_range(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[P]], align 4, !range [[RNG0:![0-9]+]], !nontemporal [[META1:![0-9]+]], !noundef [[META2:![0-9]+]], !annotation [[META3:![0-9]+]], !nosanitize [[META2]], !mmra [[META4:![0-9]+]], !mem.cache_hint [[META5:![0-9]+]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+; IC-LABEL: define i32 @bitcast_integer_range(
+; IC-SAME: ptr [[P:%.*]]) {
+; IC-NEXT:    [[V1:%.*]] = load i32, ptr [[P]], align 4, !nontemporal [[META0:![0-9]+]], !noundef [[META1:![0-9]+]], !annotation [[META2:![0-9]+]], !nosanitize [[META1]], !mmra [[META3:![0-9]+]], !mem.cache_hint [[META4:![0-9]+]]
+; IC-NEXT:    ret i32 [[V1]]
+;
+  %v = load <4 x i8>, ptr %p, align 4, !range !0, !noundef !1, !nontemporal !2, !mem.cache_hint !3, !annotation !5, !nosanitize !1, !mmra !8
+  %r = bitcast <4 x i8> %v to i32
+  ret i32 %r
+}
+
+; Floating-point value metadata must not be attached to an integer load.
+define i64 @bitcast_float_to_integer(ptr %p) {
+;
+; CHECK-LABEL: define i64 @bitcast_float_to_integer(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[R:%.*]] = load i64, ptr [[P]], align 8, !fpmath [[META7:![0-9]+]], !invariant.load [[META2]], !invariant.group [[META2]], !noundef [[META2]], !nofpclass [[META8:![0-9]+]]
+; CHECK-NEXT:    ret i64 [[R]]
+;
+; IC-LABEL: define i64 @bitcast_float_to_integer(
+; IC-SAME: ptr [[P:%.*]]) {
+; IC-NEXT:    [[V1:%.*]] = load i64, ptr [[P]], align 8, !invariant.load [[META1]], !invariant.group [[META1]], !noundef [[META1]]
+; IC-NEXT:    ret i64 [[V1]]
+;
+  %v = load <2 x float>, ptr %p, align 8, !nofpclass !6, !fpmath !7, !noundef !1, !invariant.load !1, !invariant.group !1
+  %r = bitcast <2 x float> %v to i64
+  ret i64 %r
+}
+
+; A single-element vector and its scalar have the same element facts.
+define float @bitcast_same_float_element(ptr %p) {
+;
+; CHECK-LABEL: define float @bitcast_same_float_element(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[R:%.*]] = load float, ptr [[P]], align 4, !fpmath [[META7]], !invariant.load [[META2]], !invariant.group [[META2]], !noundef [[META2]], !nofpclass [[META8]]
+; CHECK-NEXT:    ret float [[R]]
+;
+; IC-LABEL: define float @bitcast_same_float_element(
+; IC-SAME: ptr [[P:%.*]]) {
+; IC-NEXT:    [[V1:%.*]] = load float, ptr [[P]], align 4, !fpmath [[META6:![0-9]+]], !invariant.load [[META1]], !invariant.group [[META1]], !noundef [[META1]], !nofpclass [[META7:![0-9]+]]
+; IC-NEXT:    ret float [[V1]]
+;
+  %v = load <1 x float>, ptr %p, align 4, !nofpclass !6, !fpmath !7, !noundef !1, !invariant.load !1, !invariant.group !1
+  %r = bitcast <1 x float> %v to float
+  ret float %r
+}
+
+!0 = !{i8 0, i8 100}
+!1 = !{}
+!2 = !{i32 1}
+!3 = !{i32 0, !4}
+!4 = !{!"nvvm.l1_eviction", !"last"}
+!5 = !{!"original access"}
+!6 = !{i32 3}
+!7 = !{float 2.5}
+
+!8 = !{!"test", !"tag"}
+;.
+; CHECK: [[RNG0]] = !{i8 0, i8 100}
+; CHECK: [[META1]] = !{i32 1}
+; CHECK: [[META2]] = !{}
+; CHECK: [[META3]] = !{!"original access"}
+; CHECK: [[META4]] = !{!"test", !"tag"}
+; CHECK: [[META5]] = !{i32 0, [[META6:![0-9]+]]}
+; CHECK: [[META6]] = !{!"nvvm.l1_eviction", !"last"}
+; CHECK: [[META7]] = !{float 2.500000e+00}
+; CHECK: [[META8]] = !{i32 3}
+;.
+; IC: [[META0]] = !{i32 1}
+; IC: [[META1]] = !{}
+; IC: [[META2]] = !{!"original access"}
+; IC: [[META3]] = !{!"test", !"tag"}
+; IC: [[META4]] = !{i32 0, [[META5:![0-9]+]]}
+; IC: [[META5]] = !{!"nvvm.l1_eviction", !"last"}
+; IC: [[META6]] = !{float 2.500000e+00}
+; IC: [[META7]] = !{i32 3}
+;.
diff --git a/llvm/test/Transforms/VectorCombine/memory-metadata.ll b/llvm/test/Transforms/VectorCombine/memory-metadata.ll
new file mode 100644
index 00000000000000..6d34a04f0d4032
--- /dev/null
+++ b/llvm/test/Transforms/VectorCombine/memory-metadata.ll
@@ -0,0 +1,250 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; Verification is disabled only to record invalid metadata produced before the fix.
+; RUN: opt -disable-verify -S -passes=vector-combine -data-layout=e-p:64:64 < %s | FileCheck %s --implicit-check-not=!test.unknown
+; RUN: opt -disable-verify -S -passes=vector-combine -data-layout=E-p:64:64 < %s | FileCheck %s --implicit-check-not=!test.unknown
+
+define i32 @extract_zero(ptr %p) {
+;
+; CHECK-LABEL: define i32 @extract_zero(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[P]], align 16, !tbaa [[CHAR_TBAA0:![0-9]+]], !alias.scope [[META3:![0-9]+]], !noalias [[META3]], !noalias.addrspace [[META6:![0-9]+]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %v = load <4 x i32>, ptr %p, align 16, !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !range !11, !noundef !3, !invariant.load !3, !invariant.group !3, !tbaa.struct !14
+  %r = extractelement <4 x i32> %v, i32 0
+  ret i32 %r
+}
+
+define i32 @extract_nonzero(ptr %p) {
+;
+; CHECK-LABEL: define i32 @extract_nonzero(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 8
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[TMP1]], align 8, !tbaa [[CHAR_TBAA0]], !alias.scope [[META3]], !noalias [[META3]], !noalias.addrspace [[META6]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %v = load <4 x i32>, ptr %p, align 16, !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !range !11, !noundef !3, !invariant.load !3, !invariant.group !3, !tbaa.struct !14
+  %r = extractelement <4 x i32> %v, i32 2
+  ret i32 %r
+}
+
+define i32 @extract_dynamic(ptr %p, i32 %index) {
+;
+; CHECK-LABEL: define i32 @extract_dynamic(
+; CHECK-SAME: ptr [[P:%.*]], i32 [[INDEX:%.*]]) {
+; CHECK-NEXT:    [[INDEX_FROZEN:%.*]] = freeze i32 [[INDEX]]
+; CHECK-NEXT:    [[IDX:%.*]] = and i32 [[INDEX_FROZEN]], 3
+; CHECK-NEXT:    [[IDX_GEPIDX:%.*]] = zext i32 [[IDX]] to i64
+; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds [4 x i8], ptr [[P]], i64 [[IDX_GEPIDX]]
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[TMP1]], align 4
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %idx = and i32 %index, 3
+  %v = load <4 x i32>, ptr %p, align 16, !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !range !11, !noundef !3, !invariant.load !3, !invariant.group !3, !tbaa.struct !14, !tbaa !15
+  %r = extractelement <4 x i32> %v, i32 %idx
+  ret i32 %r
+}
+
+define float @extract_float(ptr %p) {
+;
+; CHECK-LABEL: define float @extract_float(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 4
+; CHECK-NEXT:    [[R:%.*]] = load float, ptr [[TMP1]], align 4, !alias.scope [[META3]], !noalias [[META3]], !noalias.addrspace [[META6]]
+; CHECK-NEXT:    ret float [[R]]
+;
+  %v = load <4 x float>, ptr %p, align 16, !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !nofpclass !12, !fpmath !13, !noundef !3, !invariant.load !3, !invariant.group !3
+  %r = extractelement <4 x float> %v, i32 1
+  ret float %r
+}
+
+define <4 x i32> @shrink_integer(ptr %p) {
+;
+; CHECK-LABEL: define <4 x i32> @shrink_integer(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x i32>, ptr [[P]], align 32, !tbaa [[CHAR_TBAA0]], !range [[RNG7:![0-9]+]], !invariant.load [[META8:![0-9]+]], !alias.scope [[META3]], !noalias [[META3]], !nontemporal [[META9:![0-9]+]], !invariant.group [[META8]], !llvm.access.group [[ACC_GRP10:![0-9]+]], !noundef [[META8]], !annotation [[META11:![0-9]+]], !nosanitize [[META8]], !mmra [[META12:![0-9]+]], !noalias.addrspace [[META6]], !mem.cache_hint [[META13:![0-9]+]]
+; CHECK-NEXT:    [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
+; CHECK-NEXT:    ret <4 x i32> [[R]]
+;
+  %v = load <8 x i32>, ptr %p, align 32, !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !range !11, !noundef !3, !invariant.load !3, !invariant.group !3, !tbaa !15
+  %r = shufflevector <8 x i32> %v, <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
+  ret <4 x i32> %r
+}
+
+define <4 x float> @shrink_float(ptr %p) {
+;
+; CHECK-LABEL: define <4 x float> @shrink_float(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x float>, ptr [[P]], align 32, !fpmath [[META15:![0-9]+]], !invariant.load [[META8]], !alias.scope [[META3]], !noalias [[META3]], !nontemporal [[META9]], !invariant.group [[META8]], !llvm.access.group [[ACC_GRP10]], !noundef [[META8]], !annotation [[META11]], !nosanitize [[META8]], !mmra [[META12]], !noalias.addrspace [[META6]], !nofpclass [[META16:![0-9]+]], !mem.cache_hint [[META13]]
+; CHECK-NEXT:    [[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
+; CHECK-NEXT:    ret <4 x float> [[R]]
+;
+  %v = load <8 x float>, ptr %p, align 32, !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !nofpclass !12, !fpmath !13, !noundef !3, !invariant.load !3, !invariant.group !3
+  %r = shufflevector <8 x float> %v, <8 x float> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
+  ret <4 x float> %r
+}
+
+define void @store_zero(ptr %p, i8 %x, i32 %index) {
+;
+; CHECK-LABEL: define void @store_zero(
+; CHECK-SAME: ptr [[P:%.*]], i8 [[X:%.*]], i32 [[INDEX:%.*]]) {
+; CHECK-NEXT:    store i8 [[X]], ptr [[P]], align 16, !tbaa.struct [[TBAA_STRUCT17:![0-9]+]], !alias.scope [[META3]], !noalias [[META3]], !nontemporal [[META9]], !llvm.access.group [[ACC_GRP10]], !annotation [[META11]], !nosanitize [[META8]], !mmra [[META12]], !noalias.addrspace [[META6]], !mem.cache_hint [[META18:![0-9]+]]
+; CHECK-NEXT:    ret void
+;
+  %v = load <16 x i8>, ptr %p, align 16
+  %i = insertelement <16 x i8> %v, i8 %x, i32 0
+  store <16 x i8> %i, ptr %p, align 16, !nontemporal !0, !mem.cache_hint !18, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !invariant.group !3, !tbaa.struct !14
+  ret void
+}
+
+define void @store_nonzero(ptr %p, i8 %x, i32 %index) {
+;
+; CHECK-LABEL: define void @store_nonzero(
+; CHECK-SAME: ptr [[P:%.*]], i8 [[X:%.*]], i32 [[INDEX:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 3
+; CHECK-NEXT:    store i8 [[X]], ptr [[TMP1]], align 1, !tbaa.struct [[TBAA_STRUCT17]], !alias.scope [[META3]], !noalias [[META3]], !nontemporal [[META9]], !llvm.access.group [[ACC_GRP10]], !annotation [[META11]], !nosanitize [[META8]], !mmra [[META12]], !noalias.addrspace [[META6]], !mem.cache_hint [[META18]]
+; CHECK-NEXT:    ret void
+;
+  %v = load <16 x i8>, ptr %p, align 16
+  %i = insertelement <16 x i8> %v, i8 %x, i32 3
+  store <16 x i8> %i, ptr %p, align 16, !nontemporal !0, !mem.cache_hint !18, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !invariant.group !3, !tbaa.struct !14
+  ret void
+}
+
+define void @store_dynamic(ptr %p, i8 %x, i32 %index) {
+;
+; CHECK-LABEL: define void @store_dynamic(
+; CHECK-SAME: ptr [[P:%.*]], i8 [[X:%.*]], i32 [[INDEX:%.*]]) {
+; CHECK-NEXT:    [[INDEX_FROZEN:%.*]] = freeze i32 [[INDEX]]
+; CHECK-NEXT:    [[IDX:%.*]] = and i32 [[INDEX_FROZEN]], 15
+; CHECK-NEXT:    [[IDX_GEPIDX:%.*]] = zext i32 [[IDX]] to i64
+; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[IDX_GEPIDX]]
+; CHECK-NEXT:    store i8 [[X]], ptr [[TMP1]], align 1, !tbaa.struct [[TBAA_STRUCT17]], !alias.scope [[META3]], !noalias [[META3]], !nontemporal [[META9]], !llvm.access.group [[ACC_GRP10]], !annotation [[META11]], !nosanitize [[META8]], !mmra [[META12]], !noalias.addrspace [[META6]], !mem.cache_hint [[META18]]
+; CHECK-NEXT:    ret void
+;
+  %idx = and i32 %index, 15
+  %v = load <16 x i8>, ptr %p, align 16
+  %i = insertelement <16 x i8> %v, i8 %x, i32 %idx
+  store <16 x i8> %i, ptr %p, align 16, !nontemporal !0, !mem.cache_hint !18, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !invariant.group !3, !tbaa.struct !14
+  ret void
+}
+
+
+; A known offset selects the corresponding field's alias tag.
+define i32 @extract_struct_field(ptr %p) {
+;
+; CHECK-LABEL: define i32 @extract_struct_field(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 4
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[TMP1]], align 4, !tbaa [[INT_TBAA19:![0-9]+]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %v = load <4 x i32>, ptr %p, align 16, !tbaa.struct !21
+  %r = extractelement <4 x i32> %v, i32 1
+  ret i32 %r
+}
+
+define void @store_struct_field(ptr %p, i32 %x) {
+;
+; CHECK-LABEL: define void @store_struct_field(
+; CHECK-SAME: ptr [[P:%.*]], i32 [[X:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 4
+; CHECK-NEXT:    store i32 [[X]], ptr [[TMP1]], align 4, !tbaa.struct [[TBAA_STRUCT21:![0-9]+]]
+; CHECK-NEXT:    ret void
+;
+  %v = load <4 x i32>, ptr %p, align 16
+  %i = insertelement <4 x i32> %v, i32 %x, i32 1
+  store <4 x i32> %i, ptr %p, align 16, !tbaa.struct !21
+  ret void
+}
+
+define void @scalar_store(ptr %p, i8 %x) {
+;
+; CHECK-LABEL: define void @scalar_store(
+; CHECK-SAME: ptr [[P:%.*]], i8 [[X:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 3
+; CHECK-NEXT:    store i8 [[X]], ptr [[TMP1]], align 1, !pcsections [[META22:![0-9]+]], !test.unknown [[META23:![0-9]+]]
+; CHECK-NEXT:    ret void
+;
+  %v = load <16 x i8>, ptr %p, align 16
+  %i = insertelement <16 x i8> %v, i8 %x, i32 3
+  store <16 x i8> %i, ptr %p, align 16, !pcsections !22, !test.unknown !23
+  ret void
+}
+
+define i32 @whole_bitcast(ptr %p) {
+;
+; CHECK-LABEL: define i32 @whole_bitcast(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[P]], align 4, !pcsections [[META22]], !test.unknown [[META23]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %v = load <4 x i8>, ptr %p, align 4, !pcsections !22, !test.unknown !23
+  %r = bitcast <4 x i8> %v to i32
+  ret i32 %r
+}
+
+define <4 x i32> @shrink_load(ptr %p) {
+;
+; CHECK-LABEL: define <4 x i32> @shrink_load(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x i32>, ptr [[P]], align 32, !pcsections [[META22]], !test.unknown [[META23]]
+; CHECK-NEXT:    [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
+; CHECK-NEXT:    ret <4 x i32> [[R]]
+;
+  %v = load <8 x i32>, ptr %p, align 32, !pcsections !22, !test.unknown !23
+  %r = shufflevector <8 x i32> %v, <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
+  ret <4 x i32> %r
+}
+
+!0 = !{i32 1}
+!1 = !{i32 0, !2}
+!2 = !{!"nvvm.l1_eviction", !"last"}
+!3 = !{}
+!4 = !{!"original access"}
+!5 = !{!"test", !"tag"}
+!6 = !{i32 5, i32 6}
+!7 = !{!8}
+!8 = distinct !{!8, !9, !"scope"}
+!9 = distinct !{!9, i1 false, !"domain"}
+!10 = distinct !{}
+!11 = !{i32 0, i32 100}
+!12 = !{i32 3}
+!13 = !{float 2.5}
+!14 = !{i64 0, i64 4, !15, i64 4, i64 4, !15, i64 8, i64 4, !15, i64 12, i64 4, !15}
+!15 = !{!16, !16, i64 0}
+!16 = !{!"omnipotent char", !17, i64 0}
+!17 = !{!"root"}
+!18 = !{i32 1, !2}
+
+!19 = !{!"int", !16, i64 0}
+!20 = !{!19, !19, i64 0}
+!21 = !{i64 0, i64 4, !15, i64 4, i64 4, !20, i64 8, i64 4, !15, i64 12, i64 4, !15}
+!22 = !{!"test_section"}
+!23 = !{!"custom annotation"}
+;.
+; CHECK: [[CHAR_TBAA0]] = !{[[META1:![0-9]+]], [[META1]], i64 0}
+; CHECK: [[META1]] = !{!"omnipotent char", [[META2:![0-9]+]], i64 0}
+; CHECK: [[META2]] = !{!"root"}
+; CHECK: [[META3]] = !{[[META4:![0-9]+]]}
+; CHECK: [[META4]] = distinct !{[[META4]], [[META5:![0-9]+]], !"scope"}
+; CHECK: [[META5]] = distinct !{[[META5]], i1 false, !"domain"}
+; CHECK: [[META6]] = !{i32 5, i32 6}
+; CHECK: [[RNG7]] = !{i32 0, i32 100}
+; CHECK: [[META8]] = !{}
+; CHECK: [[META9]] = !{i32 1}
+; CHECK: [[ACC_GRP10]] = distinct !{}
+; CHECK: [[META11]] = !{!"original access"}
+; CHECK: [[META12]] = !{!"test", !"tag"}
+; CHECK: [[META13]] = !{i32 0, [[META14:![0-9]+]]}
+; CHECK: [[META14]] = !{!"nvvm.l1_eviction", !"last"}
+; CHECK: [[META15]] = !{float 2.500000e+00}
+; CHECK: [[META16]] = !{i32 3}
+; CHECK: [[TBAA_STRUCT17]] = !{i64 0, i64 4, [[CHAR_TBAA0]], i64 4, i64 4, [[CHAR_TBAA0]], i64 8, i64 4, [[CHAR_TBAA0]], i64 12, i64 4, [[CHAR_TBAA0]]}
+; CHECK: [[META18]] = !{i32 1, [[META14]]}
+; CHECK: [[INT_TBAA19]] = !{[[META20:![0-9]+]], [[META20]], i64 0}
+; CHECK: [[META20]] = !{!"int", [[META1]], i64 0}
+; CHECK: [[TBAA_STRUCT21]] = !{i64 0, i64 4, [[CHAR_TBAA0]], i64 4, i64 4, [[INT_TBAA19]], i64 8, i64 4, [[CHAR_TBAA0]], i64 12, i64 4, [[CHAR_TBAA0]]}
+; CHECK: [[META22]] = !{!"test_section"}
+; CHECK: [[META23]] = !{!"custom annotation"}
+;.

>From fbd07dad5a9aa383dd3534bca2f69e20a5b40d5e Mon Sep 17 00:00:00 2001
From: Yonah Goldberg <ygoldberg at nvidia.com>
Date: Wed, 18 Nov 2026 01:04:29 +0000
Subject: [PATCH 2/2] [VectorCombine] Use shared memory metadata propagation

---
 .../Transforms/Vectorize/VectorCombine.cpp    | 48 ++++++++------
 .../VectorCombine/RISCV/memory-metadata.ll    | 17 ++++-
 .../VectorCombine/X86/memory-metadata.ll      | 17 +++--
 .../VectorCombine/load-bitcast-metadata.ll    | 30 ++++-----
 .../VectorCombine/memory-metadata.ll          | 64 +++++++++----------
 5 files changed, 99 insertions(+), 77 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index ffdef6fbb1e521..39c5f4d87780a1 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -24,6 +24,7 @@
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/InstSimplifyFolder.h"
 #include "llvm/Analysis/Loads.h"
+#include "llvm/Analysis/MetadataUtils.h"
 #include "llvm/Analysis/TargetFolder.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Analysis/ValueTracking.h"
@@ -359,7 +360,13 @@ bool VectorCombine::vectorizeLoadInsert(Instruction &I) {
   Builder.SetInsertPoint(Load);
   Value *CastedPtr =
       Builder.CreatePointerBitCastOrAddrSpaceCast(SrcPtr, Builder.getPtrTy(AS));
-  Value *VecLd = Builder.CreateAlignedLoad(MinVecTy, CastedPtr, Alignment);
+  auto *NewLoad = Builder.CreateAlignedLoad(MinVecTy, CastedPtr, Alignment);
+  copyMetadataForMemoryAccess(
+      *NewLoad, *Load,
+      SrcPtr == Load->getPointerOperand()->stripPointerCasts()
+          ? std::optional<int64_t>(0)
+          : -int64_t(OffsetEltIndex * (ScalarSize / 8)));
+  Value *VecLd = NewLoad;
   VecLd = Builder.CreateShuffleVector(VecLd, Mask);
 
   replaceValue(I, *VecLd);
@@ -424,7 +431,8 @@ bool VectorCombine::widenSubvectorLoad(Instruction &I) {
   Builder.SetInsertPoint(Load);
   Value *CastedPtr =
       Builder.CreatePointerBitCastOrAddrSpaceCast(SrcPtr, Builder.getPtrTy(AS));
-  Value *VecLd = Builder.CreateAlignedLoad(Ty, CastedPtr, Alignment);
+  auto *VecLd = Builder.CreateAlignedLoad(Ty, CastedPtr, Alignment);
+  copyMetadataForMemoryAccess(*VecLd, *Load);
   replaceValue(I, *VecLd);
   ++NumVecLoad;
   return true;
@@ -2136,11 +2144,14 @@ bool VectorCombine::foldInsertElementsToStores(Instruction &I) {
         {ConstantInt::get(GEPIdx->getType(), 0), GEPIdx});
 
     LastStore = Builder.CreateStore(InsertVal, GEP);
-    LastStore->copyMetadata(*SI);
-
-    // The new GEP may change the pointer operand, so !invariant.group cannot
-    // be transferred to the scalar store.
-    LastStore->setMetadata(LLVMContext::MD_invariant_group, nullptr);
+    std::optional<size_t> Offset;
+    if (auto *ConstIdx = dyn_cast<ConstantInt>(Idx))
+      Offset =
+          ConstIdx->getZExtValue() * DL->getTypeStoreSize(InsertVal->getType());
+    copyMetadataForMemoryAccess(*LastStore, *SI, Offset);
+    // Unchanged lanes remain in memory, so the original assignment still
+    // describes the whole vector after the replacement stores.
+    LastStore->copyMetadata(*SI, LLVMContext::MD_DIAssignID);
     Align ScalarOpAlignment = computeAlignmentAfterScalarization(
         std::max(SI->getAlign(), Load->getAlign()), InsertVal->getType(), Idx,
         *DL);
@@ -2307,11 +2318,10 @@ bool VectorCombine::scalarizeLoadExtract(LoadInst *LI, VectorType *VecTy,
         computeAlignmentAfterScalarization(LI->getAlign(), ElemType, Idx, *DL);
     NewLoad->setAlignment(ScalarOpAlignment);
 
-    if (auto *ConstIdx = dyn_cast<ConstantInt>(Idx)) {
-      size_t Offset = ConstIdx->getZExtValue() * DL->getTypeStoreSize(ElemType);
-      AAMDNodes OldAAMD = LI->getAAMetadata();
-      NewLoad->setAAMetadata(OldAAMD.adjustForAccess(Offset, ElemType, *DL));
-    }
+    std::optional<size_t> Offset;
+    if (auto *ConstIdx = dyn_cast<ConstantInt>(Idx))
+      Offset = ConstIdx->getZExtValue() * DL->getTypeStoreSize(ElemType);
+    copyMetadataForMemoryAccess(*NewLoad, *LI, Offset);
 
     replaceValue(*EI, *NewLoad, false);
   }
@@ -2378,7 +2388,7 @@ bool VectorCombine::scalarizeLoadBitcast(LoadInst *LI, VectorType *VecTy,
   auto *ScalarLoad =
       Builder.CreateLoad(TargetScalarType, Ptr, LI->getName() + ".scalar");
   ScalarLoad->setAlignment(LI->getAlign());
-  ScalarLoad->copyMetadata(*LI);
+  copyMetadataForMemoryAccess(*ScalarLoad, *LI);
 
   // Replace all bitcast users with the scalar load.
   for (User *U : LI->users()) {
@@ -6635,6 +6645,7 @@ bool VectorCombine::foldBitcastOfVPLoad(Instruction &I) {
   CallInst *NewVP = Builder.CreateIntrinsicWithoutFolding(
       NewVecTy, Intrinsic::vp_load,
       {II->getMemoryPointerParam(), NewMask, NewEVL});
+  copyMetadataForMemoryAccess(*NewVP, *II);
   // Preserve the original alignment.
   NewVP->addParamAttrs(
       0, AttrBuilder(II->getContext()).addAlignmentAttr(OrigAlign));
@@ -6891,7 +6902,7 @@ bool VectorCombine::shrinkLoadForShuffles(Instruction &I) {
       // Create new load of smaller vector.
       auto *NewLoad = cast<LoadInst>(
           Builder.CreateAlignedLoad(NewLoadTy, PtrOp, OldLoad->getAlign()));
-      NewLoad->copyMetadata(I);
+      copyMetadataForMemoryAccess(*NewLoad, *OldLoad);
 
       // Replace all uses.
       for (UseEntry &Use : NewUses) {
@@ -7083,13 +7094,8 @@ bool VectorCombine::foldShuffleOfAdjacentLoads(Instruction &I) {
   LoadInst *WideLoad = Builder.CreateAlignedLoad(
       WideTy, LowLoad->getPointerOperand(), LowLoad->getAlign());
 
-  // Set the metadata on the wide load. copyMetadataForLoad seeds it from
-  // LowLoad, then combineMetadataForCSE intersects every known kind against
-  // HighLoad (taking the most-generic value where applicable, keeping facts
-  // only where both loads agree, and dropping unknown metadata), so nothing is
-  // asserted over the combined load unless justified by both halves.
-  copyMetadataForLoad(*WideLoad, *LowLoad);
-  combineMetadataForCSE(WideLoad, HighLoad, /*DoesKMove=*/true);
+  // Merge metadata from both loads over the combined access.
+  propagateMetadata(WideLoad, {LowLoad, HighLoad});
 
   for (ShuffleVectorInst *SV : Shuffles) {
     SmallVector<int, 32> NewMask;
diff --git a/llvm/test/Transforms/VectorCombine/RISCV/memory-metadata.ll b/llvm/test/Transforms/VectorCombine/RISCV/memory-metadata.ll
index 3583f538688032..44f5d20414189d 100644
--- a/llvm/test/Transforms/VectorCombine/RISCV/memory-metadata.ll
+++ b/llvm/test/Transforms/VectorCombine/RISCV/memory-metadata.ll
@@ -6,7 +6,7 @@ define <8 x i16> @vp_bitcast_fixed(ptr %p, i32 %evl) {
 ; CHECK-LABEL: define <8 x i16> @vp_bitcast_fixed(
 ; CHECK-SAME: ptr [[P:%.*]], i32 [[EVL:%.*]]) #[[ATTR0:[0-9]+]] {
 ; CHECK-NEXT:    [[TMP1:%.*]] = mul nuw i32 [[EVL]], 2
-; CHECK-NEXT:    [[R:%.*]] = call <8 x i16> @llvm.vp.load.v8i16.p0(ptr align 4 [[P]], <8 x i1> splat (i1 true), i32 [[TMP1]])
+; CHECK-NEXT:    [[R:%.*]] = call <8 x i16> @llvm.vp.load.v8i16.p0(ptr align 4 [[P]], <8 x i1> splat (i1 true), i32 [[TMP1]]), !invariant.load [[META0:![0-9]+]], !alias.scope [[META1:![0-9]+]], !noalias [[META1]], !nontemporal [[META4:![0-9]+]], !llvm.access.group [[ACC_GRP5:![0-9]+]], !annotation [[META6:![0-9]+]], !nosanitize [[META0]], !mmra [[META7:![0-9]+]], !noalias.addrspace [[META8:![0-9]+]], !mem.cache_hint [[META9:![0-9]+]]
 ; CHECK-NEXT:    ret <8 x i16> [[R]]
 ;
   %v = call <4 x i32> @llvm.vp.load(ptr align 4 %p, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, i32 %evl), !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !range !11, !invariant.load !3
@@ -19,7 +19,7 @@ define <vscale x 8 x i16> @vp_bitcast_scalable(ptr %p, i32 %evl) {
 ; CHECK-LABEL: define <vscale x 8 x i16> @vp_bitcast_scalable(
 ; CHECK-SAME: ptr [[P:%.*]], i32 [[EVL:%.*]]) #[[ATTR0]] {
 ; CHECK-NEXT:    [[TMP1:%.*]] = mul nuw i32 [[EVL]], 2
-; CHECK-NEXT:    [[R:%.*]] = call <vscale x 8 x i16> @llvm.vp.load.nxv8i16.p0(ptr align 4 [[P]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP1]])
+; CHECK-NEXT:    [[R:%.*]] = call <vscale x 8 x i16> @llvm.vp.load.nxv8i16.p0(ptr align 4 [[P]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP1]]), !invariant.load [[META0]], !alias.scope [[META1]], !noalias [[META1]], !nontemporal [[META4]], !llvm.access.group [[ACC_GRP5]], !annotation [[META6]], !nosanitize [[META0]], !mmra [[META7]], !noalias.addrspace [[META8]], !mem.cache_hint [[META9]]
 ; CHECK-NEXT:    ret <vscale x 8 x i16> [[R]]
 ;
   %v = call <vscale x 4 x i32> @llvm.vp.load(ptr align 4 %p, <vscale x 4 x i1> splat (i1 true), i32 %evl), !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !range !11, !invariant.load !3
@@ -47,3 +47,16 @@ define <vscale x 8 x i16> @vp_bitcast_scalable(ptr %p, i32 %evl) {
 !16 = !{!"omnipotent char", !17, i64 0}
 !17 = !{!"root"}
 !18 = !{i32 1, !2}
+;.
+; CHECK: [[META0]] = !{}
+; CHECK: [[META1]] = !{[[META2:![0-9]+]]}
+; CHECK: [[META2]] = distinct !{[[META2]], [[META3:![0-9]+]], !"scope"}
+; CHECK: [[META3]] = distinct !{[[META3]], i1 false, !"domain"}
+; CHECK: [[META4]] = !{i32 1}
+; CHECK: [[ACC_GRP5]] = distinct !{}
+; CHECK: [[META6]] = !{!"original access"}
+; CHECK: [[META7]] = !{!"test", !"tag"}
+; CHECK: [[META8]] = !{i32 5, i32 6}
+; CHECK: [[META9]] = !{i32 0, [[META10:![0-9]+]]}
+; CHECK: [[META10]] = !{!"nvvm.l1_eviction", !"last"}
+;.
diff --git a/llvm/test/Transforms/VectorCombine/X86/memory-metadata.ll b/llvm/test/Transforms/VectorCombine/X86/memory-metadata.ll
index 3226bcf5ca668d..2731094f7507a2 100644
--- a/llvm/test/Transforms/VectorCombine/X86/memory-metadata.ll
+++ b/llvm/test/Transforms/VectorCombine/X86/memory-metadata.ll
@@ -5,7 +5,7 @@ define <4 x float> @widen_scalar(ptr align 16 dereferenceable(16) %p) {
 ;
 ; CHECK-LABEL: define <4 x float> @widen_scalar(
 ; CHECK-SAME: ptr align 16 dereferenceable(16) [[P:%.*]]) #[[ATTR0:[0-9]+]] {
-; CHECK-NEXT:    [[R:%.*]] = load <4 x float>, ptr [[P]], align 16
+; CHECK-NEXT:    [[R:%.*]] = load <4 x float>, ptr [[P]], align 16, !nontemporal [[META0:![0-9]+]], !annotation [[META1:![0-9]+]], !nosanitize [[META2:![0-9]+]], !mmra [[META3:![0-9]+]], !noalias.addrspace [[META4:![0-9]+]], !mem.cache_hint [[META5:![0-9]+]]
 ; CHECK-NEXT:    ret <4 x float> [[R]]
 ;
   %v = load float, ptr %p, align 4, !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !nofpclass !12, !fpmath !13, !noundef !3, !invariant.load !3, !invariant.group !3, !tbaa !15
@@ -17,7 +17,7 @@ define <4 x float> @widen_shifted_scalar(ptr align 16 dereferenceable(16) %p) {
 ;
 ; CHECK-LABEL: define <4 x float> @widen_shifted_scalar(
 ; CHECK-SAME: ptr align 16 dereferenceable(16) [[P:%.*]]) #[[ATTR0]] {
-; CHECK-NEXT:    [[TMP1:%.*]] = load <4 x float>, ptr [[P]], align 16
+; CHECK-NEXT:    [[TMP1:%.*]] = load <4 x float>, ptr [[P]], align 16, !nontemporal [[META0]], !annotation [[META1]], !nosanitize [[META2]], !mmra [[META3]], !noalias.addrspace [[META4]], !mem.cache_hint [[META5]]
 ; CHECK-NEXT:    [[R:%.*]] = shufflevector <4 x float> [[TMP1]], <4 x float> poison, <4 x i32> <i32 3, i32 poison, i32 poison, i32 poison>
 ; CHECK-NEXT:    ret <4 x float> [[R]]
 ;
@@ -31,7 +31,7 @@ define <4 x i32> @widen_subvector(ptr align 16 dereferenceable(16) %p) {
 ;
 ; CHECK-LABEL: define <4 x i32> @widen_subvector(
 ; CHECK-SAME: ptr align 16 dereferenceable(16) [[P:%.*]]) #[[ATTR0]] {
-; CHECK-NEXT:    [[R:%.*]] = load <4 x i32>, ptr [[P]], align 16
+; CHECK-NEXT:    [[R:%.*]] = load <4 x i32>, ptr [[P]], align 16, !nontemporal [[META0]], !annotation [[META1]], !nosanitize [[META2]], !mmra [[META3]], !noalias.addrspace [[META4]], !mem.cache_hint [[META5]]
 ; CHECK-NEXT:    ret <4 x i32> [[R]]
 ;
   %v = load <2 x i32>, ptr %p, align 4, !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !range !11, !noundef !3, !invariant.load !3, !invariant.group !3, !tbaa !15
@@ -46,7 +46,7 @@ define <4 x i32> @shrink_load_insert(ptr align 16 dereferenceable(32) %p) {
 ;
 ; CHECK-LABEL: define <4 x i32> @shrink_load_insert(
 ; CHECK-SAME: ptr align 16 dereferenceable(32) [[P:%.*]]) #[[ATTR0]] {
-; CHECK-NEXT:    [[R:%.*]] = load <4 x i32>, ptr [[P]], align 16
+; CHECK-NEXT:    [[R:%.*]] = load <4 x i32>, ptr [[P]], align 16, !nontemporal [[META0]], !mem.cache_hint [[META5]]
 ; CHECK-NEXT:    ret <4 x i32> [[R]]
 ;
   %v = load <8 x i32>, ptr %p, align 16, !nontemporal !0, !mem.cache_hint !1, !range !11, !noundef !3, !invariant.load !3, !alias.scope !7
@@ -74,3 +74,12 @@ define <4 x i32> @shrink_load_insert(ptr align 16 dereferenceable(32) %p) {
 !16 = !{!"omnipotent char", !17, i64 0}
 !17 = !{!"root"}
 !18 = !{i32 1, !2}
+;.
+; CHECK: [[META0]] = !{i32 1}
+; CHECK: [[META1]] = !{!"original access"}
+; CHECK: [[META2]] = !{}
+; CHECK: [[META3]] = !{!"test", !"tag"}
+; CHECK: [[META4]] = !{i32 5, i32 6}
+; CHECK: [[META5]] = !{i32 0, [[META6:![0-9]+]]}
+; CHECK: [[META6]] = !{!"nvvm.l1_eviction", !"last"}
+;.
diff --git a/llvm/test/Transforms/VectorCombine/load-bitcast-metadata.ll b/llvm/test/Transforms/VectorCombine/load-bitcast-metadata.ll
index f08435fab24fec..43939c341551e3 100644
--- a/llvm/test/Transforms/VectorCombine/load-bitcast-metadata.ll
+++ b/llvm/test/Transforms/VectorCombine/load-bitcast-metadata.ll
@@ -1,15 +1,14 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
-; Verification is disabled only to record invalid metadata produced before the fix.
-; RUN: opt -disable-verify -S -passes=vector-combine -data-layout=e-p:64:64 < %s | FileCheck %s
-; RUN: opt -disable-verify -S -passes=instcombine -data-layout=e-p:64:64 < %s | FileCheck %s --check-prefix=IC
-; RUN: opt -disable-verify -S -passes=vector-combine -data-layout=E-p:64:64 < %s | FileCheck %s
+; RUN: opt -S -passes=vector-combine -data-layout=e-p:64:64 < %s | FileCheck %s
+; RUN: opt -S -passes=instcombine -data-layout=e-p:64:64 < %s | FileCheck %s --check-prefix=IC
+; RUN: opt -S -passes=vector-combine -data-layout=E-p:64:64 < %s | FileCheck %s
 
 ; The old element range does not describe the reinterpreted i32 value.
 define i32 @bitcast_integer_range(ptr %p) {
 ;
 ; CHECK-LABEL: define i32 @bitcast_integer_range(
 ; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[P]], align 4, !range [[RNG0:![0-9]+]], !nontemporal [[META1:![0-9]+]], !noundef [[META2:![0-9]+]], !annotation [[META3:![0-9]+]], !nosanitize [[META2]], !mmra [[META4:![0-9]+]], !mem.cache_hint [[META5:![0-9]+]]
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[P]], align 4, !nontemporal [[META0:![0-9]+]], !noundef [[META1:![0-9]+]], !annotation [[META2:![0-9]+]], !nosanitize [[META1]], !mmra [[META3:![0-9]+]], !mem.cache_hint [[META4:![0-9]+]]
 ; CHECK-NEXT:    ret i32 [[R]]
 ;
 ; IC-LABEL: define i32 @bitcast_integer_range(
@@ -27,7 +26,7 @@ define i64 @bitcast_float_to_integer(ptr %p) {
 ;
 ; CHECK-LABEL: define i64 @bitcast_float_to_integer(
 ; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT:    [[R:%.*]] = load i64, ptr [[P]], align 8, !fpmath [[META7:![0-9]+]], !invariant.load [[META2]], !invariant.group [[META2]], !noundef [[META2]], !nofpclass [[META8:![0-9]+]]
+; CHECK-NEXT:    [[R:%.*]] = load i64, ptr [[P]], align 8, !invariant.load [[META1]], !invariant.group [[META1]], !noundef [[META1]]
 ; CHECK-NEXT:    ret i64 [[R]]
 ;
 ; IC-LABEL: define i64 @bitcast_float_to_integer(
@@ -45,7 +44,7 @@ define float @bitcast_same_float_element(ptr %p) {
 ;
 ; CHECK-LABEL: define float @bitcast_same_float_element(
 ; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT:    [[R:%.*]] = load float, ptr [[P]], align 4, !fpmath [[META7]], !invariant.load [[META2]], !invariant.group [[META2]], !noundef [[META2]], !nofpclass [[META8]]
+; CHECK-NEXT:    [[R:%.*]] = load float, ptr [[P]], align 4, !fpmath [[META6:![0-9]+]], !invariant.load [[META1]], !invariant.group [[META1]], !noundef [[META1]], !nofpclass [[META7:![0-9]+]]
 ; CHECK-NEXT:    ret float [[R]]
 ;
 ; IC-LABEL: define float @bitcast_same_float_element(
@@ -69,15 +68,14 @@ define float @bitcast_same_float_element(ptr %p) {
 
 !8 = !{!"test", !"tag"}
 ;.
-; CHECK: [[RNG0]] = !{i8 0, i8 100}
-; CHECK: [[META1]] = !{i32 1}
-; CHECK: [[META2]] = !{}
-; CHECK: [[META3]] = !{!"original access"}
-; CHECK: [[META4]] = !{!"test", !"tag"}
-; CHECK: [[META5]] = !{i32 0, [[META6:![0-9]+]]}
-; CHECK: [[META6]] = !{!"nvvm.l1_eviction", !"last"}
-; CHECK: [[META7]] = !{float 2.500000e+00}
-; CHECK: [[META8]] = !{i32 3}
+; CHECK: [[META0]] = !{i32 1}
+; CHECK: [[META1]] = !{}
+; CHECK: [[META2]] = !{!"original access"}
+; CHECK: [[META3]] = !{!"test", !"tag"}
+; CHECK: [[META4]] = !{i32 0, [[META5:![0-9]+]]}
+; CHECK: [[META5]] = !{!"nvvm.l1_eviction", !"last"}
+; CHECK: [[META6]] = !{float 2.500000e+00}
+; CHECK: [[META7]] = !{i32 3}
 ;.
 ; IC: [[META0]] = !{i32 1}
 ; IC: [[META1]] = !{}
diff --git a/llvm/test/Transforms/VectorCombine/memory-metadata.ll b/llvm/test/Transforms/VectorCombine/memory-metadata.ll
index 6d34a04f0d4032..1eaace7c4cee2d 100644
--- a/llvm/test/Transforms/VectorCombine/memory-metadata.ll
+++ b/llvm/test/Transforms/VectorCombine/memory-metadata.ll
@@ -1,13 +1,12 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
-; Verification is disabled only to record invalid metadata produced before the fix.
-; RUN: opt -disable-verify -S -passes=vector-combine -data-layout=e-p:64:64 < %s | FileCheck %s --implicit-check-not=!test.unknown
-; RUN: opt -disable-verify -S -passes=vector-combine -data-layout=E-p:64:64 < %s | FileCheck %s --implicit-check-not=!test.unknown
+; RUN: opt -S -passes=vector-combine -data-layout=e-p:64:64 < %s | FileCheck %s --implicit-check-not=!test.unknown
+; RUN: opt -S -passes=vector-combine -data-layout=E-p:64:64 < %s | FileCheck %s --implicit-check-not=!test.unknown
 
 define i32 @extract_zero(ptr %p) {
 ;
 ; CHECK-LABEL: define i32 @extract_zero(
 ; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[P]], align 16, !tbaa [[CHAR_TBAA0:![0-9]+]], !alias.scope [[META3:![0-9]+]], !noalias [[META3]], !noalias.addrspace [[META6:![0-9]+]]
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[P]], align 16, !tbaa [[CHAR_TBAA0:![0-9]+]], !range [[RNG3:![0-9]+]], !invariant.load [[META4:![0-9]+]], !alias.scope [[META5:![0-9]+]], !noalias [[META5]], !nontemporal [[META8:![0-9]+]], !invariant.group [[META4]], !llvm.access.group [[ACC_GRP9:![0-9]+]], !noundef [[META4]], !annotation [[META10:![0-9]+]], !nosanitize [[META4]], !mmra [[META11:![0-9]+]], !noalias.addrspace [[META12:![0-9]+]], !mem.cache_hint [[META13:![0-9]+]]
 ; CHECK-NEXT:    ret i32 [[R]]
 ;
   %v = load <4 x i32>, ptr %p, align 16, !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !range !11, !noundef !3, !invariant.load !3, !invariant.group !3, !tbaa.struct !14
@@ -20,7 +19,7 @@ define i32 @extract_nonzero(ptr %p) {
 ; CHECK-LABEL: define i32 @extract_nonzero(
 ; CHECK-SAME: ptr [[P:%.*]]) {
 ; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 8
-; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[TMP1]], align 8, !tbaa [[CHAR_TBAA0]], !alias.scope [[META3]], !noalias [[META3]], !noalias.addrspace [[META6]]
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[TMP1]], align 8, !tbaa [[CHAR_TBAA0]], !range [[RNG3]], !invariant.load [[META4]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.access.group [[ACC_GRP9]], !noundef [[META4]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META13]]
 ; CHECK-NEXT:    ret i32 [[R]]
 ;
   %v = load <4 x i32>, ptr %p, align 16, !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !range !11, !noundef !3, !invariant.load !3, !invariant.group !3, !tbaa.struct !14
@@ -36,7 +35,7 @@ define i32 @extract_dynamic(ptr %p, i32 %index) {
 ; CHECK-NEXT:    [[IDX:%.*]] = and i32 [[INDEX_FROZEN]], 3
 ; CHECK-NEXT:    [[IDX_GEPIDX:%.*]] = zext i32 [[IDX]] to i64
 ; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds [4 x i8], ptr [[P]], i64 [[IDX_GEPIDX]]
-; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[TMP1]], align 4
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[TMP1]], align 4, !tbaa [[CHAR_TBAA0]], !range [[RNG3]], !invariant.load [[META4]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.access.group [[ACC_GRP9]], !noundef [[META4]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META13]]
 ; CHECK-NEXT:    ret i32 [[R]]
 ;
   %idx = and i32 %index, 3
@@ -50,7 +49,7 @@ define float @extract_float(ptr %p) {
 ; CHECK-LABEL: define float @extract_float(
 ; CHECK-SAME: ptr [[P:%.*]]) {
 ; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 4
-; CHECK-NEXT:    [[R:%.*]] = load float, ptr [[TMP1]], align 4, !alias.scope [[META3]], !noalias [[META3]], !noalias.addrspace [[META6]]
+; CHECK-NEXT:    [[R:%.*]] = load float, ptr [[TMP1]], align 4, !fpmath [[META15:![0-9]+]], !invariant.load [[META4]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.access.group [[ACC_GRP9]], !noundef [[META4]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !nofpclass [[META16:![0-9]+]], !mem.cache_hint [[META13]]
 ; CHECK-NEXT:    ret float [[R]]
 ;
   %v = load <4 x float>, ptr %p, align 16, !nontemporal !0, !mem.cache_hint !1, !annotation !4, !nosanitize !3, !mmra !5, !noalias.addrspace !6, !alias.scope !7, !noalias !7, !llvm.access.group !10, !nofpclass !12, !fpmath !13, !noundef !3, !invariant.load !3, !invariant.group !3
@@ -62,7 +61,7 @@ define <4 x i32> @shrink_integer(ptr %p) {
 ;
 ; CHECK-LABEL: define <4 x i32> @shrink_integer(
 ; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x i32>, ptr [[P]], align 32, !tbaa [[CHAR_TBAA0]], !range [[RNG7:![0-9]+]], !invariant.load [[META8:![0-9]+]], !alias.scope [[META3]], !noalias [[META3]], !nontemporal [[META9:![0-9]+]], !invariant.group [[META8]], !llvm.access.group [[ACC_GRP10:![0-9]+]], !noundef [[META8]], !annotation [[META11:![0-9]+]], !nosanitize [[META8]], !mmra [[META12:![0-9]+]], !noalias.addrspace [[META6]], !mem.cache_hint [[META13:![0-9]+]]
+; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x i32>, ptr [[P]], align 32, !tbaa [[CHAR_TBAA0]], !range [[RNG3]], !invariant.load [[META4]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !invariant.group [[META4]], !llvm.access.group [[ACC_GRP9]], !noundef [[META4]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META13]]
 ; CHECK-NEXT:    [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
 ; CHECK-NEXT:    ret <4 x i32> [[R]]
 ;
@@ -75,7 +74,7 @@ define <4 x float> @shrink_float(ptr %p) {
 ;
 ; CHECK-LABEL: define <4 x float> @shrink_float(
 ; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x float>, ptr [[P]], align 32, !fpmath [[META15:![0-9]+]], !invariant.load [[META8]], !alias.scope [[META3]], !noalias [[META3]], !nontemporal [[META9]], !invariant.group [[META8]], !llvm.access.group [[ACC_GRP10]], !noundef [[META8]], !annotation [[META11]], !nosanitize [[META8]], !mmra [[META12]], !noalias.addrspace [[META6]], !nofpclass [[META16:![0-9]+]], !mem.cache_hint [[META13]]
+; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x float>, ptr [[P]], align 32, !fpmath [[META15]], !invariant.load [[META4]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !invariant.group [[META4]], !llvm.access.group [[ACC_GRP9]], !noundef [[META4]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !nofpclass [[META16]], !mem.cache_hint [[META13]]
 ; CHECK-NEXT:    [[R:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
 ; CHECK-NEXT:    ret <4 x float> [[R]]
 ;
@@ -88,7 +87,7 @@ define void @store_zero(ptr %p, i8 %x, i32 %index) {
 ;
 ; CHECK-LABEL: define void @store_zero(
 ; CHECK-SAME: ptr [[P:%.*]], i8 [[X:%.*]], i32 [[INDEX:%.*]]) {
-; CHECK-NEXT:    store i8 [[X]], ptr [[P]], align 16, !tbaa.struct [[TBAA_STRUCT17:![0-9]+]], !alias.scope [[META3]], !noalias [[META3]], !nontemporal [[META9]], !llvm.access.group [[ACC_GRP10]], !annotation [[META11]], !nosanitize [[META8]], !mmra [[META12]], !noalias.addrspace [[META6]], !mem.cache_hint [[META18:![0-9]+]]
+; CHECK-NEXT:    store i8 [[X]], ptr [[P]], align 16, !tbaa [[CHAR_TBAA0]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !invariant.group [[META4]], !llvm.access.group [[ACC_GRP9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META17:![0-9]+]]
 ; CHECK-NEXT:    ret void
 ;
   %v = load <16 x i8>, ptr %p, align 16
@@ -102,7 +101,7 @@ define void @store_nonzero(ptr %p, i8 %x, i32 %index) {
 ; CHECK-LABEL: define void @store_nonzero(
 ; CHECK-SAME: ptr [[P:%.*]], i8 [[X:%.*]], i32 [[INDEX:%.*]]) {
 ; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 3
-; CHECK-NEXT:    store i8 [[X]], ptr [[TMP1]], align 1, !tbaa.struct [[TBAA_STRUCT17]], !alias.scope [[META3]], !noalias [[META3]], !nontemporal [[META9]], !llvm.access.group [[ACC_GRP10]], !annotation [[META11]], !nosanitize [[META8]], !mmra [[META12]], !noalias.addrspace [[META6]], !mem.cache_hint [[META18]]
+; CHECK-NEXT:    store i8 [[X]], ptr [[TMP1]], align 1, !tbaa [[CHAR_TBAA0]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.access.group [[ACC_GRP9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META17]]
 ; CHECK-NEXT:    ret void
 ;
   %v = load <16 x i8>, ptr %p, align 16
@@ -119,7 +118,7 @@ define void @store_dynamic(ptr %p, i8 %x, i32 %index) {
 ; CHECK-NEXT:    [[IDX:%.*]] = and i32 [[INDEX_FROZEN]], 15
 ; CHECK-NEXT:    [[IDX_GEPIDX:%.*]] = zext i32 [[IDX]] to i64
 ; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[IDX_GEPIDX]]
-; CHECK-NEXT:    store i8 [[X]], ptr [[TMP1]], align 1, !tbaa.struct [[TBAA_STRUCT17]], !alias.scope [[META3]], !noalias [[META3]], !nontemporal [[META9]], !llvm.access.group [[ACC_GRP10]], !annotation [[META11]], !nosanitize [[META8]], !mmra [[META12]], !noalias.addrspace [[META6]], !mem.cache_hint [[META18]]
+; CHECK-NEXT:    store i8 [[X]], ptr [[TMP1]], align 1, !tbaa [[CHAR_TBAA0]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.access.group [[ACC_GRP9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META17]]
 ; CHECK-NEXT:    ret void
 ;
   %idx = and i32 %index, 15
@@ -136,7 +135,7 @@ define i32 @extract_struct_field(ptr %p) {
 ; CHECK-LABEL: define i32 @extract_struct_field(
 ; CHECK-SAME: ptr [[P:%.*]]) {
 ; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 4
-; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[TMP1]], align 4, !tbaa [[INT_TBAA19:![0-9]+]]
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[TMP1]], align 4, !tbaa [[INT_TBAA18:![0-9]+]]
 ; CHECK-NEXT:    ret i32 [[R]]
 ;
   %v = load <4 x i32>, ptr %p, align 16, !tbaa.struct !21
@@ -149,7 +148,7 @@ define void @store_struct_field(ptr %p, i32 %x) {
 ; CHECK-LABEL: define void @store_struct_field(
 ; CHECK-SAME: ptr [[P:%.*]], i32 [[X:%.*]]) {
 ; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 4
-; CHECK-NEXT:    store i32 [[X]], ptr [[TMP1]], align 4, !tbaa.struct [[TBAA_STRUCT21:![0-9]+]]
+; CHECK-NEXT:    store i32 [[X]], ptr [[TMP1]], align 4, !tbaa [[INT_TBAA18]]
 ; CHECK-NEXT:    ret void
 ;
   %v = load <4 x i32>, ptr %p, align 16
@@ -163,7 +162,7 @@ define void @scalar_store(ptr %p, i8 %x) {
 ; CHECK-LABEL: define void @scalar_store(
 ; CHECK-SAME: ptr [[P:%.*]], i8 [[X:%.*]]) {
 ; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 3
-; CHECK-NEXT:    store i8 [[X]], ptr [[TMP1]], align 1, !pcsections [[META22:![0-9]+]], !test.unknown [[META23:![0-9]+]]
+; CHECK-NEXT:    store i8 [[X]], ptr [[TMP1]], align 1, !pcsections [[META20:![0-9]+]]
 ; CHECK-NEXT:    ret void
 ;
   %v = load <16 x i8>, ptr %p, align 16
@@ -176,7 +175,7 @@ define i32 @whole_bitcast(ptr %p) {
 ;
 ; CHECK-LABEL: define i32 @whole_bitcast(
 ; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[P]], align 4, !pcsections [[META22]], !test.unknown [[META23]]
+; CHECK-NEXT:    [[R:%.*]] = load i32, ptr [[P]], align 4, !pcsections [[META20]]
 ; CHECK-NEXT:    ret i32 [[R]]
 ;
   %v = load <4 x i8>, ptr %p, align 4, !pcsections !22, !test.unknown !23
@@ -188,7 +187,7 @@ define <4 x i32> @shrink_load(ptr %p) {
 ;
 ; CHECK-LABEL: define <4 x i32> @shrink_load(
 ; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x i32>, ptr [[P]], align 32, !pcsections [[META22]], !test.unknown [[META23]]
+; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x i32>, ptr [[P]], align 32, !pcsections [[META20]]
 ; CHECK-NEXT:    [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
 ; CHECK-NEXT:    ret <4 x i32> [[R]]
 ;
@@ -226,25 +225,22 @@ define <4 x i32> @shrink_load(ptr %p) {
 ; CHECK: [[CHAR_TBAA0]] = !{[[META1:![0-9]+]], [[META1]], i64 0}
 ; CHECK: [[META1]] = !{!"omnipotent char", [[META2:![0-9]+]], i64 0}
 ; CHECK: [[META2]] = !{!"root"}
-; CHECK: [[META3]] = !{[[META4:![0-9]+]]}
-; CHECK: [[META4]] = distinct !{[[META4]], [[META5:![0-9]+]], !"scope"}
-; CHECK: [[META5]] = distinct !{[[META5]], i1 false, !"domain"}
-; CHECK: [[META6]] = !{i32 5, i32 6}
-; CHECK: [[RNG7]] = !{i32 0, i32 100}
-; CHECK: [[META8]] = !{}
-; CHECK: [[META9]] = !{i32 1}
-; CHECK: [[ACC_GRP10]] = distinct !{}
-; CHECK: [[META11]] = !{!"original access"}
-; CHECK: [[META12]] = !{!"test", !"tag"}
+; CHECK: [[RNG3]] = !{i32 0, i32 100}
+; CHECK: [[META4]] = !{}
+; CHECK: [[META5]] = !{[[META6:![0-9]+]]}
+; CHECK: [[META6]] = distinct !{[[META6]], [[META7:![0-9]+]], !"scope"}
+; CHECK: [[META7]] = distinct !{[[META7]], i1 false, !"domain"}
+; CHECK: [[META8]] = !{i32 1}
+; CHECK: [[ACC_GRP9]] = distinct !{}
+; CHECK: [[META10]] = !{!"original access"}
+; CHECK: [[META11]] = !{!"test", !"tag"}
+; CHECK: [[META12]] = !{i32 5, i32 6}
 ; CHECK: [[META13]] = !{i32 0, [[META14:![0-9]+]]}
 ; CHECK: [[META14]] = !{!"nvvm.l1_eviction", !"last"}
 ; CHECK: [[META15]] = !{float 2.500000e+00}
 ; CHECK: [[META16]] = !{i32 3}
-; CHECK: [[TBAA_STRUCT17]] = !{i64 0, i64 4, [[CHAR_TBAA0]], i64 4, i64 4, [[CHAR_TBAA0]], i64 8, i64 4, [[CHAR_TBAA0]], i64 12, i64 4, [[CHAR_TBAA0]]}
-; CHECK: [[META18]] = !{i32 1, [[META14]]}
-; CHECK: [[INT_TBAA19]] = !{[[META20:![0-9]+]], [[META20]], i64 0}
-; CHECK: [[META20]] = !{!"int", [[META1]], i64 0}
-; CHECK: [[TBAA_STRUCT21]] = !{i64 0, i64 4, [[CHAR_TBAA0]], i64 4, i64 4, [[INT_TBAA19]], i64 8, i64 4, [[CHAR_TBAA0]], i64 12, i64 4, [[CHAR_TBAA0]]}
-; CHECK: [[META22]] = !{!"test_section"}
-; CHECK: [[META23]] = !{!"custom annotation"}
+; CHECK: [[META17]] = !{i32 1, [[META14]]}
+; CHECK: [[INT_TBAA18]] = !{[[META19:![0-9]+]], [[META19]], i64 0}
+; CHECK: [[META19]] = !{!"int", [[META1]], i64 0}
+; CHECK: [[META20]] = !{!"test_section"}
 ;.



More information about the llvm-branch-commits mailing list