diff options
author | Nikita Popov <npopov@redhat.com> | 2023-03-31 12:18:02 +0200 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2023-04-04 11:57:30 -0700 |
commit | c3591d714b49c52d4726f376e6f52db481fd8900 (patch) | |
tree | 2c6ff6384469cd6d2aa02ba4bd7e6b9b098f62eb | |
parent | dae44c8ccc84ef557b646164c185fcda6c15eb5f (diff) |
[Local] Handle size mismatch between pointer/int in copyRangeMetadata()
SROA may convert a wide integer load into a narrow pointer load,
make sure we don't crash. It would not be legal to transfer the
metadata in this case.
(cherry picked from commit fc6e91fe8184129d2395b79ce42f4495b95b0d0d)
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 3 | ||||
-rw-r--r-- | llvm/test/Transforms/SROA/preserve-metadata.ll | 18 |
2 files changed, 20 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 31cdd2ee56b9..b2ed95b05e04 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2930,7 +2930,8 @@ void llvm::copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, return; unsigned BitWidth = DL.getPointerTypeSizeInBits(NewTy); - if (!getConstantRangeFromMetadata(*N).contains(APInt(BitWidth, 0))) { + if (BitWidth == OldLI.getType()->getScalarSizeInBits() && + !getConstantRangeFromMetadata(*N).contains(APInt(BitWidth, 0))) { MDNode *NN = MDNode::get(OldLI.getContext(), std::nullopt); NewLI.setMetadata(LLVMContext::MD_nonnull, NN); } diff --git a/llvm/test/Transforms/SROA/preserve-metadata.ll b/llvm/test/Transforms/SROA/preserve-metadata.ll index 6910a4c0e6ba..ba8fbc8efc37 100644 --- a/llvm/test/Transforms/SROA/preserve-metadata.ll +++ b/llvm/test/Transforms/SROA/preserve-metadata.ll @@ -128,6 +128,24 @@ entry: ret ptr %load } +define i128 @load_i128_to_load_ptr() { +; CHECK-LABEL: @load_i128_to_load_ptr( +; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr null to i64 +; CHECK-NEXT: [[A_SROA_2_0_INSERT_EXT:%.*]] = zext i64 undef to i128 +; CHECK-NEXT: [[A_SROA_2_0_INSERT_SHIFT:%.*]] = shl i128 [[A_SROA_2_0_INSERT_EXT]], 64 +; CHECK-NEXT: [[A_SROA_2_0_INSERT_MASK:%.*]] = and i128 undef, 18446744073709551615 +; CHECK-NEXT: [[A_SROA_2_0_INSERT_INSERT:%.*]] = or i128 [[A_SROA_2_0_INSERT_MASK]], [[A_SROA_2_0_INSERT_SHIFT]] +; CHECK-NEXT: [[A_SROA_0_0_INSERT_EXT:%.*]] = zext i64 [[TMP1]] to i128 +; CHECK-NEXT: [[A_SROA_0_0_INSERT_MASK:%.*]] = and i128 [[A_SROA_2_0_INSERT_INSERT]], -18446744073709551616 +; CHECK-NEXT: [[A_SROA_0_0_INSERT_INSERT:%.*]] = or i128 [[A_SROA_0_0_INSERT_MASK]], [[A_SROA_0_0_INSERT_EXT]] +; CHECK-NEXT: ret i128 [[A_SROA_0_0_INSERT_INSERT]] +; + %a = alloca i128 + store ptr null, ptr %a + %v = load i128, ptr %a, !range !{i128 1, i128 0} + ret i128 %v +} + !0 = !{} ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line: ; CHECK-MODIFY-CFG: {{.*}} |