Skip to content

Commit 4b66dc3

Browse files
scottp101igcbot
authored andcommitted
Add names to variables and cleanup
Add names to variables and cleanup
1 parent 40d5e01 commit 4b66dc3

File tree

7 files changed

+198
-25
lines changed

7 files changed

+198
-25
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8922,6 +8922,8 @@ namespace IGC
89228922

89238923
return;
89248924
}
8925+
8926+
unsigned surfaceIndex = 0x0;
89258927
V(vKernel->AppendVISALscUntypedStore(
89268928
subOp,
89278929
lscSfid,
@@ -8932,7 +8934,7 @@ namespace IGC
89328934
addr,
89338935
dataShape,
89348936
globalOffsetOpnd,
8935-
0,
8937+
surfaceIndex,
89368938
addressOpnd,
89378939
src1Opnd));
89388940
}

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9281,13 +9281,15 @@ void EmitPass::EmitGenIntrinsicMessage(llvm::GenIntrinsicInst* inst)
92819281
emitLoadRawIndexed(
92829282
cast<LdRawIntrinsic>(inst),
92839283
cast<LdRawIntrinsic>(inst)->getOffsetValue(),
9284+
nullptr,
92849285
nullptr);
92859286
break;
92869287
case GenISAIntrinsic::GenISA_storerawvector_indexed:
92879288
case GenISAIntrinsic::GenISA_storeraw_indexed:
92889289
emitStoreRawIndexed(
92899290
cast<StoreRawIntrinsic>(inst),
92909291
cast<StoreRawIntrinsic>(inst)->getOffsetValue(),
9292+
nullptr,
92919293
nullptr);
92929294
break;
92939295
case GenISAIntrinsic::GenISA_GetBufferPtr:
@@ -11104,11 +11106,13 @@ void EmitPass::setRovCacheCtrl(GenIntrinsicInst* inst)
1110411106
}
1110511107

1110611108
void EmitPass::emitLoadRawIndexed(
11107-
LdRawIntrinsic * inst, Value * varOffset, ConstantInt * immOffset)
11109+
LdRawIntrinsic* inst,
11110+
Value* varOffset,
11111+
ConstantInt* immScale,
11112+
ConstantInt* immOffset)
1110811113
{
1110911114
Value* bufPtrv = inst->getResourceValue();
1111011115

11111-
ResourceDescriptor resource = GetResourceVariable(bufPtrv);
1111211116
LSC_DOC_ADDR_SPACE addrSpace = m_pCtx->getUserAddrSpaceMD().Get(inst);
1111311117
m_currShader->m_State.isMessageTargetDataCacheDataPort = true;
1111411118
if (shouldGenerateLSC(inst))
@@ -11124,13 +11128,14 @@ void EmitPass::emitLoadRawIndexed(
1112411128
bufPtrv,
1112511129
varOffset,
1112611130
immOffset,
11127-
nullptr,
11131+
immScale,
1112811132
cacheOpts,
1112911133
addrSpace
1113011134
);
1113111135
return;
1113211136
}
1113311137
IGC_ASSERT(immOffset == nullptr);
11138+
ResourceDescriptor resource = GetResourceVariable(bufPtrv);
1113411139
emitLoad3DInner(inst, resource, varOffset);
1113511140
}
1113611141

@@ -12594,7 +12599,10 @@ void EmitPass::emitSymbolRelocation(Function& F)
1259412599
}
1259512600

