diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -4081,13 +4081,16 @@ if (isa(Ops[0])) return UndefValue::get(GEPTy); + bool IsScalableVec = + SrcTy->isVectorTy() ? SrcTy->getVectorIsScalable() : false; + if (Ops.size() == 2) { // getelementptr P, 0 -> P. if (match(Ops[1], m_Zero()) && Ops[0]->getType() == GEPTy) return Ops[0]; Type *Ty = SrcTy; - if (Ty->isSized()) { + if (!IsScalableVec && Ty->isSized()) { Value *P; uint64_t C; uint64_t TyAllocSize = Q.DL.getTypeAllocSize(Ty); @@ -4135,7 +4138,7 @@ } } - if (Q.DL.getTypeAllocSize(LastType) == 1 && + if (!IsScalableVec && Q.DL.getTypeAllocSize(LastType) == 1 && all_of(Ops.slice(1).drop_back(1), [](Value *Idx) { return match(Idx, m_Zero()); })) { unsigned IdxWidth = diff --git a/llvm/test/Transforms/InstSimplify/vscale.ll b/llvm/test/Transforms/InstSimplify/vscale.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/InstSimplify/vscale.ll @@ -0,0 +1,23 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -S -instsimplify -verify < %s | FileCheck %s + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Memory Access and Addressing Operations +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +define @getelementptr_1() { +; CHECK-LABEL: @getelementptr_1( +; CHECK-NEXT: ret zeroinitializer +; + %ptr = getelementptr i32, zeroinitializer, undef + ret %ptr +} + +define *> @getelementptr_2() { +; CHECK-LABEL: @getelementptr_2( +; CHECK-NEXT: ret *> zeroinitializer +; + %ptr = getelementptr , * null, undef + ret *> %ptr +} +