[llvm-branch-commits] [llvm] [InstCombine] Use shared memory metadata propagation (PR #243672)
Yonah Goldberg via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 18 01:13:37 PST 2026
https://github.com/YonahGoldberg updated https://github.com/llvm/llvm-project/pull/243672
>From 4b323dc3e822cb893b631049e191d154d3c266d7 Mon Sep 17 00:00:00 2001
From: Yonah Goldberg <ygoldberg at nvidia.com>
Date: Wed, 18 Nov 2026 01:01:55 +0000
Subject: [PATCH 1/2] [InstCombine] Add memory metadata tests
---
.../masked_intrinsics_keep_metadata.ll | 19 ++
.../InstCombine/memory-cache-hint.ll | 63 +++++
.../Transforms/InstCombine/memory-metadata.ll | 259 ++++++++++++++++++
.../InstCombine/ptr-replace-alloca.ll | 4 +-
.../InstCombine/storemerge-metadata.ll | 220 +++++++++++++++
5 files changed, 562 insertions(+), 3 deletions(-)
create mode 100644 llvm/test/Transforms/InstCombine/memory-cache-hint.ll
create mode 100644 llvm/test/Transforms/InstCombine/memory-metadata.ll
create mode 100644 llvm/test/Transforms/InstCombine/storemerge-metadata.ll
diff --git a/llvm/test/Transforms/InstCombine/masked_intrinsics_keep_metadata.ll b/llvm/test/Transforms/InstCombine/masked_intrinsics_keep_metadata.ll
index 0832561e2b02b5..e6029c7b58e73b 100644
--- a/llvm/test/Transforms/InstCombine/masked_intrinsics_keep_metadata.ll
+++ b/llvm/test/Transforms/InstCombine/masked_intrinsics_keep_metadata.ll
@@ -40,6 +40,20 @@ b0:
ret void
}
+; For an { i32, float } object, only the integer field is initially read.
+; TODO: Check whether the integer TBAA tag remains valid on the unmasked load,
+; which also reads the inactive float field. Record the existing behavior.
+define <2 x i32> @unmask_integer_field_tbaa(ptr dereferenceable(8) %p) {
+; CHECK-LABEL: define <2 x i32> @unmask_integer_field_tbaa(
+; CHECK-SAME: ptr dereferenceable(8) [[P:%.*]]) {
+; CHECK-NEXT: [[UNMASKEDLOAD:%.*]] = load <2 x i32>, ptr [[P]], align 1, !tbaa [[INT_TBAA3:![0-9]+]]
+; CHECK-NEXT: [[V1:%.*]] = insertelement <2 x i32> [[UNMASKEDLOAD]], i32 0, i64 1
+; CHECK-NEXT: ret <2 x i32> [[V1]]
+;
+ %v = call <2 x i32> @llvm.masked.load.v2i32.p0(ptr %p, <2 x i1> <i1 true, i1 false>, <2 x i32> zeroinitializer), !tbaa !3
+ ret <2 x i32> %v
+}
+
attributes #0 = { norecurse nounwind }
declare <4 x i32> @llvm.masked.load.v4i1.p0(ptr, i32, <4 x i1>, <4 x i32>)
@@ -49,8 +63,13 @@ declare void @llvm.masked.store.v4i1.p0(<4 x i32>, ptr, i32, <4 x i1>)
!1 = !{!"omnipotent char", !2, i64 0}
!2 = !{!"Simple C/C++ TBAA"}
+!3 = !{!4, !4, i64 0}
+!4 = !{!"int", !1, i64 0}
+
;.
; CHECK: [[CHAR_TBAA0]] = !{[[META1:![0-9]+]], [[META1]], i64 0}
; CHECK: [[META1]] = !{!"omnipotent char", [[META2:![0-9]+]], i64 0}
; CHECK: [[META2]] = !{!"Simple C/C++ TBAA"}
+; CHECK: [[INT_TBAA3]] = !{[[META4:![0-9]+]], [[META4]], i64 0}
+; CHECK: [[META4]] = !{!"int", [[META1]], i64 0}
;.
diff --git a/llvm/test/Transforms/InstCombine/memory-cache-hint.ll b/llvm/test/Transforms/InstCombine/memory-cache-hint.ll
new file mode 100644
index 00000000000000..d42093a7f35bb5
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/memory-cache-hint.ll
@@ -0,0 +1,63 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -passes=instcombine < %s | FileCheck %s
+
+define void @store_bitcast(ptr %p, float %x) {
+;
+; CHECK-LABEL: define void @store_bitcast(
+; CHECK-SAME: ptr [[P:%.*]], float [[X:%.*]]) {
+; CHECK-NEXT: store float [[X]], ptr [[P]], align 4
+; CHECK-NEXT: ret void
+;
+ %bits = bitcast float %x to i32
+ store i32 %bits, ptr %p, align 4, !mem.cache_hint !0
+ ret void
+}
+
+define void @copy_both_hints(ptr %dst, ptr %src) {
+;
+; CHECK-LABEL: define void @copy_both_hints(
+; CHECK-SAME: ptr [[DST:%.*]], ptr [[SRC:%.*]]) {
+; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[SRC]], align 4
+; CHECK-NEXT: store i32 [[TMP1]], ptr [[DST]], align 4
+; CHECK-NEXT: ret void
+;
+ call void @llvm.memcpy.p0.p0.i64(ptr align 4 %dst, ptr align 4 %src, i64 4, i1 false), !mem.cache_hint !2
+ ret void
+}
+
+define void @set_destination_hint(ptr %dst) {
+;
+; CHECK-LABEL: define void @set_destination_hint(
+; CHECK-SAME: ptr [[DST:%.*]]) {
+; CHECK-NEXT: store i32 0, ptr [[DST]], align 4
+; CHECK-NEXT: ret void
+;
+ call void @llvm.memset.p0.i64(ptr align 4 %dst, i8 0, i64 4, i1 false), !mem.cache_hint !3
+ ret void
+}
+
+; TODO: Check whether invariant.load can be kept after exposing inactive lanes.
+; This records the existing behavior while preserving the cache policy.
+define <2 x i32> @speculated_masked_load(ptr dereferenceable(8) %p, <2 x i1> %mask) {
+;
+; CHECK-LABEL: define <2 x i32> @speculated_masked_load(
+; CHECK-SAME: ptr dereferenceable(8) [[P:%.*]], <2 x i1> [[MASK:%.*]]) {
+; CHECK-NEXT: [[UNMASKEDLOAD:%.*]] = load <2 x i32>, ptr [[P]], align 1, !invariant.load [[META0:![0-9]+]], !mem.cache_hint [[META1:![0-9]+]]
+; CHECK-NEXT: [[V:%.*]] = select <2 x i1> [[MASK]], <2 x i32> [[UNMASKEDLOAD]], <2 x i32> zeroinitializer
+; CHECK-NEXT: ret <2 x i32> [[V]]
+;
+ %v = call <2 x i32> @llvm.masked.load.v2i32.p0(ptr %p, <2 x i1> %mask, <2 x i32> zeroinitializer), !mem.cache_hint !3, !invariant.load !6
+ ret <2 x i32> %v
+}
+
+!0 = !{i32 1, !1}
+!1 = !{!"nvvm.l1_eviction", !"last"}
+!2 = !{i32 0, !1, i32 1, !4}
+!3 = !{i32 0, !1}
+!4 = !{!"nvvm.l1_eviction", !"first"}
+!6 = !{}
+;.
+; CHECK: [[META0]] = !{}
+; CHECK: [[META1]] = !{i32 0, [[META2:![0-9]+]]}
+; CHECK: [[META2]] = !{!"nvvm.l1_eviction", !"last"}
+;.
diff --git a/llvm/test/Transforms/InstCombine/memory-metadata.ll b/llvm/test/Transforms/InstCombine/memory-metadata.ll
new file mode 100644
index 00000000000000..22eb8945aa0b9d
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/memory-metadata.ll
@@ -0,0 +1,259 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -passes=instcombine < %s | FileCheck %s --implicit-check-not=!test.unknown --implicit-check-not=!prof
+
+target datalayout = "e-p:64:64"
+
+define float @bitcast_load(ptr %p) {
+;
+; CHECK-LABEL: define float @bitcast_load(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[V1:%.*]] = load float, ptr [[P]], align 4, !tbaa [[INT_TBAA0:![0-9]+]], !invariant.load [[META4:![0-9]+]], !alias.scope [[META5:![0-9]+]], !noalias [[META5]], !nontemporal [[META8:![0-9]+]], !llvm.mem.parallel_loop_access [[META9:![0-9]+]], !invariant.group [[META4]], !llvm.access.group [[META9]], !noundef [[META4]], !annotation [[META10:![0-9]+]], !mmra [[META11:![0-9]+]], !noalias.addrspace [[META12:![0-9]+]], !mem.cache_hint [[META13:![0-9]+]]
+; CHECK-NEXT: ret float [[V1]]
+;
+ %v = load i32, ptr %p, align 4, !tbaa !10, !range !9, !noundef !0, !invariant.load !0, !invariant.group !0, !mem.cache_hint !16, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4, !test.unknown !0
+ %r = bitcast i32 %v to float
+ ret float %r
+}
+
+define void @bitcast_store(ptr %p, float %v) {
+;
+; CHECK-LABEL: define void @bitcast_store(
+; CHECK-SAME: ptr [[P:%.*]], float [[V:%.*]]) {
+; CHECK-NEXT: store float [[V]], ptr [[P]], align 4, !tbaa [[INT_TBAA0]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]]
+; CHECK-NEXT: ret void
+;
+ %bits = bitcast float %v to i32
+ store i32 %bits, ptr %p, align 4, !tbaa !10, !invariant.group !0, !mem.cache_hint !18, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4, !test.unknown !0
+ ret void
+}
+
+define i32 @unpack_struct_load(ptr %p) {
+;
+; CHECK-LABEL: define i32 @unpack_struct_load(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[V_UNPACK:%.*]] = load i32, ptr [[P]], align 8, !tbaa.struct [[TBAA_STRUCT15:![0-9]+]], !invariant.load [[META4]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: [[V_ELT1:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 4, !annotation [[META10]]
+; CHECK-NEXT: [[V_UNPACK2:%.*]] = load i32, ptr [[V_ELT1]], align 4, !tbaa.struct [[TBAA_STRUCT15]], !invariant.load [[META4]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: [[R:%.*]] = add i32 [[V_UNPACK]], [[V_UNPACK2]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %v = load {i32, i32}, ptr %p, align 8, !tbaa.struct !19, !invariant.load !0, !invariant.group !0, !mem.cache_hint !16, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4, !test.unknown !0
+ %a = extractvalue {i32, i32} %v, 0
+ %b = extractvalue {i32, i32} %v, 1
+ %r = add i32 %a, %b
+ ret i32 %r
+}
+
+define i32 @unpack_array_load(ptr %p) {
+;
+; CHECK-LABEL: define i32 @unpack_array_load(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[V_UNPACK:%.*]] = load i32, ptr [[P]], align 8, !tbaa.struct [[TBAA_STRUCT15]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: [[V_ELT1:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 4, !annotation [[META10]]
+; CHECK-NEXT: [[V_UNPACK2:%.*]] = load i32, ptr [[V_ELT1]], align 4, !tbaa.struct [[TBAA_STRUCT15]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: [[R:%.*]] = add i32 [[V_UNPACK]], [[V_UNPACK2]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %v = load [2 x i32], ptr %p, align 8, !tbaa.struct !19, !invariant.load !0, !invariant.group !0, !mem.cache_hint !16, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4, !test.unknown !0
+ %a = extractvalue [2 x i32] %v, 0
+ %b = extractvalue [2 x i32] %v, 1
+ %r = add i32 %a, %b
+ ret i32 %r
+}
+
+define void @unpack_struct_store(ptr %p, {i32, i32} %v) {
+;
+; CHECK-LABEL: define void @unpack_struct_store(
+; CHECK-SAME: ptr [[P:%.*]], { i32, i32 } [[V:%.*]]) {
+; CHECK-NEXT: [[V_ELT:%.*]] = extractvalue { i32, i32 } [[V]], 0, !annotation [[META10]]
+; CHECK-NEXT: store i32 [[V_ELT]], ptr [[P]], align 8, !tbaa.struct [[TBAA_STRUCT15]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: [[P_REPACK1:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 4, !annotation [[META10]]
+; CHECK-NEXT: [[V_ELT2:%.*]] = extractvalue { i32, i32 } [[V]], 1, !annotation [[META10]]
+; CHECK-NEXT: store i32 [[V_ELT2]], ptr [[P_REPACK1]], align 4, !tbaa.struct [[TBAA_STRUCT15]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: ret void
+;
+ store {i32, i32} %v, ptr %p, align 8, !tbaa.struct !19, !invariant.group !0, !mem.cache_hint !18, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4, !test.unknown !0
+ ret void
+}
+
+define void @unpack_array_store(ptr %p, [2 x i32] %v) {
+;
+; CHECK-LABEL: define void @unpack_array_store(
+; CHECK-SAME: ptr [[P:%.*]], [2 x i32] [[V:%.*]]) {
+; CHECK-NEXT: [[V_ELT:%.*]] = extractvalue [2 x i32] [[V]], 0, !annotation [[META10]]
+; CHECK-NEXT: store i32 [[V_ELT]], ptr [[P]], align 8, !tbaa.struct [[TBAA_STRUCT15]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: [[P_REPACK1:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 4, !annotation [[META10]]
+; CHECK-NEXT: [[V_ELT2:%.*]] = extractvalue [2 x i32] [[V]], 1, !annotation [[META10]]
+; CHECK-NEXT: store i32 [[V_ELT2]], ptr [[P_REPACK1]], align 4, !tbaa.struct [[TBAA_STRUCT15]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: ret void
+;
+ store [2 x i32] %v, ptr %p, align 8, !tbaa.struct !19, !invariant.group !0, !mem.cache_hint !18, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4, !test.unknown !0
+ ret void
+}
+
+; The two pointer operands carry different policies. Call profiling must not
+; be attached to the replacement native memory operations.
+define void @copy_memory(ptr %dst, ptr %src) {
+;
+; CHECK-LABEL: define void @copy_memory(
+; CHECK-SAME: ptr [[DST:%.*]], ptr [[SRC:%.*]]) {
+; CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr [[SRC]], align 8, !alias.scope [[META5]], !noalias [[META5]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: store i64 [[TMP1]], ptr [[DST]], align 8, !alias.scope [[META5]], !noalias [[META5]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: ret void
+;
+ call void @llvm.memcpy.p0.p0.i64(ptr align 8 %dst, ptr align 8 %src, i64 8, i1 false), !tbaa.struct !19, !prof !24, !mem.cache_hint !22, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4, !test.unknown !0
+ ret void
+}
+
+define void @set_memory(ptr %dst) {
+;
+; CHECK-LABEL: define void @set_memory(
+; CHECK-SAME: ptr [[DST:%.*]]) {
+; CHECK-NEXT: store i32 0, ptr [[DST]], align 4, !annotation [[META10]]
+; CHECK-NEXT: ret void
+;
+ call void @llvm.memset.p0.i64(ptr align 4 %dst, i8 0, i64 4, i1 false), !tbaa !10, !prof !24, !mem.cache_hint !16, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4, !test.unknown !0
+ ret void
+}
+
+define <2 x i32> @splat_gather(ptr %p) {
+;
+; CHECK-LABEL: define <2 x i32> @splat_gather(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[LOAD_SCALAR:%.*]] = load i32, ptr [[P]], align 1, !annotation [[META10]]
+; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[LOAD_SCALAR]], i64 0, !annotation [[META10]]
+; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer, !annotation [[META10]]
+; CHECK-NEXT: ret <2 x i32> [[BROADCAST_SPLAT]]
+;
+ %ptr0 = insertelement <2 x ptr> poison, ptr %p, i32 0
+ %ptrs = shufflevector <2 x ptr> %ptr0, <2 x ptr> poison, <2 x i32> zeroinitializer
+ %v = call <2 x i32> @llvm.masked.gather.v2i32.v2p0(<2 x ptr> %ptrs, <2 x i1> <i1 true, i1 true>, <2 x i32> poison), !tbaa !10, !range !9, !invariant.load !0, !prof !24, !mem.cache_hint !16, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4, !test.unknown !0
+ ret <2 x i32> %v
+}
+
+define void @splat_scatter(ptr %p, i32 %v) {
+;
+; CHECK-LABEL: define void @splat_scatter(
+; CHECK-SAME: ptr [[P:%.*]], i32 [[V:%.*]]) {
+; CHECK-NEXT: store i32 [[V]], ptr [[P]], align 1, !tbaa [[INT_TBAA0]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META18:![0-9]+]]
+; CHECK-NEXT: ret void
+;
+ %ptr0 = insertelement <2 x ptr> poison, ptr %p, i32 0
+ %ptrs = shufflevector <2 x ptr> %ptr0, <2 x ptr> poison, <2 x i32> zeroinitializer
+ %val0 = insertelement <2 x i32> poison, i32 %v, i32 0
+ %vals = shufflevector <2 x i32> %val0, <2 x i32> poison, <2 x i32> zeroinitializer
+ call void @llvm.masked.scatter.v2i32.v2p0(<2 x i32> %vals, <2 x ptr> %ptrs, <2 x i1> <i1 true, i1 true>), !tbaa !10, !mem.cache_hint !18, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4
+ ret void
+}
+
+define i32 @single_struct_noundef(ptr %p) {
+;
+; CHECK-LABEL: define i32 @single_struct_noundef(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[V_UNPACK:%.*]] = load i32, ptr [[P]], align 4, !noundef [[META4]]
+; CHECK-NEXT: ret i32 [[V_UNPACK]]
+;
+ %v = load {i32}, ptr %p, !noundef !0
+ %x = extractvalue {i32} %v, 0
+ ret i32 %x
+}
+
+define i32 @single_array_noundef(ptr %p) {
+;
+; CHECK-LABEL: define i32 @single_array_noundef(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[V_UNPACK:%.*]] = load i32, ptr [[P]], align 4, !noundef [[META4]]
+; CHECK-NEXT: ret i32 [[V_UNPACK]]
+;
+ %v = load [1 x i32], ptr %p, !noundef !0
+ %x = extractvalue [1 x i32] %v, 0
+ ret i32 %x
+}
+
+define float @single_struct_fpmath(ptr %p) {
+;
+; CHECK-LABEL: define float @single_struct_fpmath(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[V_UNPACK:%.*]] = load float, ptr [[P]], align 4, !fpmath [[META19:![0-9]+]], !noundef [[META4]]
+; CHECK-NEXT: ret float [[V_UNPACK]]
+;
+ %v = load {float}, ptr %p, !fpmath !14, !nofpclass !15, !noundef !0
+ %x = extractvalue {float} %v, 0
+ ret float %x
+}
+
+define float @single_array_fpmath(ptr %p) {
+;
+; CHECK-LABEL: define float @single_array_fpmath(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[V_UNPACK:%.*]] = load float, ptr [[P]], align 4, !fpmath [[META19]], !noundef [[META4]]
+; CHECK-NEXT: ret float [[V_UNPACK]]
+;
+ %v = load [1 x float], ptr %p, !fpmath !14, !nofpclass !15, !noundef !0
+ %x = extractvalue [1 x float] %v, 0
+ ret float %x
+}
+
+define <2 x i32> @unmask_pcsections(ptr %p) {
+;
+; CHECK-LABEL: define <2 x i32> @unmask_pcsections(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[UNMASKEDLOAD:%.*]] = load <2 x i32>, ptr [[P]], align 1, !pcsections [[META20:![0-9]+]]
+; CHECK-NEXT: ret <2 x i32> [[UNMASKEDLOAD]]
+;
+ %v = call <2 x i32> @llvm.masked.load.v2i32.p0(ptr %p, <2 x i1> <i1 true, i1 true>, <2 x i32> poison), !pcsections !26
+ ret <2 x i32> %v
+}
+
+!0 = !{}
+!1 = !{i32 1}
+!2 = !{!"preserved memory metadata"}
+!3 = !{!"test", !"relaxed"}
+!4 = !{i32 5, i32 6}
+!5 = distinct !{}
+!6 = !{!7}
+!7 = distinct !{!7, !8, !"scope"}
+!8 = distinct !{!8, i1 false, !"domain"}
+!9 = !{i32 0, i32 100}
+!10 = !{!11, !11, i64 0}
+!11 = !{!"int", !12, i64 0}
+!12 = !{!"omnipotent char", !13, i64 0}
+!13 = !{!"root"}
+!14 = !{float 2.5}
+!15 = !{i32 3}
+!16 = !{i32 0, !17}
+!17 = !{!"nvvm.l1_eviction", !"last"}
+!18 = !{i32 1, !17}
+!19 = !{i64 0, i64 4, !10, i64 4, i64 4, !20}
+!20 = !{!21, !21, i64 0}
+!21 = !{!"float", !12, i64 0}
+!22 = !{i32 0, !17, i32 1, !23}
+!23 = !{!"nvvm.l1_eviction", !"first"}
+!24 = !{!"branch_weights", i32 10}
+!25 = !{i64 8}
+!26 = !{!"test_section", !27}
+!27 = !{i32 42}
+;.
+; CHECK: [[INT_TBAA0]] = !{[[META1:![0-9]+]], [[META1]], i64 0}
+; CHECK: [[META1]] = !{!"int", [[META2:![0-9]+]], i64 0}
+; CHECK: [[META2]] = !{!"omnipotent char", [[META3:![0-9]+]], i64 0}
+; CHECK: [[META3]] = !{!"root"}
+; 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: [[META9]] = distinct !{}
+; CHECK: [[META10]] = !{!"preserved memory metadata"}
+; CHECK: [[META11]] = !{!"test", !"relaxed"}
+; CHECK: [[META12]] = !{i32 5, i32 6}
+; CHECK: [[META13]] = !{i32 0, [[META14:![0-9]+]]}
+; CHECK: [[META14]] = !{!"nvvm.l1_eviction", !"last"}
+; CHECK: [[TBAA_STRUCT15]] = !{i64 0, i64 4, [[INT_TBAA0]], i64 4, i64 4, [[META16:![0-9]+]]}
+; CHECK: [[META16]] = !{[[META17:![0-9]+]], [[META17]], i64 0}
+; CHECK: [[META17]] = !{!"float", [[META2]], i64 0}
+; CHECK: [[META18]] = !{i32 1, [[META14]]}
+; CHECK: [[META19]] = !{float 2.500000e+00}
+; CHECK: [[META20]] = !{!"test_section", [[META21:![0-9]+]]}
+; CHECK: [[META21]] = !{i32 42}
+;.
diff --git a/llvm/test/Transforms/InstCombine/ptr-replace-alloca.ll b/llvm/test/Transforms/InstCombine/ptr-replace-alloca.ll
index a3bab9d5403bac..d0043e58537f82 100644
--- a/llvm/test/Transforms/InstCombine/ptr-replace-alloca.ll
+++ b/llvm/test/Transforms/InstCombine/ptr-replace-alloca.ll
@@ -514,9 +514,7 @@ define i8 @call_readonly_keep_alloca2() {
ret i8 %v
}
-; The pointer changes but the load type doesn't, so all metadata (here
-; !annotation, which the type-changing copyMetadataForLoad would drop) must be
-; preserved.
+; Only the pointer changes, so preserve all metadata on the load.
@g3 = external constant [32 x i8], align 16
define i8 @preserve_load_metadata(i64 %idx) {
diff --git a/llvm/test/Transforms/InstCombine/storemerge-metadata.ll b/llvm/test/Transforms/InstCombine/storemerge-metadata.ll
new file mode 100644
index 00000000000000..de3e5478ad1ab0
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/storemerge-metadata.ll
@@ -0,0 +1,220 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -passes=instcombine < %s | FileCheck %s
+
+define void @common_metadata(ptr %p, i1 %c, i32 %a, i32 %b) {
+;
+; CHECK-LABEL: define void @common_metadata(
+; CHECK-SAME: ptr [[P:%.*]], i1 [[C:%.*]], i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: br i1 [[C]], label %[[LEFT:.*]], label %[[RIGHT:.*]]
+; CHECK: [[LEFT]]:
+; CHECK-NEXT: br label %[[JOIN:.*]]
+; CHECK: [[RIGHT]]:
+; CHECK-NEXT: br label %[[JOIN]]
+; CHECK: [[JOIN]]:
+; CHECK-NEXT: [[STOREMERGE:%.*]] = phi i32 [ [[B]], %[[RIGHT]] ], [ [[A]], %[[LEFT]] ]
+; CHECK-NEXT: store i32 [[STOREMERGE]], ptr [[P]], align 4, !tbaa [[INT_TBAA0:![0-9]+]], !alias.scope [[META4:![0-9]+]], !noalias [[META4]], !llvm.access.group [[ACC_GRP7:![0-9]+]]
+; CHECK-NEXT: ret void
+;
+entry:
+ br i1 %c, label %left, label %right
+left:
+ store i32 %a, ptr %p, align 4, !tbaa !10, !alias.scope !14, !noalias !14, !nontemporal !4, !llvm.access.group !8, !mem.cache_hint !0
+ br label %join
+right:
+ store i32 %b, ptr %p, align 4, !tbaa !10, !alias.scope !14, !noalias !14, !nontemporal !4, !llvm.access.group !8, !mem.cache_hint !0
+ br label %join
+join:
+ ret void
+}
+
+define void @intersect_access_groups(ptr %p, i1 %c, i32 %a, i32 %b) {
+;
+; CHECK-LABEL: define void @intersect_access_groups(
+; CHECK-SAME: ptr [[P:%.*]], i1 [[C:%.*]], i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: br i1 [[C]], label %[[LEFT:.*]], label %[[RIGHT:.*]]
+; CHECK: [[LEFT]]:
+; CHECK-NEXT: br label %[[JOIN:.*]]
+; CHECK: [[RIGHT]]:
+; CHECK-NEXT: br label %[[JOIN]]
+; CHECK: [[JOIN]]:
+; CHECK-NEXT: [[STOREMERGE:%.*]] = phi i32 [ [[B]], %[[RIGHT]] ], [ [[A]], %[[LEFT]] ]
+; CHECK-NEXT: store i32 [[STOREMERGE]], ptr [[P]], align 4, !llvm.access.group [[ACC_GRP9:![0-9]+]]
+; CHECK-NEXT: ret void
+;
+entry:
+ br i1 %c, label %left, label %right
+left:
+ store i32 %a, ptr %p, align 4, !llvm.access.group !8
+ br label %join
+right:
+ store i32 %b, ptr %p, align 4, !llvm.access.group !9
+ br label %join
+join:
+ ret void
+}
+
+define void @conflicting_cache_hints(ptr %p, i1 %c, i32 %a, i32 %b) {
+;
+; CHECK-LABEL: define void @conflicting_cache_hints(
+; CHECK-SAME: ptr [[P:%.*]], i1 [[C:%.*]], i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: br i1 [[C]], label %[[LEFT:.*]], label %[[RIGHT:.*]]
+; CHECK: [[LEFT]]:
+; CHECK-NEXT: br label %[[JOIN:.*]]
+; CHECK: [[RIGHT]]:
+; CHECK-NEXT: br label %[[JOIN]]
+; CHECK: [[JOIN]]:
+; CHECK-NEXT: [[STOREMERGE:%.*]] = phi i32 [ [[B]], %[[RIGHT]] ], [ [[A]], %[[LEFT]] ]
+; CHECK-NEXT: store i32 [[STOREMERGE]], ptr [[P]], align 4
+; CHECK-NEXT: ret void
+;
+entry:
+ br i1 %c, label %left, label %right
+left:
+ store i32 %a, ptr %p, align 4, !mem.cache_hint !0
+ br label %join
+right:
+ store i32 %b, ptr %p, align 4, !mem.cache_hint !2
+ br label %join
+join:
+ ret void
+}
+
+define void @metadata_only_left(ptr %p, i1 %c, i32 %a, i32 %b) {
+;
+; CHECK-LABEL: define void @metadata_only_left(
+; CHECK-SAME: ptr [[P:%.*]], i1 [[C:%.*]], i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: br i1 [[C]], label %[[LEFT:.*]], label %[[RIGHT:.*]]
+; CHECK: [[LEFT]]:
+; CHECK-NEXT: br label %[[JOIN:.*]]
+; CHECK: [[RIGHT]]:
+; CHECK-NEXT: br label %[[JOIN]]
+; CHECK: [[JOIN]]:
+; CHECK-NEXT: [[STOREMERGE:%.*]] = phi i32 [ [[B]], %[[RIGHT]] ], [ [[A]], %[[LEFT]] ]
+; CHECK-NEXT: store i32 [[STOREMERGE]], ptr [[P]], align 4
+; CHECK-NEXT: ret void
+;
+entry:
+ br i1 %c, label %left, label %right
+left:
+ store i32 %a, ptr %p, align 4, !tbaa !10, !alias.scope !14, !noalias !14, !nontemporal !4, !llvm.access.group !8, !mem.cache_hint !0
+ br label %join
+right:
+ store i32 %b, ptr %p, align 4
+ br label %join
+join:
+ ret void
+}
+
+define void @metadata_only_right(ptr %p, i1 %c, i32 %a, i32 %b) {
+;
+; CHECK-LABEL: define void @metadata_only_right(
+; CHECK-SAME: ptr [[P:%.*]], i1 [[C:%.*]], i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: br i1 [[C]], label %[[LEFT:.*]], label %[[RIGHT:.*]]
+; CHECK: [[LEFT]]:
+; CHECK-NEXT: br label %[[JOIN:.*]]
+; CHECK: [[RIGHT]]:
+; CHECK-NEXT: br label %[[JOIN]]
+; CHECK: [[JOIN]]:
+; CHECK-NEXT: [[STOREMERGE:%.*]] = phi i32 [ [[B]], %[[RIGHT]] ], [ [[A]], %[[LEFT]] ]
+; CHECK-NEXT: store i32 [[STOREMERGE]], ptr [[P]], align 4
+; CHECK-NEXT: ret void
+;
+entry:
+ br i1 %c, label %left, label %right
+left:
+ store i32 %a, ptr %p, align 4
+ br label %join
+right:
+ store i32 %b, ptr %p, align 4, !tbaa !10, !alias.scope !14, !noalias !14, !nontemporal !4, !llvm.access.group !8, !mem.cache_hint !0
+ br label %join
+join:
+ ret void
+}
+
+define void @triangle_common_metadata(ptr %p, i1 %c, i32 %a, i32 %b) {
+;
+; CHECK-LABEL: define void @triangle_common_metadata(
+; CHECK-SAME: ptr [[P:%.*]], i1 [[C:%.*]], i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*]]:
+; CHECK-NEXT: br i1 [[C]], label %[[THEN:.*]], label %[[JOIN:.*]]
+; CHECK: [[THEN]]:
+; CHECK-NEXT: br label %[[JOIN]]
+; CHECK: [[JOIN]]:
+; CHECK-NEXT: [[STOREMERGE:%.*]] = phi i32 [ [[B]], %[[THEN]] ], [ [[A]], %[[ENTRY]] ]
+; CHECK-NEXT: store i32 [[STOREMERGE]], ptr [[P]], align 4
+; CHECK-NEXT: ret void
+;
+entry:
+ store i32 %a, ptr %p, align 4, !nontemporal !4, !mem.cache_hint !0
+ br i1 %c, label %then, label %join
+then:
+ store i32 %b, ptr %p, align 4, !nontemporal !4, !mem.cache_hint !0
+ br label %join
+join:
+ ret void
+}
+; Capture components must be combined across both incoming pointer values.
+define void @merge_pointer_captures(ptr %p, i1 %c, ptr %a, ptr %b) {
+;
+; CHECK-LABEL: define void @merge_pointer_captures(
+; CHECK-SAME: ptr [[P:%.*]], i1 [[C:%.*]], ptr [[A:%.*]], ptr [[B:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: br i1 [[C]], label %[[LEFT:.*]], label %[[RIGHT:.*]]
+; CHECK: [[LEFT]]:
+; CHECK-NEXT: br label %[[JOIN:.*]]
+; CHECK: [[RIGHT]]:
+; CHECK-NEXT: br label %[[JOIN]]
+; CHECK: [[JOIN]]:
+; CHECK-NEXT: [[STOREMERGE:%.*]] = phi ptr [ [[B]], %[[RIGHT]] ], [ [[A]], %[[LEFT]] ]
+; CHECK-NEXT: store ptr [[STOREMERGE]], ptr [[P]], align 8
+; CHECK-NEXT: ret void
+;
+entry:
+ br i1 %c, label %left, label %right
+left:
+ store ptr %a, ptr %p, align 8, !captures !17
+ br label %join
+right:
+ store ptr %b, ptr %p, align 8, !captures !18
+ br label %join
+join:
+ ret void
+}
+
+!0 = !{i32 1, !1}
+!1 = !{!"nvvm.l1_eviction", !"last"}
+!2 = !{i32 1, !3}
+!3 = !{!"nvvm.l1_eviction", !"first"}
+!4 = !{i32 1}
+!5 = distinct !{}
+!6 = distinct !{}
+!7 = distinct !{}
+!8 = !{!5, !6}
+!9 = !{!6, !7}
+!10 = !{!11, !11, i64 0}
+!11 = !{!"int", !12}
+!12 = !{!"char", !13}
+!13 = !{!"root"}
+!14 = !{!15}
+!15 = distinct !{!15, !16}
+!16 = distinct !{!16, i1 false, !"domain"}
+!17 = !{!"address"}
+!18 = !{!"read_provenance"}
+
+;.
+; CHECK: [[INT_TBAA0]] = !{[[META1:![0-9]+]], [[META1]], i64 0}
+; CHECK: [[META1]] = !{!"int", [[META2:![0-9]+]]}
+; CHECK: [[META2]] = !{!"char", [[META3:![0-9]+]]}
+; CHECK: [[META3]] = !{!"root"}
+; CHECK: [[META4]] = !{[[META5:![0-9]+]]}
+; CHECK: [[META5]] = distinct !{[[META5]], [[META6:![0-9]+]]}
+; CHECK: [[META6]] = distinct !{[[META6]], i1 false, !"domain"}
+; CHECK: [[ACC_GRP7]] = !{[[META8:![0-9]+]], [[ACC_GRP9]]}
+; CHECK: [[META8]] = distinct !{}
+; CHECK: [[ACC_GRP9]] = distinct !{}
+;.
>From 6486a6e66f98ee7e3ae0682c0f488c72fe0c208f Mon Sep 17 00:00:00 2001
From: Yonah Goldberg <ygoldberg at nvidia.com>
Date: Wed, 18 Nov 2026 01:02:03 +0000
Subject: [PATCH 2/2] [InstCombine] Use shared memory metadata propagation
---
.../InstCombine/InstCombineCalls.cpp | 34 +++------
.../InstCombineLoadStoreAlloca.cpp | 74 +++----------------
.../InstCombine/memory-cache-hint.ll | 19 +++--
.../Transforms/InstCombine/memory-metadata.ll | 52 +++++++------
.../InstCombine/storemerge-metadata.ll | 18 +++--
5 files changed, 74 insertions(+), 123 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 5d9e01ac505a0c..e98c6bb616e955 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -27,6 +27,7 @@
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/MemoryBuiltins.h"
+#include "llvm/Analysis/MetadataUtils.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Analysis/VectorUtils.h"
#include "llvm/IR/AttributeMask.h"
@@ -169,32 +170,17 @@ Instruction *InstCombinerImpl::SimplifyAnyMemTransfer(AnyMemTransferInst *MI) {
// Use an integer load+store unless we can find something better.
IntegerType* IntType = IntegerType::get(MI->getContext(), Size<<3);
- // If the memcpy has metadata describing the members, see if we can get the
- // TBAA, scope and noalias tags describing our copy.
- AAMDNodes AACopyMD = MI->getAAMetadata().adjustForAccess(Size);
-
Value *Src = MI->getArgOperand(1);
Value *Dest = MI->getArgOperand(0);
LoadInst *L = Builder.CreateLoad(IntType, Src);
// Alignment from the mem intrinsic will be better, so use it.
L->setAlignment(*CopySrcAlign);
- L->setAAMetadata(AACopyMD);
- MDNode *LoopMemParallelMD =
- MI->getMetadata(LLVMContext::MD_mem_parallel_loop_access);
- if (LoopMemParallelMD)
- L->setMetadata(LLVMContext::MD_mem_parallel_loop_access, LoopMemParallelMD);
- MDNode *AccessGroupMD = MI->getMetadata(LLVMContext::MD_access_group);
- if (AccessGroupMD)
- L->setMetadata(LLVMContext::MD_access_group, AccessGroupMD);
+ copyMetadataForMemoryAccess(*L, *MI);
StoreInst *S = Builder.CreateStore(L, Dest);
// Alignment from the mem intrinsic will be better, so use it.
S->setAlignment(*CopyDstAlign);
- S->setAAMetadata(AACopyMD);
- if (LoopMemParallelMD)
- S->setMetadata(LLVMContext::MD_mem_parallel_loop_access, LoopMemParallelMD);
- if (AccessGroupMD)
- S->setMetadata(LLVMContext::MD_access_group, AccessGroupMD);
+ copyMetadataForMemoryAccess(*S, *MI);
S->copyMetadata(*MI, LLVMContext::MD_DIAssignID);
if (auto *MT = dyn_cast<MemTransferInst>(MI)) {
@@ -272,6 +258,7 @@ Instruction *InstCombinerImpl::SimplifyAnyMemSet(AnyMemSetInst *MI) {
return nullptr;
StoreInst *S = Builder.CreateStore(FillVal, Dest, MI->isVolatile());
+ copyMetadataForMemoryAccess(*S, *MI);
S->copyMetadata(*MI, LLVMContext::MD_DIAssignID);
for (DbgVariableRecord *DbgAssign : at::getDVRAssignmentMarkers(S)) {
if (llvm::is_contained(DbgAssign->location_ops(), Fill))
@@ -302,7 +289,7 @@ Value *InstCombinerImpl::simplifyMaskedLoad(IntrinsicInst &II) {
if (match(Mask, m_AllOnesOrPoison())) {
LoadInst *L = Builder.CreateAlignedLoad(II.getType(), LoadPtr, Alignment,
"unmaskedload");
- L->copyMetadata(II);
+ copyMetadataForMemoryAccess(*L, II);
return L;
}
@@ -312,7 +299,9 @@ Value *InstCombinerImpl::simplifyMaskedLoad(IntrinsicInst &II) {
SQ.getWithInstruction(&II))) {
LoadInst *LI = Builder.CreateAlignedLoad(II.getType(), LoadPtr, Alignment,
"unmaskedload");
- LI->copyMetadata(II);
+ // TODO: Check whether metadata valid only for active lanes can be retained
+ // on the unmasked load.
+ copyMetadataForMemoryAccess(*LI, II);
return Builder.CreateSelect(II.getArgOperand(1), LI, II.getArgOperand(2));
}
@@ -338,7 +327,7 @@ Instruction *InstCombinerImpl::simplifyMaskedStore(IntrinsicInst &II) {
if (match(ConstMask, m_AllOnesOrPoison())) {
StoreInst *S =
new StoreInst(II.getArgOperand(0), StorePtr, false, Alignment);
- S->copyMetadata(II);
+ copyMetadataForMemoryAccess(*S, II);
return S;
}
@@ -375,6 +364,7 @@ Instruction *InstCombinerImpl::simplifyMaskedGather(IntrinsicInst &II) {
const Align Alignment = II.getParamAlign(0).valueOrOne();
LoadInst *L = Builder.CreateAlignedLoad(VecTy->getElementType(), SplatPtr,
Alignment, "load.scalar");
+ copyMetadataForMemoryAccess(*L, II);
Value *Shuf =
Builder.CreateVectorSplat(VecTy->getElementCount(), L, "broadcast");
return replaceInstUsesWith(II, cast<Instruction>(Shuf));
@@ -405,7 +395,7 @@ Instruction *InstCombinerImpl::simplifyMaskedScatter(IntrinsicInst &II) {
Align Alignment = II.getParamAlign(1).valueOrOne();
StoreInst *S = new StoreInst(SplatValue, SplatPtr, /*IsVolatile=*/false,
Alignment);
- S->copyMetadata(II);
+ copyMetadataForMemoryAccess(*S, II);
return S;
}
}
@@ -421,7 +411,7 @@ Instruction *InstCombinerImpl::simplifyMaskedScatter(IntrinsicInst &II) {
Builder.CreateExtractElement(II.getArgOperand(0), LastLane);
StoreInst *S =
new StoreInst(Extract, SplatPtr, /*IsVolatile=*/false, Alignment);
- S->copyMetadata(II);
+ copyMetadataForMemoryAccess(*S, II);
return S;
}
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 60331a3d37b05b..a281e93aa6b977 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -16,6 +16,7 @@
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/Loads.h"
+#include "llvm/Analysis/MetadataUtils.h"
#include "llvm/Analysis/VectorUtils.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
@@ -611,7 +612,7 @@ LoadInst *InstCombinerImpl::combineLoadToNewType(LoadInst &LI, Type *NewTy,
LoadInst *NewLoad = Builder.CreateLoad(
NewTy, LI.getPointerOperand(), LI.getProperties(), LI.getName() + Suffix);
- copyMetadataForLoad(*NewLoad, LI);
+ copyMetadataForMemoryAccess(*NewLoad, LI);
return NewLoad;
}
@@ -624,47 +625,8 @@ static StoreInst *combineStoreToNewValue(InstCombinerImpl &IC, StoreInst &SI,
"can't fold an atomic store of requested type");
Value *Ptr = SI.getPointerOperand();
- SmallVector<std::pair<unsigned, MDNode *>, 8> MD;
- SI.getAllMetadata(MD);
-
StoreInst *NewStore = IC.Builder.CreateStore(V, Ptr, SI.getProperties());
- for (const auto &MDPair : MD) {
- unsigned ID = MDPair.first;
- MDNode *N = MDPair.second;
- // Note, essentially every kind of metadata should be preserved here! This
- // routine is supposed to clone a store instruction changing *only its
- // type*. The only metadata it makes sense to drop is metadata which is
- // invalidated when the pointer type changes. This should essentially
- // never be the case in LLVM, but we explicitly switch over only known
- // metadata to be conservatively correct. If you are adding metadata to
- // LLVM which pertains to stores, you almost certainly want to add it
- // here.
- switch (ID) {
- case LLVMContext::MD_dbg:
- case LLVMContext::MD_DIAssignID:
- case LLVMContext::MD_tbaa:
- case LLVMContext::MD_prof:
- case LLVMContext::MD_fpmath:
- case LLVMContext::MD_tbaa_struct:
- case LLVMContext::MD_alias_scope:
- case LLVMContext::MD_noalias:
- case LLVMContext::MD_nontemporal:
- case LLVMContext::MD_mem_parallel_loop_access:
- case LLVMContext::MD_access_group:
- // All of these directly apply.
- NewStore->setMetadata(ID, N);
- break;
- case LLVMContext::MD_invariant_load:
- case LLVMContext::MD_nonnull:
- case LLVMContext::MD_noundef:
- case LLVMContext::MD_range:
- case LLVMContext::MD_align:
- case LLVMContext::MD_dereferenceable:
- case LLVMContext::MD_dereferenceable_or_null:
- // These don't apply for stores.
- break;
- }
- }
+ copyMetadataForMemoryAccess(*NewStore, SI);
return NewStore;
}
@@ -752,9 +714,6 @@ static Instruction *unpackLoadToAggregate(InstCombinerImpl &IC, LoadInst &LI) {
if (NumElements == 1) {
LoadInst *NewLoad = IC.combineLoadToNewType(LI, ST->getTypeAtIndex(0U),
".unpack");
- NewLoad->setAAMetadata(LI.getAAMetadata());
- // Copy invariant metadata from parent load.
- NewLoad->copyMetadata(LI, LLVMContext::MD_invariant_load);
return IC.replaceInstUsesWith(LI, IC.Builder.CreateInsertValue(
PoisonValue::get(T), NewLoad, 0, Name));
}
@@ -780,10 +739,8 @@ static Instruction *unpackLoadToAggregate(InstCombinerImpl &IC, LoadInst &LI) {
ST->getElementType(i), Ptr,
commonAlignment(Align, SL->getElementOffset(i).getKnownMinValue()),
Name + ".unpack");
- // Propagate AA metadata. It'll still be valid on the narrowed load.
- L->setAAMetadata(LI.getAAMetadata());
- // Copy invariant metadata from parent load.
- L->copyMetadata(LI, LLVMContext::MD_invariant_load);
+ copyMetadataForMemoryAccess(*L, LI,
+ SL->getElementOffset(i).getKnownMinValue());
V = IC.Builder.CreateInsertValue(V, L, i);
}
@@ -796,7 +753,6 @@ static Instruction *unpackLoadToAggregate(InstCombinerImpl &IC, LoadInst &LI) {
auto NumElements = AT->getNumElements();
if (NumElements == 1) {
LoadInst *NewLoad = IC.combineLoadToNewType(LI, ET, ".unpack");
- NewLoad->setAAMetadata(LI.getAAMetadata());
return IC.replaceInstUsesWith(LI, IC.Builder.CreateInsertValue(
PoisonValue::get(T), NewLoad, 0, Name));
}
@@ -828,7 +784,7 @@ static Instruction *unpackLoadToAggregate(InstCombinerImpl &IC, LoadInst &LI) {
auto EltAlign = commonAlignment(Align, Offset.getKnownMinValue());
auto *L = IC.Builder.CreateAlignedLoad(AT->getElementType(), Ptr,
EltAlign, Name + ".unpack");
- L->setAAMetadata(LI.getAAMetadata());
+ copyMetadataForMemoryAccess(*L, LI, Offset.getKnownMinValue());
V = IC.Builder.CreateInsertValue(V, L, i);
Offset += EltSize;
}
@@ -1435,7 +1391,8 @@ static bool unpackStoreToAggregate(InstCombinerImpl &IC, StoreInst &SI) {
auto EltAlign =
commonAlignment(Align, SL->getElementOffset(i).getKnownMinValue());
llvm::Instruction *NS = IC.Builder.CreateAlignedStore(Val, Ptr, EltAlign);
- NS->setAAMetadata(SI.getAAMetadata());
+ copyMetadataForMemoryAccess(*NS, SI,
+ SL->getElementOffset(i).getKnownMinValue());
}
return true;
@@ -1481,7 +1438,7 @@ static bool unpackStoreToAggregate(InstCombinerImpl &IC, StoreInst &SI) {
auto *Val = IC.Builder.CreateExtractValue(V, i, EltName);
auto EltAlign = commonAlignment(Align, Offset.getKnownMinValue());
Instruction *NS = IC.Builder.CreateAlignedStore(Val, Ptr, EltAlign);
- NS->setAAMetadata(SI.getAAMetadata());
+ copyMetadataForMemoryAccess(*NS, SI, Offset.getKnownMinValue());
Offset += EltSize;
}
@@ -1802,17 +1759,10 @@ bool InstCombinerImpl::mergeStoreIntoSuccessor(StoreInst &SI) {
StoreInst *NewSI =
new StoreInst(MergedVal, SI.getOperand(1), SI.getProperties());
InsertNewInstBefore(NewSI, BBI);
- NewSI->setDebugLoc(MergedLoc);
+ copyMetadataForMemoryAccess(*NewSI, SI);
NewSI->mergeDIAssignID({&SI, OtherStore});
-
- // If the two stores had AA tags, merge them.
- AAMDNodes AATags = SI.getAAMetadata();
- if (AATags)
- NewSI->setAAMetadata(AATags.merge(OtherStore->getAAMetadata()));
-
- // If the two stores had access groups, intersect them.
- NewSI->setMetadata(LLVMContext::MD_access_group,
- intersectAccessGroups(&SI, OtherStore));
+ combineMetadataForCSE(NewSI, OtherStore, /*DoesKMove=*/true);
+ NewSI->setDebugLoc(MergedLoc);
// Nuke the old stores.
eraseInstFromFunction(SI);
diff --git a/llvm/test/Transforms/InstCombine/memory-cache-hint.ll b/llvm/test/Transforms/InstCombine/memory-cache-hint.ll
index d42093a7f35bb5..23aa7b6b06b069 100644
--- a/llvm/test/Transforms/InstCombine/memory-cache-hint.ll
+++ b/llvm/test/Transforms/InstCombine/memory-cache-hint.ll
@@ -5,7 +5,7 @@ define void @store_bitcast(ptr %p, float %x) {
;
; CHECK-LABEL: define void @store_bitcast(
; CHECK-SAME: ptr [[P:%.*]], float [[X:%.*]]) {
-; CHECK-NEXT: store float [[X]], ptr [[P]], align 4
+; CHECK-NEXT: store float [[X]], ptr [[P]], align 4, !mem.cache_hint [[META0:![0-9]+]]
; CHECK-NEXT: ret void
;
%bits = bitcast float %x to i32
@@ -17,8 +17,8 @@ define void @copy_both_hints(ptr %dst, ptr %src) {
;
; CHECK-LABEL: define void @copy_both_hints(
; CHECK-SAME: ptr [[DST:%.*]], ptr [[SRC:%.*]]) {
-; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[SRC]], align 4
-; CHECK-NEXT: store i32 [[TMP1]], ptr [[DST]], align 4
+; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[SRC]], align 4, !mem.cache_hint [[META2:![0-9]+]]
+; CHECK-NEXT: store i32 [[TMP1]], ptr [[DST]], align 4, !mem.cache_hint [[META0]]
; CHECK-NEXT: ret void
;
call void @llvm.memcpy.p0.p0.i64(ptr align 4 %dst, ptr align 4 %src, i64 4, i1 false), !mem.cache_hint !2
@@ -29,7 +29,7 @@ define void @set_destination_hint(ptr %dst) {
;
; CHECK-LABEL: define void @set_destination_hint(
; CHECK-SAME: ptr [[DST:%.*]]) {
-; CHECK-NEXT: store i32 0, ptr [[DST]], align 4
+; CHECK-NEXT: store i32 0, ptr [[DST]], align 4, !mem.cache_hint [[META0]]
; CHECK-NEXT: ret void
;
call void @llvm.memset.p0.i64(ptr align 4 %dst, i8 0, i64 4, i1 false), !mem.cache_hint !3
@@ -42,7 +42,7 @@ define <2 x i32> @speculated_masked_load(ptr dereferenceable(8) %p, <2 x i1> %ma
;
; CHECK-LABEL: define <2 x i32> @speculated_masked_load(
; CHECK-SAME: ptr dereferenceable(8) [[P:%.*]], <2 x i1> [[MASK:%.*]]) {
-; CHECK-NEXT: [[UNMASKEDLOAD:%.*]] = load <2 x i32>, ptr [[P]], align 1, !invariant.load [[META0:![0-9]+]], !mem.cache_hint [[META1:![0-9]+]]
+; CHECK-NEXT: [[UNMASKEDLOAD:%.*]] = load <2 x i32>, ptr [[P]], align 1, !invariant.load [[META4:![0-9]+]], !mem.cache_hint [[META5:![0-9]+]]
; CHECK-NEXT: [[V:%.*]] = select <2 x i1> [[MASK]], <2 x i32> [[UNMASKEDLOAD]], <2 x i32> zeroinitializer
; CHECK-NEXT: ret <2 x i32> [[V]]
;
@@ -57,7 +57,10 @@ define <2 x i32> @speculated_masked_load(ptr dereferenceable(8) %p, <2 x i1> %ma
!4 = !{!"nvvm.l1_eviction", !"first"}
!6 = !{}
;.
-; CHECK: [[META0]] = !{}
-; CHECK: [[META1]] = !{i32 0, [[META2:![0-9]+]]}
-; CHECK: [[META2]] = !{!"nvvm.l1_eviction", !"last"}
+; CHECK: [[META0]] = !{i32 1, [[META1:![0-9]+]]}
+; CHECK: [[META1]] = !{!"nvvm.l1_eviction", !"last"}
+; CHECK: [[META2]] = !{i32 0, [[META3:![0-9]+]]}
+; CHECK: [[META3]] = !{!"nvvm.l1_eviction", !"first"}
+; CHECK: [[META4]] = !{}
+; CHECK: [[META5]] = !{i32 0, [[META1]]}
;.
diff --git a/llvm/test/Transforms/InstCombine/memory-metadata.ll b/llvm/test/Transforms/InstCombine/memory-metadata.ll
index 22eb8945aa0b9d..5b5509875e9f6b 100644
--- a/llvm/test/Transforms/InstCombine/memory-metadata.ll
+++ b/llvm/test/Transforms/InstCombine/memory-metadata.ll
@@ -7,7 +7,7 @@ define float @bitcast_load(ptr %p) {
;
; CHECK-LABEL: define float @bitcast_load(
; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT: [[V1:%.*]] = load float, ptr [[P]], align 4, !tbaa [[INT_TBAA0:![0-9]+]], !invariant.load [[META4:![0-9]+]], !alias.scope [[META5:![0-9]+]], !noalias [[META5]], !nontemporal [[META8:![0-9]+]], !llvm.mem.parallel_loop_access [[META9:![0-9]+]], !invariant.group [[META4]], !llvm.access.group [[META9]], !noundef [[META4]], !annotation [[META10:![0-9]+]], !mmra [[META11:![0-9]+]], !noalias.addrspace [[META12:![0-9]+]], !mem.cache_hint [[META13:![0-9]+]]
+; CHECK-NEXT: [[V1:%.*]] = load float, ptr [[P]], align 4, !tbaa [[INT_TBAA0:![0-9]+]], !invariant.load [[META4:![0-9]+]], !alias.scope [[META5:![0-9]+]], !noalias [[META5]], !nontemporal [[META8:![0-9]+]], !llvm.mem.parallel_loop_access [[META9:![0-9]+]], !invariant.group [[META4]], !llvm.access.group [[META9]], !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 float [[V1]]
;
%v = load i32, ptr %p, align 4, !tbaa !10, !range !9, !noundef !0, !invariant.load !0, !invariant.group !0, !mem.cache_hint !16, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4, !test.unknown !0
@@ -19,7 +19,7 @@ define void @bitcast_store(ptr %p, float %v) {
;
; CHECK-LABEL: define void @bitcast_store(
; CHECK-SAME: ptr [[P:%.*]], float [[V:%.*]]) {
-; CHECK-NEXT: store float [[V]], ptr [[P]], align 4, !tbaa [[INT_TBAA0]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]]
+; CHECK-NEXT: store float [[V]], ptr [[P]], align 4, !tbaa [[INT_TBAA0]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !invariant.group [[META4]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META15:![0-9]+]]
; CHECK-NEXT: ret void
;
%bits = bitcast float %v to i32
@@ -31,9 +31,9 @@ define i32 @unpack_struct_load(ptr %p) {
;
; CHECK-LABEL: define i32 @unpack_struct_load(
; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT: [[V_UNPACK:%.*]] = load i32, ptr [[P]], align 8, !tbaa.struct [[TBAA_STRUCT15:![0-9]+]], !invariant.load [[META4]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: [[V_UNPACK:%.*]] = load i32, ptr [[P]], align 8, !tbaa [[INT_TBAA0]], !invariant.load [[META4]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !invariant.group [[META4]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META13]]
; CHECK-NEXT: [[V_ELT1:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 4, !annotation [[META10]]
-; CHECK-NEXT: [[V_UNPACK2:%.*]] = load i32, ptr [[V_ELT1]], align 4, !tbaa.struct [[TBAA_STRUCT15]], !invariant.load [[META4]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: [[V_UNPACK2:%.*]] = load i32, ptr [[V_ELT1]], align 4, !tbaa [[FLOAT_TBAA16:![0-9]+]], !invariant.load [[META4]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META13]]
; CHECK-NEXT: [[R:%.*]] = add i32 [[V_UNPACK]], [[V_UNPACK2]]
; CHECK-NEXT: ret i32 [[R]]
;
@@ -48,9 +48,9 @@ define i32 @unpack_array_load(ptr %p) {
;
; CHECK-LABEL: define i32 @unpack_array_load(
; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT: [[V_UNPACK:%.*]] = load i32, ptr [[P]], align 8, !tbaa.struct [[TBAA_STRUCT15]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: [[V_UNPACK:%.*]] = load i32, ptr [[P]], align 8, !tbaa [[INT_TBAA0]], !invariant.load [[META4]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !invariant.group [[META4]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META13]]
; CHECK-NEXT: [[V_ELT1:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 4, !annotation [[META10]]
-; CHECK-NEXT: [[V_UNPACK2:%.*]] = load i32, ptr [[V_ELT1]], align 4, !tbaa.struct [[TBAA_STRUCT15]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: [[V_UNPACK2:%.*]] = load i32, ptr [[V_ELT1]], align 4, !tbaa [[FLOAT_TBAA16]], !invariant.load [[META4]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META13]]
; CHECK-NEXT: [[R:%.*]] = add i32 [[V_UNPACK]], [[V_UNPACK2]]
; CHECK-NEXT: ret i32 [[R]]
;
@@ -66,10 +66,10 @@ define void @unpack_struct_store(ptr %p, {i32, i32} %v) {
; CHECK-LABEL: define void @unpack_struct_store(
; CHECK-SAME: ptr [[P:%.*]], { i32, i32 } [[V:%.*]]) {
; CHECK-NEXT: [[V_ELT:%.*]] = extractvalue { i32, i32 } [[V]], 0, !annotation [[META10]]
-; CHECK-NEXT: store i32 [[V_ELT]], ptr [[P]], align 8, !tbaa.struct [[TBAA_STRUCT15]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: store i32 [[V_ELT]], ptr [[P]], align 8, !tbaa [[INT_TBAA0]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !invariant.group [[META4]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META15]]
; CHECK-NEXT: [[P_REPACK1:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 4, !annotation [[META10]]
; CHECK-NEXT: [[V_ELT2:%.*]] = extractvalue { i32, i32 } [[V]], 1, !annotation [[META10]]
-; CHECK-NEXT: store i32 [[V_ELT2]], ptr [[P_REPACK1]], align 4, !tbaa.struct [[TBAA_STRUCT15]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: store i32 [[V_ELT2]], ptr [[P_REPACK1]], align 4, !tbaa [[FLOAT_TBAA16]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META15]]
; CHECK-NEXT: ret void
;
store {i32, i32} %v, ptr %p, align 8, !tbaa.struct !19, !invariant.group !0, !mem.cache_hint !18, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4, !test.unknown !0
@@ -81,10 +81,10 @@ define void @unpack_array_store(ptr %p, [2 x i32] %v) {
; CHECK-LABEL: define void @unpack_array_store(
; CHECK-SAME: ptr [[P:%.*]], [2 x i32] [[V:%.*]]) {
; CHECK-NEXT: [[V_ELT:%.*]] = extractvalue [2 x i32] [[V]], 0, !annotation [[META10]]
-; CHECK-NEXT: store i32 [[V_ELT]], ptr [[P]], align 8, !tbaa.struct [[TBAA_STRUCT15]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: store i32 [[V_ELT]], ptr [[P]], align 8, !tbaa [[INT_TBAA0]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !invariant.group [[META4]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META15]]
; CHECK-NEXT: [[P_REPACK1:%.*]] = getelementptr inbounds nuw i8, ptr [[P]], i64 4, !annotation [[META10]]
; CHECK-NEXT: [[V_ELT2:%.*]] = extractvalue [2 x i32] [[V]], 1, !annotation [[META10]]
-; CHECK-NEXT: store i32 [[V_ELT2]], ptr [[P_REPACK1]], align 4, !tbaa.struct [[TBAA_STRUCT15]], !alias.scope [[META5]], !noalias [[META5]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: store i32 [[V_ELT2]], ptr [[P_REPACK1]], align 4, !tbaa [[FLOAT_TBAA16]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META15]]
; CHECK-NEXT: ret void
;
store [2 x i32] %v, ptr %p, align 8, !tbaa.struct !19, !invariant.group !0, !mem.cache_hint !18, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4, !test.unknown !0
@@ -97,8 +97,8 @@ define void @copy_memory(ptr %dst, ptr %src) {
;
; CHECK-LABEL: define void @copy_memory(
; CHECK-SAME: ptr [[DST:%.*]], ptr [[SRC:%.*]]) {
-; CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr [[SRC]], align 8, !alias.scope [[META5]], !noalias [[META5]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !noalias.addrspace [[META12]]
-; CHECK-NEXT: store i64 [[TMP1]], ptr [[DST]], align 8, !alias.scope [[META5]], !noalias [[META5]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !noalias.addrspace [[META12]]
+; CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr [[SRC]], align 8, !tbaa.struct [[TBAA_STRUCT18:![0-9]+]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META19:![0-9]+]]
+; CHECK-NEXT: store i64 [[TMP1]], ptr [[DST]], align 8, !tbaa.struct [[TBAA_STRUCT18]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META15]]
; CHECK-NEXT: ret void
;
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %dst, ptr align 8 %src, i64 8, i1 false), !tbaa.struct !19, !prof !24, !mem.cache_hint !22, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4, !test.unknown !0
@@ -109,7 +109,7 @@ define void @set_memory(ptr %dst) {
;
; CHECK-LABEL: define void @set_memory(
; CHECK-SAME: ptr [[DST:%.*]]) {
-; CHECK-NEXT: store i32 0, ptr [[DST]], align 4, !annotation [[META10]]
+; CHECK-NEXT: store i32 0, ptr [[DST]], align 4, !tbaa [[INT_TBAA0]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META15]]
; CHECK-NEXT: ret void
;
call void @llvm.memset.p0.i64(ptr align 4 %dst, i8 0, i64 4, i1 false), !tbaa !10, !prof !24, !mem.cache_hint !16, !alias.scope !6, !noalias !6, !nontemporal !1, !llvm.mem.parallel_loop_access !5, !llvm.access.group !5, !annotation !2, !nosanitize !0, !mmra !3, !noalias.addrspace !4, !test.unknown !0
@@ -120,7 +120,7 @@ define <2 x i32> @splat_gather(ptr %p) {
;
; CHECK-LABEL: define <2 x i32> @splat_gather(
; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT: [[LOAD_SCALAR:%.*]] = load i32, ptr [[P]], align 1, !annotation [[META10]]
+; CHECK-NEXT: [[LOAD_SCALAR:%.*]] = load i32, ptr [[P]], align 1, !tbaa [[INT_TBAA0]], !range [[RNG21:![0-9]+]], !invariant.load [[META4]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META13]]
; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[LOAD_SCALAR]], i64 0, !annotation [[META10]]
; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer, !annotation [[META10]]
; CHECK-NEXT: ret <2 x i32> [[BROADCAST_SPLAT]]
@@ -135,7 +135,7 @@ define void @splat_scatter(ptr %p, i32 %v) {
;
; CHECK-LABEL: define void @splat_scatter(
; CHECK-SAME: ptr [[P:%.*]], i32 [[V:%.*]]) {
-; CHECK-NEXT: store i32 [[V]], ptr [[P]], align 1, !tbaa [[INT_TBAA0]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META18:![0-9]+]]
+; CHECK-NEXT: store i32 [[V]], ptr [[P]], align 1, !tbaa [[INT_TBAA0]], !alias.scope [[META5]], !noalias [[META5]], !nontemporal [[META8]], !llvm.mem.parallel_loop_access [[META9]], !llvm.access.group [[META9]], !annotation [[META10]], !nosanitize [[META4]], !mmra [[META11]], !noalias.addrspace [[META12]], !mem.cache_hint [[META15]]
; CHECK-NEXT: ret void
;
%ptr0 = insertelement <2 x ptr> poison, ptr %p, i32 0
@@ -174,7 +174,7 @@ define float @single_struct_fpmath(ptr %p) {
;
; CHECK-LABEL: define float @single_struct_fpmath(
; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT: [[V_UNPACK:%.*]] = load float, ptr [[P]], align 4, !fpmath [[META19:![0-9]+]], !noundef [[META4]]
+; CHECK-NEXT: [[V_UNPACK:%.*]] = load float, ptr [[P]], align 4, !fpmath [[META22:![0-9]+]], !noundef [[META4]], !nofpclass [[META23:![0-9]+]]
; CHECK-NEXT: ret float [[V_UNPACK]]
;
%v = load {float}, ptr %p, !fpmath !14, !nofpclass !15, !noundef !0
@@ -186,7 +186,7 @@ define float @single_array_fpmath(ptr %p) {
;
; CHECK-LABEL: define float @single_array_fpmath(
; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT: [[V_UNPACK:%.*]] = load float, ptr [[P]], align 4, !fpmath [[META19]], !noundef [[META4]]
+; CHECK-NEXT: [[V_UNPACK:%.*]] = load float, ptr [[P]], align 4, !fpmath [[META22]], !noundef [[META4]], !nofpclass [[META23]]
; CHECK-NEXT: ret float [[V_UNPACK]]
;
%v = load [1 x float], ptr %p, !fpmath !14, !nofpclass !15, !noundef !0
@@ -198,7 +198,7 @@ define <2 x i32> @unmask_pcsections(ptr %p) {
;
; CHECK-LABEL: define <2 x i32> @unmask_pcsections(
; CHECK-SAME: ptr [[P:%.*]]) {
-; CHECK-NEXT: [[UNMASKEDLOAD:%.*]] = load <2 x i32>, ptr [[P]], align 1, !pcsections [[META20:![0-9]+]]
+; CHECK-NEXT: [[UNMASKEDLOAD:%.*]] = load <2 x i32>, ptr [[P]], align 1, !pcsections [[META24:![0-9]+]]
; CHECK-NEXT: ret <2 x i32> [[UNMASKEDLOAD]]
;
%v = call <2 x i32> @llvm.masked.load.v2i32.p0(ptr %p, <2 x i1> <i1 true, i1 true>, <2 x i32> poison), !pcsections !26
@@ -249,11 +249,15 @@ define <2 x i32> @unmask_pcsections(ptr %p) {
; CHECK: [[META12]] = !{i32 5, i32 6}
; CHECK: [[META13]] = !{i32 0, [[META14:![0-9]+]]}
; CHECK: [[META14]] = !{!"nvvm.l1_eviction", !"last"}
-; CHECK: [[TBAA_STRUCT15]] = !{i64 0, i64 4, [[INT_TBAA0]], i64 4, i64 4, [[META16:![0-9]+]]}
-; CHECK: [[META16]] = !{[[META17:![0-9]+]], [[META17]], i64 0}
+; CHECK: [[META15]] = !{i32 1, [[META14]]}
+; CHECK: [[FLOAT_TBAA16]] = !{[[META17:![0-9]+]], [[META17]], i64 0}
; CHECK: [[META17]] = !{!"float", [[META2]], i64 0}
-; CHECK: [[META18]] = !{i32 1, [[META14]]}
-; CHECK: [[META19]] = !{float 2.500000e+00}
-; CHECK: [[META20]] = !{!"test_section", [[META21:![0-9]+]]}
-; CHECK: [[META21]] = !{i32 42}
+; CHECK: [[TBAA_STRUCT18]] = !{i64 0, i64 4, [[INT_TBAA0]], i64 4, i64 4, [[FLOAT_TBAA16]]}
+; CHECK: [[META19]] = !{i32 0, [[META20:![0-9]+]]}
+; CHECK: [[META20]] = !{!"nvvm.l1_eviction", !"first"}
+; CHECK: [[RNG21]] = !{i32 0, i32 100}
+; CHECK: [[META22]] = !{float 2.500000e+00}
+; CHECK: [[META23]] = !{i32 3}
+; CHECK: [[META24]] = !{!"test_section", [[META25:![0-9]+]]}
+; CHECK: [[META25]] = !{i32 42}
;.
diff --git a/llvm/test/Transforms/InstCombine/storemerge-metadata.ll b/llvm/test/Transforms/InstCombine/storemerge-metadata.ll
index de3e5478ad1ab0..0bec45d237fba9 100644
--- a/llvm/test/Transforms/InstCombine/storemerge-metadata.ll
+++ b/llvm/test/Transforms/InstCombine/storemerge-metadata.ll
@@ -13,7 +13,7 @@ define void @common_metadata(ptr %p, i1 %c, i32 %a, i32 %b) {
; CHECK-NEXT: br label %[[JOIN]]
; CHECK: [[JOIN]]:
; CHECK-NEXT: [[STOREMERGE:%.*]] = phi i32 [ [[B]], %[[RIGHT]] ], [ [[A]], %[[LEFT]] ]
-; CHECK-NEXT: store i32 [[STOREMERGE]], ptr [[P]], align 4, !tbaa [[INT_TBAA0:![0-9]+]], !alias.scope [[META4:![0-9]+]], !noalias [[META4]], !llvm.access.group [[ACC_GRP7:![0-9]+]]
+; CHECK-NEXT: store i32 [[STOREMERGE]], ptr [[P]], align 4, !tbaa [[INT_TBAA0:![0-9]+]], !alias.scope [[META4:![0-9]+]], !noalias [[META4]], !nontemporal [[META7:![0-9]+]], !llvm.access.group [[ACC_GRP8:![0-9]+]], !mem.cache_hint [[META11:![0-9]+]]
; CHECK-NEXT: ret void
;
entry:
@@ -40,7 +40,7 @@ define void @intersect_access_groups(ptr %p, i1 %c, i32 %a, i32 %b) {
; CHECK-NEXT: br label %[[JOIN]]
; CHECK: [[JOIN]]:
; CHECK-NEXT: [[STOREMERGE:%.*]] = phi i32 [ [[B]], %[[RIGHT]] ], [ [[A]], %[[LEFT]] ]
-; CHECK-NEXT: store i32 [[STOREMERGE]], ptr [[P]], align 4, !llvm.access.group [[ACC_GRP9:![0-9]+]]
+; CHECK-NEXT: store i32 [[STOREMERGE]], ptr [[P]], align 4, !llvm.access.group [[ACC_GRP10:![0-9]+]]
; CHECK-NEXT: ret void
;
entry:
@@ -146,7 +146,7 @@ define void @triangle_common_metadata(ptr %p, i1 %c, i32 %a, i32 %b) {
; CHECK-NEXT: br label %[[JOIN]]
; CHECK: [[JOIN]]:
; CHECK-NEXT: [[STOREMERGE:%.*]] = phi i32 [ [[B]], %[[THEN]] ], [ [[A]], %[[ENTRY]] ]
-; CHECK-NEXT: store i32 [[STOREMERGE]], ptr [[P]], align 4
+; CHECK-NEXT: store i32 [[STOREMERGE]], ptr [[P]], align 4, !nontemporal [[META7]], !mem.cache_hint [[META11]]
; CHECK-NEXT: ret void
;
entry:
@@ -171,7 +171,7 @@ define void @merge_pointer_captures(ptr %p, i1 %c, ptr %a, ptr %b) {
; CHECK-NEXT: br label %[[JOIN]]
; CHECK: [[JOIN]]:
; CHECK-NEXT: [[STOREMERGE:%.*]] = phi ptr [ [[B]], %[[RIGHT]] ], [ [[A]], %[[LEFT]] ]
-; CHECK-NEXT: store ptr [[STOREMERGE]], ptr [[P]], align 8
+; CHECK-NEXT: store ptr [[STOREMERGE]], ptr [[P]], align 8, !captures [[META13:![0-9]+]]
; CHECK-NEXT: ret void
;
entry:
@@ -214,7 +214,11 @@ join:
; CHECK: [[META4]] = !{[[META5:![0-9]+]]}
; CHECK: [[META5]] = distinct !{[[META5]], [[META6:![0-9]+]]}
; CHECK: [[META6]] = distinct !{[[META6]], i1 false, !"domain"}
-; CHECK: [[ACC_GRP7]] = !{[[META8:![0-9]+]], [[ACC_GRP9]]}
-; CHECK: [[META8]] = distinct !{}
-; CHECK: [[ACC_GRP9]] = distinct !{}
+; CHECK: [[META7]] = !{i32 1}
+; CHECK: [[ACC_GRP8]] = !{[[META9:![0-9]+]], [[ACC_GRP10]]}
+; CHECK: [[META9]] = distinct !{}
+; CHECK: [[ACC_GRP10]] = distinct !{}
+; CHECK: [[META11]] = !{i32 1, [[META12:![0-9]+]]}
+; CHECK: [[META12]] = !{!"nvvm.l1_eviction", !"last"}
+; CHECK: [[META13]] = !{!"address", !"read_provenance"}
;.
More information about the llvm-branch-commits
mailing list