[llvm] 3c51b9e - Fix incorrect GEP bitwidth in areNonOverlapSameBaseLoadAndStore()
Alex Richardson via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 28 09:57:58 PDT 2021
Author: Alex Richardson
Date: 2021-09-28T17:57:36+01:00
New Revision: 3c51b9e270bac26fdec1b06ae8dd72960a2353a3
URL: https://github.com/llvm/llvm-project/commit/3c51b9e270bac26fdec1b06ae8dd72960a2353a3
DIFF: https://github.com/llvm/llvm-project/commit/3c51b9e270bac26fdec1b06ae8dd72960a2353a3.diff
LOG: Fix incorrect GEP bitwidth in areNonOverlapSameBaseLoadAndStore()
When using a datalayout that has pointer index width != pointer size this
code triggers an assertion in Value::stripAndAccumulateConstantOffsets().
I encountered this this while compiling FreeBSD for CHERI-RISC-V.
Also update LoadsTest.cpp to use a DataLayout with index width != pointer
width to ensure this case is tested.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D110406
Added:
Modified:
llvm/lib/Analysis/Loads.cpp
llvm/unittests/Analysis/LoadsTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index 1c55f485aa763..2e5f80d800156 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -451,8 +451,8 @@ static bool areNonOverlapSameBaseLoadAndStore(const Value *LoadPtr,
const Value *StorePtr,
Type *StoreTy,
const DataLayout &DL) {
- APInt LoadOffset(DL.getTypeSizeInBits(LoadPtr->getType()), 0);
- APInt StoreOffset(DL.getTypeSizeInBits(StorePtr->getType()), 0);
+ APInt LoadOffset(DL.getIndexTypeSizeInBits(LoadPtr->getType()), 0);
+ APInt StoreOffset(DL.getIndexTypeSizeInBits(StorePtr->getType()), 0);
const Value *LoadBase = LoadPtr->stripAndAccumulateConstantOffsets(
DL, LoadOffset, /* AllowNonInbounds */ false);
const Value *StoreBase = StorePtr->stripAndAccumulateConstantOffsets(
diff --git a/llvm/unittests/Analysis/LoadsTest.cpp b/llvm/unittests/Analysis/LoadsTest.cpp
index 0ee1a5fa08a32..5570b747a4464 100644
--- a/llvm/unittests/Analysis/LoadsTest.cpp
+++ b/llvm/unittests/Analysis/LoadsTest.cpp
@@ -28,6 +28,7 @@ TEST(LoadsTest, FindAvailableLoadedValueSameBasePtrConstantOffsetsNullAA) {
LLVMContext C;
std::unique_ptr<Module> M = parseIR(C,
R"IR(
+target datalayout = "p:64:64:64:32"
%class = type <{ i32, i32 }>
define i32 @f() {
More information about the llvm-commits
mailing list