Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "llvm/IR/PatternMatch.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"

Expand Down Expand Up @@ -644,6 +645,42 @@ static Value *promoteAllocaUserToVector(Instruction *Inst, const DataLayout &DL,
auto *SubVecTy = FixedVectorType::get(VecEltTy, NumLoadedElts);
assert(DL.getTypeStoreSize(SubVecTy) == DL.getTypeStoreSize(AccessTy));

// If idx is dynamic, then sandwich load with bitcasts.
// ie. CurValTy SubVecTy AccessTy
// <64 x i8> -> <16 x i8> <8 x i16>
// <64 x i8> -> <4 x i128> -> i128 -> <8 x i16>
// Extracting subvector with dynamic index has very large expansion in
// the amdgpu backend. Limit to pow2 for UDiv.
FixedVectorType *AccessVecTy = cast<FixedVectorType>(AccessTy);
FixedVectorType *VectorTy = AA.Vector.Ty;
uint64_t NumBits =
SubVecTy->getScalarSizeInBits() * SubVecTy->getNumElements();
uint64_t LoadAlign = cast<LoadInst>(Inst)->getAlign().value();
if (!isa<ConstantInt>(Index) && SubVecTy->isIntOrIntVectorTy() &&
Comment thread
choikwa marked this conversation as resolved.
Outdated
llvm::isPowerOf2_32(SubVecTy->getNumElements()) &&
VectorTy->getNumElements() % SubVecTy->getNumElements() == 0 &&
Comment thread
choikwa marked this conversation as resolved.
Outdated
llvm::isPowerOf2_32(AccessVecTy->getNumElements()) &&
NumBits <= (LoadAlign * 8u)) {
IntegerType *NewElemType = Builder.getIntNTy(NumBits);
const unsigned NewNumElts = VectorTy->getNumElements() *
Comment thread
choikwa marked this conversation as resolved.
Outdated
VectorTy->getScalarSizeInBits() /
NewElemType->getScalarSizeInBits();
const unsigned IndexDivisor = VectorTy->getNumElements() / NewNumElts;
assert(VectorTy->getScalarSizeInBits() <
NewElemType->getScalarSizeInBits() &&
"New element type should be bigger");
Comment thread
choikwa marked this conversation as resolved.
Outdated
assert(IndexDivisor > 0u && "Zero index divisor");
Comment thread
choikwa marked this conversation as resolved.
Outdated
FixedVectorType *BitCastType =
FixedVectorType::get(NewElemType, NewNumElts);
Value *BCVal = Builder.CreateBitCast(CurVal, BitCastType);
Value *NewIdx = Builder.CreateUDiv(
Comment thread
choikwa marked this conversation as resolved.
Outdated
Index, ConstantInt::get(Index->getType(), IndexDivisor));
Value *ExtVal = Builder.CreateExtractElement(BCVal, NewIdx);
Value *BCOut = Builder.CreateBitCast(ExtVal, AccessTy);
Inst->replaceAllUsesWith(BCOut);
return nullptr;
}

Value *SubVec = PoisonValue::get(SubVecTy);
for (unsigned K = 0; K < NumLoadedElts; ++K) {
Value *CurIdx =
Expand Down
Loading