Skip to content

Commit 2f0daaf

Browse files
jfuentessys_zuul
authored andcommitted
Pattern matching for immediate offset
Change-Id: Idb07d848819a688276157af4d90b9ad91530ea63
1 parent a558ecd commit 2f0daaf

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8513,9 +8513,9 @@ getMsgBlockSizes(unsigned sizeInBits, unsigned alignInBits) {
85138513
return std::make_pair(~0U, ~0U);
85148514
}
85158515

8516-
void EmitPass::emitLoad(LoadInst* inst)
8516+
void EmitPass::emitLoad(LoadInst* inst, Value* offset, ConstantInt* immOffset)
85178517
{
8518-
emitVectorLoad(inst, inst->getPointerOperand());
8518+
emitVectorLoad(inst, offset, immOffset);
85198519
}
85208520

85218521
void EmitPass::EmitNoModifier(llvm::Instruction* inst)
@@ -8558,10 +8558,10 @@ void EmitPass::EmitNoModifier(llvm::Instruction* inst)
85588558
}
85598559
break;
85608560
case Instruction::Store:
8561-
emitStore(cast<StoreInst>(inst));
8561+
emitStore(cast<StoreInst>(inst), nullptr, nullptr);
85628562
break;
85638563
case Instruction::Load:
8564-
emitLoad(cast<LoadInst>(inst));
8564+
emitLoad(cast<LoadInst>(inst), nullptr, nullptr);
85658565
break;
85668566
case Instruction::GetElementPtr:
85678567
emitGEP(cast<GetElementPtrInst>(inst));
@@ -9632,9 +9632,9 @@ void EmitPass::emitStore3DInner(Value* pllValToStore, Value* pllDstPtr, Value* p
96329632
}
96339633
}
96349634

9635-
void EmitPass::emitStore(StoreInst* inst)
9635+
void EmitPass::emitStore(StoreInst* inst, Value* offset, ConstantInt* immOffset)
96369636
{
9637-
emitVectorStore(inst);
9637+
emitVectorStore(inst, offset, immOffset);
96389638
}
96399639

96409640
CVariable* EmitPass::GetSymbol(llvm::Value* v)
@@ -13360,15 +13360,20 @@ unsigned int EmitPass::GetScalarTypeSizeInRegister(Type* Ty) const
1336013360
}
1336113361

1336213362

13363-
void EmitPass::emitVectorLoad(LoadInst* inst, Value* offset)
13363+
void EmitPass::emitVectorLoad(LoadInst* inst, Value* offset, ConstantInt* immOffset)
1336413364
{
13365+
int immOffsetInt = 0;
13366+
if (immOffset)
13367+
immOffsetInt = static_cast<int>(immOffset->getSExtValue());
13368+
1336513369
Value* Ptr = inst->getPointerOperand();
1336613370
PointerType* ptrType = cast<PointerType>(Ptr->getType());
1336713371
bool useA32 = !IGC::isA64Ptr(ptrType, m_currShader->GetContext());
1336813372

1336913373
ResourceDescriptor resource = GetResourceVariable(Ptr);
1337013374
// eOffset is in bytes as 2/19/14
13371-
CVariable* eOffset = GetSymbol(offset);
13375+
// offset corresponds to Int2Ptr operand obtained during pattern matching
13376+
CVariable* eOffset = GetSymbol(immOffset ? offset : Ptr);
1337213377
if (useA32)
1337313378
{
1337413379
eOffset = TruncatePointer(eOffset);
@@ -13786,8 +13791,12 @@ void EmitPass::emitVectorLoad(LoadInst* inst, Value* offset)
1378613791
}
1378713792
}
1378813793

