[PATCH] D32101: Skip bitcasts while looking for GEP in LoadStoreVectorizer

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 17:18:49 PDT 2017


Ignoring the issue of neededness or not, we have a function to do this
anyway, you would want to use ->stripPointerCasts(), not do it yourself :)


On Fri, Apr 14, 2017 at 4:15 PM, Stanislav Mekhanoshin via Phabricator via
llvm-commits <llvm-commits at lists.llvm.org> wrote:

> rampitec created this revision.
> Herald added subscribers: nhaehnle, wdng, mzolotukhin.
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D32101
>
> Files:
>   lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
>   test/Transforms/LoadStoreVectorizer/AMDGPU/gep-bitcast.ll
>
>
> Index: test/Transforms/LoadStoreVectorizer/AMDGPU/gep-bitcast.ll
> ===================================================================
> --- /dev/null
> +++ test/Transforms/LoadStoreVectorizer/AMDGPU/gep-bitcast.ll
> @@ -0,0 +1,27 @@
> +; RUN: opt -S -mtriple=amdgcn--amdhsa -load-store-vectorizer < %s |
> FileCheck %s
> +
> +; Check that vectorizer can find a GEP through bitcast
> +; CHECK: load <4 x i32>
> +define void @vect_zext_bitcast_idx(float addrspace(1)* %arg1, i32 %base) {
> +  %add1 = add nuw i32 %base, 0
> +  %zext1 = zext i32 %add1 to i64
> +  %gep1 = getelementptr inbounds float, float addrspace(1)* %arg1, i64
> %zext1
> +  %f2i1 = bitcast float addrspace(1)* %gep1 to i32 addrspace(1)*
> +  %load1 = load i32, i32 addrspace(1)* %f2i1, align 4
> +  %add2 = add nuw i32 %base, 1
> +  %zext2 = zext i32 %add2 to i64
> +  %gep2 = getelementptr inbounds float, float addrspace(1)* %arg1, i64
> %zext2
> +  %f2i2 = bitcast float addrspace(1)* %gep2 to i32 addrspace(1)*
> +  %load2 = load i32, i32 addrspace(1)* %f2i2, align 4
> +  %add3 = add nuw i32 %base, 2
> +  %zext3 = zext i32 %add3 to i64
> +  %gep3 = getelementptr inbounds float, float addrspace(1)* %arg1, i64
> %zext3
> +  %f2i3 = bitcast float addrspace(1)* %gep3 to i32 addrspace(1)*
> +  %load3 = load i32, i32 addrspace(1)* %f2i3, align 4
> +  %add4 = add nuw i32 %base, 3
> +  %zext4 = zext i32 %add4 to i64
> +  %gep4 = getelementptr inbounds float, float addrspace(1)* %arg1, i64
> %zext4
> +  %f2i4 = bitcast float addrspace(1)* %gep4 to i32 addrspace(1)*
> +  %load4 = load i32, i32 addrspace(1)* %f2i4, align 4
> +  ret void
> +}
> Index: lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
> ===================================================================
> --- lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
> +++ lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
> @@ -283,8 +283,14 @@
>
>    // Look through GEPs after checking they're the same except for the last
>    // index.
> -  GetElementPtrInst *GEPA = dyn_cast<GetElementPtrInst>(
> getPointerOperand(A));
> -  GetElementPtrInst *GEPB = dyn_cast<GetElementPtrInst>(
> getPointerOperand(B));
> +  Value *SrcPTRA = getPointerOperand(A);
> +  Value *SrcPTRB = getPointerOperand(B);
> +  while (auto *C = dyn_cast<BitCastInst>(SrcPTRA))
> +    SrcPTRA = C->getOperand(0);
> +  while (auto *C = dyn_cast<BitCastInst>(SrcPTRB))
> +    SrcPTRB = C->getOperand(0);
> +  GetElementPtrInst *GEPA = dyn_cast<GetElementPtrInst>(SrcPTRA);
> +  GetElementPtrInst *GEPB = dyn_cast<GetElementPtrInst>(SrcPTRB);
>    if (!GEPA || !GEPB || GEPA->getNumOperands() != GEPB->getNumOperands())
>      return false;
>    unsigned FinalIndex = GEPA->getNumOperands() - 1;
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170414/82928910/attachment.html>


More information about the llvm-commits mailing list