Skip to content

Commit 2e3c18c

Browse files
bcheng0127igcbot
authored andcommitted
acc substitution update
acc substitution update
1 parent 721bd55 commit 2e3c18c

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

visa/BuildIR.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,8 @@ class IR_Builder {
604604
return kernel.getBoolKernelAttr(Attributes::ATTR_LTOInvokeOptTarget);
605605
}
606606

607+
bool isGRFDstAligned(G4_Operand *dst, int alignByte) const;
608+
607609
//
608610
// Check if opnd is or can be made "alignByte"-byte aligned.
609611
// These functions will change the underlying variable's alignment

visa/BuildIRImpl.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,63 @@ void IR_Builder::bindInputDecl(
165165
}
166166
}
167167

168+
bool IR_Builder::isGRFDstAligned(G4_Operand* opnd, int alignByte) const
169+
{
170+
bool isAligned = true;
171+
unsigned short offset = 0;
172+
int type_size = opnd->getTypeSize();
173+
G4_Declare *dcl = NULL;
174+
175+
dcl = opnd->getBase()->asRegVar()->getDeclare();
176+
while (dcl && dcl->getAliasDeclare()) {
177+
if (dcl->getSubRegAlign() != Any &&
178+
(((dcl->getSubRegAlign() * 2) >= alignByte &&
179+
(dcl->getSubRegAlign() * 2) % alignByte != 0) ||
180+
((dcl->getSubRegAlign() * 2) < alignByte &&
181+
alignByte % (dcl->getSubRegAlign() * 2) != 0))) {
182+
isAligned = false;
183+
break;
184+
}
185+
offset += (unsigned short)dcl->getAliasOffset();
186+
dcl = dcl->getAliasDeclare();
187+
}
188+
189+
if (dcl && dcl->getRegVar() && dcl->getRegVar()->isPhyRegAssigned()) {
190+
offset += static_cast<unsigned short>(dcl->getRegVar()->getByteAddr(*this));
191+
}
192+
193+
if (!isAligned) {
194+
return false;
195+
}
196+
197+
if (opnd->isDstRegRegion()) {
198+
if (opnd->asDstRegRegion()->getRegAccess() != Direct) {
199+
isAligned = false;
200+
}
201+
offset += opnd->asDstRegRegion()->getRegOff() * numEltPerGRF<Type_UB>() +
202+
opnd->asDstRegRegion()->getSubRegOff() * type_size;
203+
}
204+
205+
if (offset % alignByte != 0) {
206+
return false;
207+
}
208+
209+
if (dcl && dcl->getRegFile() == G4_GRF) {
210+
if (dcl->getSubRegAlign() == Any ||
211+
((dcl->getSubRegAlign() * 2) < alignByte &&
212+
alignByte % (dcl->getSubRegAlign() * 2) == 0)) {
213+
isAligned = false;
214+
} else if ((dcl->getSubRegAlign() * 2) < alignByte ||
215+
(dcl->getSubRegAlign() * 2) % alignByte != 0) {
216+
isAligned = false;
217+
}
218+
} else {
219+
isAligned = false;
220+
}
221+
222+
return isAligned;
223+
}
224+
168225
// check if an operand is aligned to <alignByte>
169226
bool IR_Builder::tryToAlignOperand(G4_Operand *opnd, unsigned short &offset,
170227
int alignByte) const {

visa/G4_IR.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7564,7 +7564,15 @@ bool G4_INST::canSrcBeAccAfterHWConform(Gen4_Operand_Number opndNum) const {
75647564
} else {
75657565
// If the destination offset is not GRF aligned, such as has sub
75667566
// register offset, the src cannot be replaced with ACC
7567-
if (!builder.tryToAlignOperand(dst,
7567+
if (builder.enableACCBeforRA() &&
7568+
!builder.enablePreSchedACC() && builder.supports4GRFAlign()) {
7569+
// Before RA, align may affect the RA result, so don't do
7570+
// alignment, just check if it's aligned
7571+
if (!builder.isGRFDstAligned(dst,
7572+
getBuilder().numEltPerGRF<Type_UB>())) {
7573+
return false;
7574+
}
7575+
} else if (!builder.tryToAlignOperand(dst,
75687576
getBuilder().numEltPerGRF<Type_UB>())) {
75697577
return false;
75707578
}

0 commit comments

Comments
 (0)