13789-
void EmitPass::emitVectorStore(StoreInst* inst)
13794+
void EmitPass::emitVectorStore(StoreInst* inst, Value* offset, ConstantInt* immOffset)
1379013795
{
13796+
int immOffsetInt = 0;
13797+
if (immOffset)
13798+
immOffsetInt = static_cast<int>(immOffset->getSExtValue());
13799+
1379113800
Value* Ptr = inst->getPointerOperand();
1379213801
PointerType* ptrType = cast<PointerType>(Ptr->getType());
1379313802

@@ -13797,7 +13806,8 @@ void EmitPass::emitVectorStore(StoreInst* inst)
1379713806
ForceDMask(false);
1379813807
}
1379913808
// As 2/19/14, eOffset is in bytes !
13800-
CVariable* eOffset = GetSymbol(Ptr);
13809+
// offset corresponds to Int2Ptr operand obtained during pattern matching
13810+
CVariable* eOffset = GetSymbol(immOffset ? offset : Ptr);
1380113811
bool useA32 = !isA64Ptr(ptrType, m_currShader->GetContext());
1380213812
if (useA32)
1380313813
{

IGC/Compiler/CISACodeGen/EmitVISAPass.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ namespace IGC
147147
void emitSampleOffset(llvm::GenIntrinsicInst* inst);
148148

149149
// TODO: unify the functions below and clean up
150-
void emitStore(llvm::StoreInst* inst);
150+
void emitStore(llvm::StoreInst* inst, llvm::Value* offset = nullptr, llvm::ConstantInt* immOffset = nullptr);
151151
void emitStore3D(llvm::StoreInst* inst, llvm::Value* elemIdxV = nullptr);
152152
void emitStore3DInner(llvm::Value* pllValToStore, llvm::Value* pllDstPtr, llvm::Value* pllElmIdx);
153153

154-
void emitLoad(llvm::LoadInst* inst); // single load, no pattern
154+
void emitLoad(llvm::LoadInst* inst, llvm::Value* offset = nullptr, llvm::ConstantInt* immOffset = nullptr); // single load, no pattern
155155
void emitLoad3DInner(llvm::LdRawIntrinsic* inst, ResourceDescriptor& resource, llvm::Value* elemIdxV);
156156

157157
// when resource is dynamically indexed, load/store must use special intrinsics
@@ -377,8 +377,8 @@ namespace IGC
377377
// non-vector version.
378378
bool isUniformStoreOCL(llvm::StoreInst* SI);
379379
void emitVectorBitCast(llvm::BitCastInst* BCI);
380-
void emitVectorLoad(llvm::LoadInst* LI, llvm::Value* offset);
381-
void emitVectorStore(llvm::StoreInst* SI);
380+
void emitVectorLoad(llvm::LoadInst* LI, llvm::Value* offset, llvm::ConstantInt* immOffset);
381+
void emitVectorStore(llvm::StoreInst* SI, llvm::Value* offset, llvm::ConstantInt* immOffset);
382382
void emitGenISACopy(llvm::GenIntrinsicInst* GenCopyInst);
383383
void emitVectorCopy(CVariable* Dst, CVariable* Src, uint32_t nElts,
384384
uint32_t DstSubRegOffset = 0, uint32_t SrcSubRegOffset = 0);

IGC/Compiler/CISACodeGen/PatternMatchPass.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2051,17 +2051,19 @@ namespace IGC
20512051
return false;
20522052
}
20532053

2054+
20542055
bool CodeGenPatternMatch::MatchLoadStorePointer(llvm::Instruction& I, llvm::Value& ptrVal)
20552056
{
20562057
struct LoadStorePointerPattern : public Pattern
20572058
{
20582059
Instruction* inst;
20592060
Value* offset;
2061+
ConstantInt* immOffset;
20602062
virtual void Emit(EmitPass* pass, const DstModifier& modifier)
20612063
{
20622064
if (isa<LoadInst>(inst))
20632065
{
2064-
pass->emitVectorLoad(cast<LoadInst>(inst), offset);
2066+
pass->emitVectorLoad(cast<LoadInst>(inst), offset, immOffset);
20652067
}
20662068
else if (isa<StoreInst>(inst))
20672069
{
@@ -2097,6 +2099,7 @@ namespace IGC
20972099
}
20982100
}
20992101
pattern->offset = cast<Instruction>(&ptrVal)->getOperand(0);
2102+
pattern->immOffset = ConstantInt::get(Type::getInt32Ty(I.getContext()), 0);
21002103
MarkAsSource(pattern->offset);
21012104
AddPattern(pattern);
21022105
return true;

0 commit comments

Comments
 (0)