[PATCH] D26014: [ConstantFold] Get the correct vector type when folding a getelementptr instruction with vector indices

Filipe Cabecinhas via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 26 15:23:09 PDT 2016


Can we have mixed integer and vector indices (langref doesn't seem to
forbid it)? If so, what happens if the first one is an integer, and then
you get a vector of indices?

 Filipe

On Wednesday, 26 October 2016, Davide Italiano via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> davide created this revision.
> davide added reviewers: majnemer, Bigcheese, RKSimon, spatel.
> davide added a subscriber: llvm-commits.
>
> When we constant fold `getelementptr` and the indices are vector, the type
> created is `i64 *` and not `<8 x i64*>` which caseuse an assertion to fire
> in `replaceAllUsesWith`. I think it's OK just checking for the first index
> for the reason pointed out in the comment.
>
>
> https://reviews.llvm.org/D26014
>
> Files:
>   lib/IR/ConstantFold.cpp
>   test/Transforms/InstCombine/gep-vector.ll
>
>
> Index: test/Transforms/InstCombine/gep-vector.ll
> ===================================================================
> --- /dev/null
> +++ test/Transforms/InstCombine/gep-vector.ll
> @@ -0,0 +1,19 @@
> +; RUN: opt -instcombine %s -S | FileCheck %s
> +
> +; CHECK-LABEL: patatino
> +; CHECK-NEXT: ret void
> +define void @patatino() {
> +  %el = getelementptr i64, <8 x i64*> undef, <8 x i64> undef
> +  %gather = call <8 x i64> @llvm.masked.gather.v8i64(<8 x i64*> %el, i32
> 8, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true,
> i1 true>, <8 x i64> undef)
> +  ret void
> +}
> +
> +; CHECK-LABEL: patatino2
> +; CHECK-NEXT: ret void
> +define void @patatino2() {
> +  %el = getelementptr inbounds i64, i64* undef, <8 x i64> undef
> +  %gather = call <8 x i64> @llvm.masked.gather.v8i64(<8 x i64*> %el, i32
> 8, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true,
> i1 true>, <8 x i64> undef)
> +  ret void
> +}
> +
> +declare <8 x i64> @llvm.masked.gather.v8i64(<8 x i64*>, i32, <8 x i1>, <8
> x i64>)
> Index: lib/IR/ConstantFold.cpp
> ===================================================================
> --- lib/IR/ConstantFold.cpp
> +++ lib/IR/ConstantFold.cpp
> @@ -2062,6 +2062,12 @@
>      Type *GEPTy = PointerType::get(Ty, PtrTy->getAddressSpace());
>      if (VectorType *VT = dyn_cast<VectorType>(C->getType()))
>        GEPTy = VectorType::get(GEPTy, VT->getNumElements());
> +    // When the getelementptr has one of more vector indices, it will
> +    // return a vector of pointers. We guarantee that all the vectors
> +    // in this case will have the same width, so we can just look at
> +    // the first one.
> +    else if (VectorType *VT = dyn_cast<VectorType>(Idxs[0]->getType()))
> +      GEPTy = VectorType::get(GEPTy, VT->getNumElements());
>      return UndefValue::get(GEPTy);
>    }
>
>
>
>

-- 
  F
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161026/00bdd339/attachment.html>


More information about the llvm-commits mailing list