diff options
author | Nikita Popov <npopov@redhat.com> | 2024-05-01 14:53:43 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-01 14:53:43 +0900 |
commit | 74aa1abfaec64e45a402f4601f9c228113fc0bbb (patch) | |
tree | 07a5486321b1d62542489812997b24994be45161 /llvm/lib | |
parent | 3684a38d33d7643fe8c3a870006efa8677ac37f8 (diff) | |
download | llvm-74aa1abfaec64e45a402f4601f9c228113fc0bbb.zip llvm-74aa1abfaec64e45a402f4601f9c228113fc0bbb.tar.gz llvm-74aa1abfaec64e45a402f4601f9c228113fc0bbb.tar.bz2 |
[InstCombine] Canonicalize scalable GEPs to use llvm.vscale intrinsic (#90569)
Canonicalize getelementptr instructions for scalable vector types into
ptradd representation with an explicit llvm.vscale call. This
representation has better support in BasicAA, which can reason about
llvm.vscale, but not plain scalable GEPs.
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 7356941..b6f8b24 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2711,7 +2711,6 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) { SmallVector<Value *, 8> Indices(GEP.indices()); Type *GEPType = GEP.getType(); Type *GEPEltType = GEP.getSourceElementType(); - bool IsGEPSrcEleScalable = GEPEltType->isScalableTy(); if (Value *V = simplifyGEPInst(GEPEltType, PtrOp, Indices, GEP.isInBounds(), SQ.getWithInstruction(&GEP))) return replaceInstUsesWith(GEP, V); @@ -2787,6 +2786,14 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) { GEP.isInBounds())); } + // Canonicalize scalable GEPs to an explicit offset using the llvm.vscale + // intrinsic. This has better support in BasicAA. + if (GEPEltType->isScalableTy()) { + Value *Offset = EmitGEPOffset(cast<GEPOperator>(&GEP)); + return replaceInstUsesWith( + GEP, Builder.CreatePtrAdd(PtrOp, Offset, "", GEP.isInBounds())); + } + // Check to see if the inputs to the PHI node are getelementptr instructions. if (auto *PN = dyn_cast<PHINode>(PtrOp)) { auto *Op1 = dyn_cast<GetElementPtrInst>(PN->getOperand(0)); @@ -2896,9 +2903,7 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) { if (Instruction *I = visitGEPOfGEP(GEP, Src)) return I; - // Skip if GEP source element type is scalable. The type alloc size is unknown - // at compile-time. - if (GEP.getNumIndices() == 1 && !IsGEPSrcEleScalable) { + if (GEP.getNumIndices() == 1) { unsigned AS = GEP.getPointerAddressSpace(); if (GEP.getOperand(1)->getType()->getScalarSizeInBits() == DL.getIndexSizeInBits(AS)) { |