Skip to content

Commit ff92f23

Browse files
mshelegoigcbot
authored andcommitted
IGCLLVM::getNonOpaquePtrEltTy elimination in CMPacketize
This change is a part of the effort to support opaque pointers in newer LLVM versions
1 parent c4cf26e commit ff92f23

File tree

4 files changed

+59
-62
lines changed

4 files changed

+59
-62
lines changed

IGC/VectorCompiler/lib/GenXOpts/CMPacketize/GenXPacketize.cpp

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -848,15 +848,15 @@ Value *GenXPacketize::packetizeLLVMInstruction(Instruction *Inst) {
848848
Inst->getType()->getPointerAddressSpace());
849849
else {
850850
// Map <N x OldTy>* to <N x NewTy*> using cast then GEP
851-
auto *TmpTy =
852-
PointerType::get(llvm::ArrayType::get(DstScalarTy, B->VWidth),
853-
Inst->getType()->getPointerAddressSpace());
851+
auto *TmpTy = llvm::ArrayType::get(DstScalarTy, B->VWidth);
852+
auto *TmpPtrTy = PointerType::get(
853+
TmpTy, Inst->getType()->getPointerAddressSpace());
854854
auto *TmpInst =
855-
B->CAST((Instruction::CastOps)Opcode, PacketizedSrc, TmpTy);
855+
B->CAST((Instruction::CastOps)Opcode, PacketizedSrc, TmpPtrTy);
856856
SmallVector<Value *, 2> VecIndices;
857857
VecIndices.push_back(B->C(0));
858858
VecIndices.push_back(B->CInc<uint32_t>(0, B->VWidth));
859-
ReplacedInst = B->GEPA(TmpInst, VecIndices);
859+
ReplacedInst = B->GEPA(TmpTy, TmpInst, VecIndices);
860860
break;
861861
}
862862
}
@@ -869,31 +869,26 @@ Value *GenXPacketize::packetizeLLVMInstruction(Instruction *Inst) {
869869
}
870870
case Instruction::GetElementPtr: {
871871
auto *GepInst = cast<GetElementPtrInst>(Inst);
872-
auto *Base = GepInst->getPointerOperand();
873-
Value *VecSrc = nullptr;
874-
if (isa<GlobalValue>(Base))
875-
VecSrc = Base;
876-
else if (isa<Argument>(Base))
877-
VecSrc = Base;
878-
else if (isa<Instruction>(Base) &&
879-
UniformInsts.count(cast<Instruction>(Base)))
880-
VecSrc = Base;
881-
else
882-
VecSrc = getPacketizeValue(Base);
872+
auto *VecSrc = GepInst->getPointerOperand();
873+
auto *VecSrcTy = GepInst->getSourceElementType();
874+
if (!isa<GlobalValue>(VecSrc) && !isa<Argument>(VecSrc) &&
875+
!(isa<Instruction>(VecSrc) &&
876+
UniformInsts.count(cast<Instruction>(VecSrc))))
877+
VecSrc = getPacketizeValue(VecSrc);
883878
if (!isa<AllocaInst>(VecSrc)) {
884879
// just packetize the GEP to a vector GEP.
885880
SmallVector<Value *, 8> VecIndices;
886881
for (uint32_t Idx = 0; Idx < GepInst->getNumIndices(); ++Idx)
887882
VecIndices.push_back(getPacketizeValue(GepInst->getOperand(1 + Idx)));
888-
ReplacedInst = B->GEPA(VecSrc, VecIndices);
883+
ReplacedInst = B->GEPA(VecSrcTy, VecSrc, VecIndices);
889884
} else {
890885
if (GepInst->hasAllConstantIndices()) {
891886
// SOA GEP with scalar src and constant indices, result will be <N x
892887
// Ty>* Ex. gep [4 x <8 x float>]*, 0, 0 --> <8 x float>*
893888
SmallVector<Value *, 8> VecIndices;
894889
for (uint32_t Idx = 0; Idx < GepInst->getNumIndices(); ++Idx)
895890
VecIndices.push_back(GepInst->getOperand(1 + Idx));
896-
ReplacedInst = B->GEPA(VecSrc, VecIndices);
891+
ReplacedInst = B->GEPA(VecSrcTy, VecSrc, VecIndices);
897892
} else {
898893
//// SOA GEP with non-uniform indices. Need to vector GEP to each SIMD
899894
/// lane.
@@ -903,22 +898,22 @@ Value *GenXPacketize::packetizeLLVMInstruction(Instruction *Inst) {
903898
VecIndices.push_back(getPacketizeValue(GepInst->getOperand(1 + Idx)));
904899
// Step to the SIMD lane
905900
VecIndices.push_back(B->CInc<uint32_t>(0, B->VWidth));
906-
ReplacedInst = B->GEPA(VecSrc, VecIndices);
901+
ReplacedInst = B->GEPA(VecSrcTy, VecSrc, VecIndices);
907902
}
908903
}
909904
break;
910905
}
911906
case Instruction::Load: {
912907
auto *LI = cast<LoadInst>(Inst);
913-
auto *Src = LI->getPointerOperand();
914-
auto *VecSrc = getPacketizeValue(Src);
908+
auto *VecSrc = getPacketizeValue(LI->getPointerOperand());
909+
auto *VecSrcTy = B->getVectorType(LI->getType());
915910
if (VecSrc->getType()->isVectorTy()) {
916911
IGC_ASSERT(
917912
cast<VectorType>(VecSrc->getType())->getElementType()->isPointerTy());
918913
auto Align = IGCLLVM::getAlignmentValue(LI);
919-
ReplacedInst = B->MASKED_GATHER(VecSrc, Align);
914+
ReplacedInst = B->MASKED_GATHER(VecSrcTy, VecSrc, Align);
920915
} else
921-
ReplacedInst = B->ALIGNED_LOAD(VecSrc, IGCLLVM::getAlign(*LI));
916+
ReplacedInst = B->ALIGNED_LOAD(VecSrcTy, VecSrc, IGCLLVM::getAlign(*LI));
922917
break;
923918
}
924919
case Instruction::Store: {
@@ -1068,15 +1063,15 @@ Value *GenXPacketize::packetizeLLVMInstruction(Instruction *Inst) {
10681063
} else {
10691064
// vector struct input, need to loop over components and build up new
10701065
// struct allocation
1071-
auto *Alloca = B->ALLOCA(
1072-
B->getVectorType(IGCLLVM::getNonOpaquePtrEltTy(Inst->getType())));
1073-
uint32_t NumElems =
1074-
IGCLLVM::getNonOpaquePtrEltTy(Inst->getType())->getArrayNumElements();
1066+
auto *Ty = IGCLLVM::getNonOpaquePtrEltTy(Inst->getType());
1067+
auto *VecTy = B->getVectorType(Ty);
1068+
auto *Alloca = B->ALLOCA(VecTy);
1069+
uint32_t NumElems = Ty->getArrayNumElements();
10751070
for (uint32_t Idx = 0; Idx < NumElems; ++Idx) {
1076-
auto *TrueSrcElem = B->LOAD(TrueSrc, {0, Idx});
1077-
auto *FalseSrcElem = B->LOAD(FalseSrc, {0, Idx});
1071+
auto *TrueSrcElem = B->LOAD(VecTy, TrueSrc, {0, Idx});
1072+
auto *FalseSrcElem = B->LOAD(VecTy, FalseSrc, {0, Idx});
10781073
// mask store true components
1079-
auto *GEP = B->GEP(Alloca, {0, Idx});
1074+
auto *GEP = B->GEP(VecTy, Alloca, {0, Idx});
10801075
B->MASKED_STORE(TrueSrcElem, GEP, 4, VecCond);
10811076
// store false components to inverted mask
10821077
B->MASKED_STORE(FalseSrcElem, GEP, 4, B->NOT(VecCond));
@@ -1743,7 +1738,7 @@ void GenXPacketize::fixupLLVMIntrinsics(Function &F) {
17431738
GlobalVariable *GenXPacketize::findGlobalExecMask() {
17441739
// look for the global EMask variable if exists
17451740
for (auto &Global : M->getGlobalList()) {
1746-
auto *Ty = IGCLLVM::getNonOpaquePtrEltTy(Global.getType());
1741+
auto *Ty = Global.getValueType();
17471742
if (Ty->isVectorTy() &&
17481743
cast<IGCLLVM::FixedVectorType>(Ty)->getNumElements() ==
17491744
CMSimdCFLower::MAX_SIMD_CF_WIDTH) {

IGC/VectorCompiler/lib/GenXOpts/CMPacketize/PacketBuilder.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,24 +157,21 @@ struct PacketBuilder {
157157
void assertMemoryUsageParams(Value *Ptr);
158158

159159
public:
160-
virtual Value *GEP(Value *Ptr,
161-
const std::initializer_list<uint32_t> &IndexList,
162-
Type *Ty = nullptr);
163-
164-
Value *GEPA(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &Name = "");
165-
166-
virtual LoadInst *LOAD(Value *Ptr, const Twine &Name = "", Type *Ty = nullptr);
167-
168-
virtual LoadInst *LOAD(Value *BasePtr,
160+
GetElementPtrInst *GEP(Type *Ty, Value *Ptr,
169161
const std::initializer_list<uint32_t> &IndexList,
170-
const llvm::Twine &Name = "", Type *Ty = nullptr);
171-
172-
LoadInst *ALIGNED_LOAD(Value *Ptr, IGCLLVM::Align Align,
162+
const Twine &Name = "");
163+
GetElementPtrInst *GEPA(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
164+
const Twine &Name = "");
165+
LoadInst *LOAD(Type *Ty, Value *Ptr, const Twine &Name = "");
166+
LoadInst *LOAD(Type *Ty, Value *BasePtr,
167+
const std::initializer_list<uint32_t> &IndexList,
168+
const llvm::Twine &Name = "");
169+
LoadInst *ALIGNED_LOAD(Type *Ty, Value *Ptr, IGCLLVM::Align Align,
173170
const Twine &Name = "");
174171
AllocaInst *ALLOCA(Type *Ty, Value *ArraySize = nullptr,
175172
const Twine &Name = "");
176173
Value *INT_TO_PTR(Value *V, Type *DestTy, const Twine &Name = "");
177-
CallInst *MASKED_GATHER(Value *Ptrs, unsigned Align, Value *Mask = nullptr,
174+
CallInst *MASKED_GATHER(Type *Ty, Value *Ptrs, unsigned Align, Value *Mask = nullptr,
178175
Value *PassThru = nullptr, const Twine &Name = "");
179176
CallInst *MASKED_SCATTER(Value *Val, Value *Ptrs, unsigned Align,
180177
Value *Mask = nullptr);

IGC/VectorCompiler/lib/GenXOpts/CMPacketize/PacketBuilder_mem.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,39 @@ void PacketBuilder::assertMemoryUsageParams(Value *Ptr) {
1717
"through BuilderGfxMem.");
1818
}
1919

20-
Value *PacketBuilder::GEP(Value *Ptr,
21-
const std::initializer_list<uint32_t> &IndexList,
22-
Type *Ty) {
20+
GetElementPtrInst *
21+
PacketBuilder::GEP(Type *Ty, Value *Ptr,
22+
const std::initializer_list<uint32_t> &IndexList,
23+
const Twine &Name) {
2324
std::vector<Value *> Indices;
2425
for (auto Idx : IndexList)
2526
Indices.push_back(C(Idx));
26-
return GEPA(Ptr, Indices);
27+
return GEPA(Ty, Ptr, Indices, Name);
2728
}
2829

29-
Value *PacketBuilder::GEPA(Value *Ptr, ArrayRef<Value *> IdxList,
30-
const Twine &Name) {
31-
return IRB->CreateGEP(Ptr, IdxList, Name);
30+
GetElementPtrInst *PacketBuilder::GEPA(Type *Ty, Value *Ptr,
31+
ArrayRef<Value *> IdxList,
32+
const Twine &Name) {
33+
return cast<GetElementPtrInst>(IRB->CreateGEP(Ty, Ptr, IdxList, Name));
3234
}
3335

34-
LoadInst *PacketBuilder::LOAD(Value *Ptr, const Twine &Name, Type *Ty) {
36+
LoadInst *PacketBuilder::LOAD(Type *Ty, Value *Ptr, const Twine &Name) {
3537
assertMemoryUsageParams(Ptr);
36-
return IRB->CreateLoad(Ptr, Name);
38+
return IRB->CreateLoad(Ty, Ptr, Name);
3739
}
3840

39-
LoadInst *PacketBuilder::LOAD(Value *BasePtr,
41+
LoadInst *PacketBuilder::LOAD(Type *Ty, Value *BasePtr,
4042
const std::initializer_list<uint32_t> &IndexList,
41-
const llvm::Twine &Name, Type *Ty) {
43+
const llvm::Twine &Name) {
4244
std::vector<Value *> Indices;
4345
for (auto Idx : IndexList)
4446
Indices.push_back(C(Idx));
45-
return PacketBuilder::LOAD(GEPA(BasePtr, Indices), Name);
47+
auto *GEPInst = GEPA(Ty, BasePtr, Indices);
48+
return PacketBuilder::LOAD(GEPInst->getSourceElementType(), GEPInst, Name);
4649
}
4750

48-
LoadInst *PacketBuilder::ALIGNED_LOAD(Value *Ptr, IGCLLVM::Align Align,
51+
LoadInst *PacketBuilder::ALIGNED_LOAD(Type *Ty, Value *Ptr, IGCLLVM::Align Align,
4952
const Twine &Name) {
50-
auto *Ty = IGCLLVM::getNonOpaquePtrEltTy(Ptr->getType());
5153
return IRB->CreateAlignedLoad(Ty, Ptr, Align, Name);
5254
}
5355

@@ -60,11 +62,12 @@ Value *PacketBuilder::INT_TO_PTR(Value *V, Type *DestTy, const Twine &Name) {
6062
return IRB->CreateIntToPtr(V, DestTy, Name);
6163
}
6264

63-
CallInst *PacketBuilder::MASKED_GATHER(Value *Ptrs, unsigned Align, Value *Mask,
64-
Value *PassThru, const Twine &Name) {
65+
CallInst *PacketBuilder::MASKED_GATHER(Type *Ty, Value *Ptrs, unsigned Align,
66+
Value *Mask, Value *PassThru,
67+
const Twine &Name) {
6568
return IRB->CreateMaskedGather(
66-
Ptrs, IGCLLVM::getAlignmentValueIfNeeded(IGCLLVM::getAlign(Align)), Mask,
67-
PassThru, Name);
69+
Ty, Ptrs, IGCLLVM::getAlignmentValueIfNeeded(IGCLLVM::getAlign(Align)),
70+
Mask, PassThru, Name);
6871
}
6972

7073
CallInst *PacketBuilder::MASKED_SCATTER(Value *Val, Value *Ptrs, unsigned Align,

IGC/WrapperLLVM/include/llvmWrapper/IR/IRBuilder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ namespace IGCLLVM
253253
Ty, Ptrs, Alignment, Mask, PassThru, Name);
254254
}
255255

256+
using llvm::IRBuilder<T, InserterTyDef()>::CreateMaskedGather;
257+
256258
llvm::AtomicCmpXchgInst *
257259
CreateAtomicCmpXchg(llvm::Value *Ptr, llvm::Value *Cmp, llvm::Value *New,
258260
llvm::AtomicOrdering SuccessOrdering,

0 commit comments

Comments
 (0)