1259612601
void EmitPass::emitStoreRawIndexed(
12597-
StoreRawIntrinsic* inst, Value* varOffset, ConstantInt* immOffset)
12602+
StoreRawIntrinsic* inst,
12603+
Value* varOffset,
12604+
ConstantInt* immScale,
12605+
ConstantInt* immOffset)
1259812606
{
1259912607
Value* pBufPtr = inst->getResourceValue();
1260012608
Value* pValToStore = inst->getStoreValue();
@@ -12611,7 +12619,7 @@ void EmitPass::emitStoreRawIndexed(
1261112619
pBufPtr,
1261212620
varOffset,
1261312621
immOffset,
12614-
nullptr,
12622+
immScale,
1261512623
pValToStore,
1261612624
inst->getParent(),
1261712625
cacheOpts,
@@ -19656,7 +19664,7 @@ void EmitPass::emitLSCVectorLoad(Instruction* inst,
1965619664
else if (auto CI = dyn_cast<LdRawIntrinsic>(inst))
1965719665
align = CI->getAlignment();
1965819666
PointerType* ptrType = cast<PointerType>(Ptr->getType());
19659-
ResourceDescriptor resource = GetResourceVariable(Ptr);
19667+
ResourceDescriptor resource = GetResourceVariable(Ptr, true);
1966019668
bool useA32 = !IGC::isA64Ptr(ptrType, m_currShader->GetContext());
1966119669
LSC_ADDR_SIZE addrSize = useA32 ? LSC_ADDR_SIZE_32b : LSC_ADDR_SIZE_64b;
1966219670
IGCLLVM::FixedVectorType* VTy = dyn_cast<IGCLLVM::FixedVectorType>(Ty);
@@ -19991,7 +19999,7 @@ void EmitPass::emitLSCVectorStore(Value *Ptr,
1999119999

1999220000
unsigned int width = numLanes(m_currShader->m_SIMDSize);
1999320001

19994-
ResourceDescriptor resource = GetResourceVariable(Ptr);
20002+
ResourceDescriptor resource = GetResourceVariable(Ptr, true);
1999520003
CountStatelessIndirectAccess(Ptr, resource);
1999620004
if (ptrType->getPointerAddressSpace() != ADDRESS_SPACE_PRIVATE &&
1999720005
!dontForceDmask)
@@ -21658,7 +21666,7 @@ void EmitPass::emitGetBufferPtr(GenIntrinsicInst* inst)
2165821666
m_currShader->SetBindingTableEntryCountAndBitmap(directIdx, bufType, 0, bti);
2165921667
}
2166021668

21661-
ResourceDescriptor EmitPass::GetResourceVariable(Value* resourcePtr)
21669+
ResourceDescriptor EmitPass::GetResourceVariable(Value* resourcePtr, bool Check)
2166221670
{
2166321671
ResourceDescriptor resource;
2166421672
BufferType bufType = BUFFER_TYPE_UNKNOWN;
@@ -21686,15 +21694,14 @@ ResourceDescriptor EmitPass::GetResourceVariable(Value* resourcePtr)
2168621694
if (IsBindless(bufType) ||
2168721695
!directIndexing)
2168821696
{
21689-
if (isa<IntToPtrInst>(resourcePtr))
21690-
{
21691-
IntToPtrInst* i2p = dyn_cast<IntToPtrInst>(resourcePtr);
21692-
resource.m_resource = GetSymbol(i2p->getOperand(0));
21693-
}
21694-
else
21695-
{
21696-
resource.m_resource = GetSymbol(resourcePtr);
21697-
}
21697+
auto SetResource = [&](Value* resourcePtr) {
21698+
if (auto* i2p = dyn_cast<IntToPtrInst>(resourcePtr))
21699+
resource.m_resource = GetSymbol(i2p->getOperand(0));
21700+
else
21701+
resource.m_resource = GetSymbol(resourcePtr);
21702+
};
21703+
21704+
SetResource(resourcePtr);
2169821705

2169921706
if (resource.m_resource->GetElemSize() < 4)
2170021707
{

IGC/Compiler/CISACodeGen/EmitVISAPass.hpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,16 @@ class EmitPass : public llvm::FunctionPass
205205
void emitLoad3DInner(llvm::LdRawIntrinsic* inst, ResourceDescriptor& resource, llvm::Value* elemIdxV);
206206

207207
// when resource is dynamically indexed, load/store must use special intrinsics
208-
void emitLoadRawIndexed(llvm::LdRawIntrinsic* inst, llvm::Value* varOffset, llvm::ConstantInt* immOffset);
209-
void emitStoreRawIndexed(llvm::StoreRawIntrinsic* inst, llvm::Value* varOffset, llvm::ConstantInt* immOffset);
208+
void emitLoadRawIndexed(
209+
llvm::LdRawIntrinsic* inst,
210+
llvm::Value* varOffset,
211+
llvm::ConstantInt* immScale,
212+
llvm::ConstantInt* immOffset);
213+
void emitStoreRawIndexed(
214+
llvm::StoreRawIntrinsic* inst,
215+
llvm::Value* varOffset,
216+
llvm::ConstantInt* immScale,
217+
llvm::ConstantInt* immOffset);
210218
void emitGetBufferPtr(llvm::GenIntrinsicInst* inst);
211219
// \todo, remove this function after we lower all GEP to IntToPtr before CodeGen.
212220
// Only remaining GEPs are for scratch in GFX path
@@ -789,7 +797,7 @@ class EmitPass : public llvm::FunctionPass
789797
CVariable* ReAlignUniformVariable(CVariable* pVar, e_alignment align);
790798
CVariable* BroadcastAndTruncPointer(CVariable* pVar);
791799
CVariable* IndexableResourceIndex(CVariable* indexVar, uint btiIndex);
792-
ResourceDescriptor GetResourceVariable(llvm::Value* resourcePtr);
800+
ResourceDescriptor GetResourceVariable(llvm::Value* resourcePtr, bool Check = false);
793801
SamplerDescriptor GetSamplerVariable(llvm::Value* samplerPtr);
794802
CVariable* ComputeSampleIntOffset(llvm::Instruction* sample, uint sourceIndex);
795803
void emitPlnInterpolation(CVariable* bary, CVariable* inputvar);

IGC/Compiler/CISACodeGen/PatternMatchPass.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,13 @@ namespace IGC
13191319
case GenISAIntrinsic::GenISA_atomiccounterinc:
13201320
case GenISAIntrinsic::GenISA_atomiccounterpredec:
13211321
case GenISAIntrinsic::GenISA_ldptr:
1322+
if (supportsLSCImmediateGlobalBaseOffset()) {
1323+
match = MatchImmOffsetLSC(I);
1324+
if (match)
1325+
return;
1326+
}
1327+
match = MatchSingleInstruction(I);
1328+
break;
13221329
case GenISAIntrinsic::GenISA_ldrawvector_indexed:
13231330
case GenISAIntrinsic::GenISA_ldraw_indexed:
13241331
case GenISAIntrinsic::GenISA_storerawvector_indexed:
@@ -2671,9 +2678,9 @@ namespace IGC
26712678
} else if (isa<StoreInst>(m_inst)) {
26722679
pass->emitStore(cast<StoreInst>(m_inst), m_varOff, m_immOff);
26732680
} else if (isa<LdRawIntrinsic>(m_inst)) {
2674-
pass->emitLoadRawIndexed(cast<LdRawIntrinsic>(m_inst), m_varOff, m_immOff);
2681+
pass->emitLoadRawIndexed(cast<LdRawIntrinsic>(m_inst), m_varOff, nullptr, m_immOff);
26752682
} else if (isa<StoreRawIntrinsic>(m_inst)) {
2676-
pass->emitStoreRawIndexed(cast<StoreRawIntrinsic>(m_inst), m_varOff, m_immOff);
2683+
pass->emitStoreRawIndexed(cast<StoreRawIntrinsic>(m_inst), m_varOff, nullptr, m_immOff);
26772684
} else {
26782685
IGC_ASSERT_MESSAGE(false, "unmatched imm off pattern");
26792686
}

IGC/Compiler/CISACodeGen/Platform.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,11 @@ bool hasSamplerFeedbackSurface() const
521521
return m_platformInfo.eProductFamily >= IGFX_BMG;
522522
}
523523

524+
unsigned getSurfaceStateSize() const
525+
{
526+
return 64;
527+
}
528+
524529
// logical subslice id
525530
bool hasLogicalSSID() const
526531
{

IGC/Compiler/CustomSafeOptPass.cpp

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3888,17 +3888,21 @@ void GenSpecificPattern::visitIntToPtr(llvm::IntToPtrInst& I)
38883888

38893889
void GenSpecificPattern::visitTruncInst(llvm::TruncInst& I)
38903890
{
3891+
auto& DL = I.getModule()->getDataLayout();
3892+
Value* Src = nullptr;
3893+
Value* LHS = nullptr;
3894+
Value* RHS = nullptr;
3895+
38913896
/*
38923897
from
38933898
%22 = lshr i64 %a, 52
38943899
%23 = trunc i64 %22 to i32
3895-
to
3900+
==>
38963901
%22 = extractelement <2 x i32> %a, 1
38973902
%23 = lshr i32 %22, 20 //52-32
38983903
*/
38993904

39003905
using namespace llvm::PatternMatch;
3901-
Value* LHS = nullptr;
39023906
ConstantInt* CI = nullptr;
39033907
if (match(&I, m_Trunc(m_LShr(m_Value(LHS), m_ConstantInt(CI)))) &&
39043908
I.getType()->isIntegerTy(32) &&
@@ -3916,6 +3920,95 @@ void GenSpecificPattern::visitTruncInst(llvm::TruncInst& I)
39163920
}
39173921
I.replaceAllUsesWith(new_Val);
39183922
I.eraseFromParent();
3923+
return;
3924+
}
3925+
3926+
/*
3927+
%i2p = inttoptr i32 %src to ptr addrspace(1)
3928+
%p2i = ptrtoint ptr addrspace(1) %i2p to i64
3929+
%res = trunc i64 %p2i to i32
3930+
==>
3931+
%res = %src
3932+
*/
3933+
if (match(&I, m_Trunc(m_PtrToInt(m_IntToPtr(m_Value(Src))))))
3934+
{
3935+
if (I.getType()->isVectorTy())
3936+
return;
3937+
// Ensure types match
3938+
if (Src->getType() != I.getType())
3939+
return;
3940+
auto* P2I = dyn_cast<PtrToIntInst>(I.getOperand(0));
3941+
if (!P2I)
3942+
return;
3943+
auto* I2P = dyn_cast<IntToPtrInst>(P2I->getOperand(0));
3944+
if (!I2P)
3945+
return;
3946+
if (DL.getPointerSizeInBits(I2P->getType()->getPointerAddressSpace()) <
3947+
I2P->getSrcTy()->getIntegerBitWidth())
3948+
return;
3949+
if (DL.getPointerSizeInBits(P2I->getSrcTy()->getPointerAddressSpace()) !=
3950+
P2I->getType()->getIntegerBitWidth())
3951+
return;
3952+
I.replaceAllUsesWith(Src);
3953+
I.eraseFromParent();
3954+
return;
3955+
}
3956+
3957+
/*
3958+
%i2p = inttoptr i32 %src to ptr addrspace(1)
3959+
%p2i = ptrtoint ptr addrspace(1) %i2p to i64
3960+
%add = add i64 %p2i, C
3961+
%res = trunc i64 %add to i32
3962+
==>
3963+
%res = add i32 %src, C
3964+
*/
3965+
if (match(&I, m_Trunc(m_Add(m_PtrToInt(m_IntToPtr(m_Value(Src))), m_Value(RHS)))))
3966+
{
3967+
if (I.getType()->isVectorTy())
3968+
return;
3969+
// Ensure types match
3970+
if (Src->getType() != I.getType())
3971+
return;
3972+
auto* Add = dyn_cast<Instruction>(I.getOperand(0));
3973+
if (!Add || Add->getOpcode() != Instruction::Add)
3974+
return;
3975+
auto* P2I = dyn_cast<PtrToIntInst>(Add->getOperand(0));
3976+
if (!P2I)
3977+
return;
3978+
auto* I2P = dyn_cast<IntToPtrInst>(P2I->getOperand(0));
3979+
if (!I2P)
3980+
return;
3981+
if (DL.getPointerSizeInBits(I2P->getType()->getPointerAddressSpace()) <
3982+
I2P->getSrcTy()->getIntegerBitWidth())
3983+
return;
3984+
if (DL.getPointerSizeInBits(P2I->getSrcTy()->getPointerAddressSpace()) !=
3985+
P2I->getType()->getIntegerBitWidth())
3986+
return;
3987+
IRBuilder<> IRB(&I);
3988+
RHS = IRB.CreateTrunc(RHS, I.getType());
3989+
auto* Res = IRB.CreateAdd(Src, RHS);
3990+
I.replaceAllUsesWith(Res);
3991+
I.eraseFromParent();
3992+
return;
3993+
}
3994+
3995+
/*
3996+
%s1 = sext i32 %a to i64
3997+
%s2 = sext i32 %b to i64
3998+
%add = add i64 %s1, %s2
3999+
%res = trunc i64 %add to i32
4000+
==>
4001+
%res = add i32 %a, %b
4002+
*/
4003+
if (match(&I, m_Trunc(m_Add(m_SExt(m_Value(LHS)), m_SExt(m_Value(RHS))))))
4004+
{
4005+
if (I.getType() != LHS->getType())
4006+
return;
4007+
IRBuilder<> IRB(&I);
4008+
auto* Res = IRB.CreateAdd(LHS, RHS);
4009+
I.replaceAllUsesWith(Res);
4010+
I.eraseFromParent();
4011+
return;
39194012
}
39204013
}
39214014

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2022-2024 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
10+
; REQUIRES: llvm-14-plus
11+
; RUN: igc_opt --opaque-pointers -debugify --igc-gen-specific-pattern -check-debugify -S < %s 2>&1 | FileCheck %s
12+
; ------------------------------------------------
13+
; GenSpecificPattern: cmp pattern
14+
; ------------------------------------------------
15+
16+
; Debug-info related check
17+
; CHECK-COUNT-1: WARNING
18+
; CHECK-SAME: Missing line 3
19+
; CHECK-NOT: WARNING
20+
; CHECK: CheckModuleDebugify: PASS
21+
22+
define i32 @test1(i32 %src) {
23+
; CHECK-LABEL: define i32 @test1(
24+
; CHECK: ret i32 %src
25+
%i2p = inttoptr i32 %src to ptr addrspace(1)
26+
%p2i = ptrtoint ptr addrspace(1) %i2p to i64
27+
%res = trunc i64 %p2i to i32
28+
ret i32 %res
29+
}
30+
31+
define i32 @test2(i32 %src) {
32+
; CHECK-LABEL: define i32 @test2(
33+
; CHECK: [[RES:%.*]] = add i32 %src, 17
34+
; CHECK: ret i32 [[RES]]
35+
%i2p = inttoptr i32 %src to ptr addrspace(1)
36+
%p2i = ptrtoint ptr addrspace(1) %i2p to i64
37+
%add = add i64 %p2i, 17
38+
%res = trunc i64 %add to i32
39+
ret i32 %res
40+
}
41+
42+
define i32 @test3(i32 %a, i32 %b) {
43+
; CHECK-LABEL: define i32 @test3(
44+
; CHECK: [[RES:%.*]] = add i32 %a, %b
45+
; CHECK: ret i32 [[RES]]
46+
%s1 = sext i32 %a to i64
47+
%s2 = sext i32 %b to i64
48+
%add = add i64 %s1, %s2
49+
%res = trunc i64 %add to i32
50+
ret i32 %res
51+
}

0 commit comments

Comments
 (0)