From a21ce6e9549cc847d63ea579a265151fe939ee68 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Thu, 18 Jul 2019 17:30:27 +0000 Subject: [PATCH] [LAA] Re-check bit-width of pointers after stripping. Summary: - As the pointer stripping now tracks through `addrspacecast`, prepare to handle the bit-width difference from the result pointer. Reviewers: jdoerfert Subscribers: jvesely, nhaehnle, hiraditya, arphaman, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64928 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366470 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/LoopAccessAnalysis.cpp | 15 ++++++++++++++- .../address-space-ptr-sze-gep-index-assert.ll | 13 +++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/Analysis/LoopAccessAnalysis.cpp b/lib/Analysis/LoopAccessAnalysis.cpp index 36bd9a8b7ea..31afecbaa5e 100644 --- a/lib/Analysis/LoopAccessAnalysis.cpp +++ b/lib/Analysis/LoopAccessAnalysis.cpp @@ -1189,12 +1189,25 @@ bool llvm::isConsecutiveAccess(Value *A, Value *B, const DataLayout &DL, unsigned IdxWidth = DL.getIndexSizeInBits(ASA); Type *Ty = cast(PtrA->getType())->getElementType(); - APInt Size(IdxWidth, DL.getTypeStoreSize(Ty)); APInt OffsetA(IdxWidth, 0), OffsetB(IdxWidth, 0); PtrA = PtrA->stripAndAccumulateInBoundsConstantOffsets(DL, OffsetA); PtrB = PtrB->stripAndAccumulateInBoundsConstantOffsets(DL, OffsetB); + // Retrieve the address space again as pointer stripping now tracks through + // `addrspacecast`. + ASA = cast(PtrA->getType())->getAddressSpace(); + ASB = cast(PtrB->getType())->getAddressSpace(); + // Check that the address spaces match and that the pointers are valid. + if (ASA != ASB) + return false; + + IdxWidth = DL.getIndexSizeInBits(ASA); + OffsetA = OffsetA.sextOrTrunc(IdxWidth); + OffsetB = OffsetB.sextOrTrunc(IdxWidth); + + APInt Size(IdxWidth, DL.getTypeStoreSize(Ty)); + // OffsetDelta = OffsetB - OffsetA; const SCEV *OffsetSCEVA = SE.getConstant(OffsetA); const SCEV *OffsetSCEVB = SE.getConstant(OffsetB); diff --git a/test/Transforms/SLPVectorizer/AMDGPU/address-space-ptr-sze-gep-index-assert.ll b/test/Transforms/SLPVectorizer/AMDGPU/address-space-ptr-sze-gep-index-assert.ll index 735ce651ed7..4c904b66f3d 100644 --- a/test/Transforms/SLPVectorizer/AMDGPU/address-space-ptr-sze-gep-index-assert.ll +++ b/test/Transforms/SLPVectorizer/AMDGPU/address-space-ptr-sze-gep-index-assert.ll @@ -147,3 +147,16 @@ bb: store i32 %sub1, i32* undef ret void } + +; CHECK-LABEL: slp_crash_on_addrspacecast +; CHECK: ret void +define void @slp_crash_on_addrspacecast() { +entry: + %0 = getelementptr inbounds i64, i64 addrspace(3)* undef, i32 undef + %p0 = addrspacecast i64 addrspace(3)* %0 to i64* + store i64 undef, i64* %p0, align 8 + %1 = getelementptr inbounds i64, i64 addrspace(3)* undef, i32 undef + %p1 = addrspacecast i64 addrspace(3)* %1 to i64* + store i64 undef, i64* %p1, align 8 + ret void +}