[llvm] a4898b4 - [Local] Preserve range metadata if the type did not change
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 20 06:28:40 PST 2023
Author: Nikita Popov
Date: 2023-01-20T15:28:32+01:00
New Revision: a4898b437dbd76bf62c6fc2c5f015c327aa19190
URL: https://github.com/llvm/llvm-project/commit/a4898b437dbd76bf62c6fc2c5f015c327aa19190
DIFF: https://github.com/llvm/llvm-project/commit/a4898b437dbd76bf62c6fc2c5f015c327aa19190.diff
LOG: [Local] Preserve range metadata if the type did not change
In copyRangeMetadata() and by extension copyLoadMetadata(),
handle the trivial case where the type did not change, in which
case we can simply preserve the range metadata as is.
Added:
Modified:
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/Transforms/SROA/preserve-metadata.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index a57035d165ed..31cdd2ee56b9 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -2916,6 +2916,11 @@ void llvm::copyNonnullMetadata(const LoadInst &OldLI, MDNode *N,
void llvm::copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI,
MDNode *N, LoadInst &NewLI) {
auto *NewTy = NewLI.getType();
+ // Simply copy the metadata if the type did not change.
+ if (NewTy == OldLI.getType()) {
+ NewLI.setMetadata(LLVMContext::MD_range, N);
+ return;
+ }
// Give up unless it is converted to a pointer where there is a single very
// valuable mapping we can do reliably.
diff --git a/llvm/test/Transforms/SROA/preserve-metadata.ll b/llvm/test/Transforms/SROA/preserve-metadata.ll
index f8a21604776b..1308c298cd6b 100644
--- a/llvm/test/Transforms/SROA/preserve-metadata.ll
+++ b/llvm/test/Transforms/SROA/preserve-metadata.ll
@@ -30,7 +30,7 @@ define i32 @propagate_range(i32 %v) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[A_SROA_1:%.*]] = alloca i32, align 4
; CHECK-NEXT: store i32 [[V:%.*]], ptr [[A_SROA_1]], align 4
-; CHECK-NEXT: [[A_SROA_1_0_A_SROA_1_4_LOAD:%.*]] = load volatile i32, ptr [[A_SROA_1]], align 4
+; CHECK-NEXT: [[A_SROA_1_0_A_SROA_1_4_LOAD:%.*]] = load volatile i32, ptr [[A_SROA_1]], align 4, !range [[RNG1:![0-9]+]]
; CHECK-NEXT: ret i32 [[A_SROA_1_0_A_SROA_1_4_LOAD]]
;
entry:
More information about the llvm-commits
mailing list