From: Alex Richardson Date: Tue, 28 Sep 2021 14:10:39 +0000 (+0100) Subject: Fix incorrect GEP bitwidth in areNonOverlapSameBaseLoadAndStore() X-Git-Tag: upstream/15.0.7~30263 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3c51b9e270bac26fdec1b06ae8dd72960a2353a3;p=platform%2Fupstream%2Fllvm.git 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 --- diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp index 1c55f48..2e5f80d 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 0ee1a5f..5570b74 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 M = parseIR(C, R"IR( +target datalayout = "p:64:64:64:32" %class = type <{ i32, i32 }> define i32 @f() {