Skip to content

Commit d49b842

Browse files
committed
[SROA] Use copyMetadataForLoad() helper
Instead of copying just nonnull metadata, use the generic helper to copy metadata to the new load. This helper is specifically designed for the case where the load type may change, so it's safe to use in this context.
1 parent fcd505d commit d49b842

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,25 +2790,19 @@ class llvm::sroa::AllocaSliceRewriter
27902790
LoadInst *NewLI = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), NewPtr,
27912791
NewAI.getAlign(), LI.isVolatile(),
27922792
LI.getName());
2793-
if (AATags)
2794-
NewLI->setAAMetadata(AATags.shift(NewBeginOffset - BeginOffset));
27952793
if (LI.isVolatile())
27962794
NewLI->setAtomic(LI.getOrdering(), LI.getSyncScopeID());
27972795
if (NewLI->isAtomic())
27982796
NewLI->setAlignment(LI.getAlign());
27992797

2800-
// Any !nonnull metadata or !range metadata on the old load is also valid
2801-
// on the new load. This is even true in some cases even when the loads
2802-
// are different types, for example by mapping !nonnull metadata to
2803-
// !range metadata by modeling the null pointer constant converted to the
2804-
// integer type.
2805-
// FIXME: Add support for range metadata here. Currently the utilities
2806-
// for this don't propagate range metadata in trivial cases from one
2807-
// integer load to another, don't handle non-addrspace-0 null pointers
2808-
// correctly, and don't have any support for mapping ranges as the
2809-
// integer type becomes winder or narrower.
2810-
if (MDNode *N = LI.getMetadata(LLVMContext::MD_nonnull))
2811-
copyNonnullMetadata(LI, N, *NewLI);
2798+
// Copy any metadata that is valid for the new load. This may require
2799+
// conversion to a different kind of metadata, e.g. !nonnull might change
2800+
// to !range or vice versa.
2801+
copyMetadataForLoad(*NewLI, LI);
2802+
2803+
// Do this after copyMetadataForLoad() to preserve the TBAA shift.
2804+
if (AATags)
2805+
NewLI->setAAMetadata(AATags.shift(NewBeginOffset - BeginOffset));
28122806

28132807
// Try to preserve nonnull metadata
28142808
V = NewLI;

llvm/test/Transforms/SROA/preserve-metadata.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ define ptr @propagate_noundef(ptr %v) {
4747
; CHECK-NEXT: entry:
4848
; CHECK-NEXT: [[A_SROA_1:%.*]] = alloca ptr, align 8
4949
; CHECK-NEXT: store ptr [[V:%.*]], ptr [[A_SROA_1]], align 8
50-
; CHECK-NEXT: [[A_SROA_1_0_A_SROA_1_8_LOAD:%.*]] = load volatile ptr, ptr [[A_SROA_1]], align 8
50+
; CHECK-NEXT: [[A_SROA_1_0_A_SROA_1_8_LOAD:%.*]] = load volatile ptr, ptr [[A_SROA_1]], align 8, !noundef !0
5151
; CHECK-NEXT: ret ptr [[A_SROA_1_0_A_SROA_1_8_LOAD]]
5252
;
5353
entry:

0 commit comments

Comments
 (0)