Skip to content

Commit 745d426

Browse files
jgu222igcbot
authored andcommitted
For the following code:
mov (8|M0) r80.0<1>:d 0:w send (1|M0) r80:d r4:uq 0xC 0x041401FF add (1|M0) r80.1<1>:d r54.0<0;1,0>:d r80.1<0;1,0>:d add (1|M0) r80.2<1>:d r58.0<0;1,0>:d r80.2<0;1,0>:d add (1|M0) r80.3<1>:d r62.0<0;1,0>:d r80.3<0;1,0>:d add (1|M0) r80.4<1>:d r66.0<0;1,0>:d r80.4<0;1,0>:d add (1|M0) r80.5<1>:d r70.0<0;1,0>:d r80.5<0;1,0>:d add (1|M0) r80.6<1>:d r74.0<0;1,0>:d r80.6<0;1,0>:d add (1|M0) r80.7<1>:d r78.0<0;1,0>:d r80.7<0;1,0>:d Previously, "send" kills r80 entirely, which is incorrect. This change makes sure that "send (1)" only kills r80.0:d, thus the first "mov" instruction is not dead. 2nd try: fix an issue that sendRaw's execSize isn't initialized. This is off by default. Will enable it for testing in the following change. No functional change expected from this change as it is off.
1 parent 410fcee commit 745d426

File tree

7 files changed

+247
-10
lines changed

7 files changed

+247
-10
lines changed

visa/BuildIR.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,16 @@ class IR_Builder
889889
return isRead ? SendAccess::READ_ONLY : SendAccess::WRITE_ONLY;
890890
}
891891

892+
G4_SendDescRaw* createSendMsgDesc(
893+
SFID sfid,
894+
uint32_t desc,
895+
uint32_t extDesc,
896+
int src1Len,
897+
SendAccess access,
898+
G4_Operand* bti,
899+
G4_ExecSize execSize,
900+
bool isValidFuncCtrl = true);
901+
892902
G4_SendDescRaw * createSendMsgDesc(
893903
SFID sfid,
894904
uint32_t desc,

visa/BuildIRImpl.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,19 @@ G4_SendDescRaw * IR_Builder::createSendMsgDesc(
12921292
int src1Len,
12931293
SendAccess access,
12941294
G4_Operand *bti,
1295+
G4_ExecSize execSize,
1296+
bool isValidFuncCtrl)
1297+
{
1298+
return new (mem) G4_SendDescRaw(sfid, desc, extDesc, src1Len, access, bti, execSize, isValidFuncCtrl);
1299+
}
1300+
1301+
G4_SendDescRaw* IR_Builder::createSendMsgDesc(
1302+
SFID sfid,
1303+
uint32_t desc,
1304+
uint32_t extDesc,
1305+
int src1Len,
1306+
SendAccess access,
1307+
G4_Operand* bti,
12951308
bool isValidFuncCtrl)
12961309
{
12971310
return new (mem) G4_SendDescRaw(sfid, desc, extDesc, src1Len, access, bti, isValidFuncCtrl);

visa/G4_IR.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ G4_InstSend::G4_InstSend(
354354
G4_INST(builder, prd, o, nullptr, g4::NOSAT, size, dst, payload, desc, opt),
355355
msgDesc(md)
356356
{
357+
md->setExecSize(size);
357358
}
358359

359360
G4_InstSend::G4_InstSend(
@@ -372,6 +373,7 @@ G4_InstSend::G4_InstSend(
372373
msgDesc(md)
373374
{
374375
setSrc(extDesc, 3);
376+
md->setExecSize(size);
375377
}
376378

377379
void G4_INST::setOpcode(G4_opcode opcd)

visa/G4_IR.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,7 @@ class G4_InstCF : public G4_INST
13661366

13671367
class G4_InstSend : public G4_INST
13681368
{
1369+
// Once initialized, remain unchanged as it could be shared among several sends.
13691370
G4_SendDesc* msgDesc;
13701371

13711372
public:
@@ -1436,6 +1437,12 @@ class G4_InstSend : public G4_INST
14361437
void setMsgDesc(G4_SendDesc *in)
14371438
{
14381439
assert(in && "null descriptor not expected");
1440+
#if defined(_DEBUG)
1441+
if (in && in->getExecSize() == g4::SIMD_UNDEFINED)
1442+
{
1443+
DEBUG_MSG("Msg Desc has execSize undefined!\n");
1444+
}
1445+
#endif
14391446
msgDesc = in;
14401447
resetRightBound((G4_Operand*)dst);
14411448
resetRightBound(srcs[0]);

visa/G4_SendDescs.cpp

Lines changed: 177 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,8 @@ G4_SendDescLdSt::G4_SendDescLdSt(
168168
G4_Operand *surf,
169169
ImmOff _immOff,
170170
LdStAttrs _attrs)
171-
: G4_SendDesc(G4_SendDesc::Kind::LDST, sfid),
171+
: G4_SendDesc(G4_SendDesc::Kind::LDST, sfid, _execSize),
172172
op(_op),
173-
execSize(_execSize),
174173
//
175174
addrType(at), addrBits(_addrBits), addrDims(_addrDims),
176175
//
@@ -185,7 +184,7 @@ G4_SendDescLdSt::G4_SendDescLdSt(
185184
static size_t toExecSlots(const G4_SendDescLdSt &d)
186185
{
187186
int minExecSize = 8;
188-
int execSlots = std::max((int)d.execSize, minExecSize);
187+
int execSlots = std::max((int)d.getExecSize(), minExecSize);
189188
return (size_t)execSlots;
190189
}
191190

@@ -416,15 +415,28 @@ G4_SendDescRaw::G4_SendDescRaw(
416415
}
417416
}
418417

418+
G4_SendDescRaw::G4_SendDescRaw(
419+
SFID _sfid,
420+
uint32_t _desc,
421+
uint32_t _extDesc,
422+
int _src1Len,
423+
SendAccess access,
424+
G4_Operand* bti,
425+
bool isValidFuncCtrl)
426+
: G4_SendDescRaw(_sfid, _desc, _extDesc, _src1Len, access, bti,
427+
g4::SIMD_UNDEFINED, isValidFuncCtrl)
428+
{}
429+
419430
G4_SendDescRaw::G4_SendDescRaw(
420431
SFID _sfid,
421432
uint32_t _desc,
422433
uint32_t _extDesc,
423434
int _src1Len,
424435
SendAccess access,
425436
G4_Operand *bti,
437+
G4_ExecSize execSize,
426438
bool isValidFuncCtrl)
427-
: G4_SendDesc(G4_SendDesc::Kind::RAW, _sfid),
439+
: G4_SendDesc(G4_SendDesc::Kind::RAW, _sfid, execSize),
428440
accessType(access), m_sti(nullptr), m_bti(bti), funcCtrlValid(isValidFuncCtrl)
429441
{
430442
desc.value = _desc;
@@ -586,6 +598,149 @@ bool G4_SendDescRaw::is16BitReturn() const
586598
return desc.layout.returnFormat == 1;
587599
}
588600

601+
bool G4_SendDescRaw::isByteScatterRW() const
602+
{
603+
auto funcID = getSFID();
604+
switch (funcID) {
605+
case SFID::DP_DC0:
606+
switch (getHdcMessageType()) {
607+
case DC_BYTE_SCATTERED_READ:
608+
case DC_BYTE_SCATTERED_WRITE:
609+
return true;
610+
default:
611+
break;
612+
}
613+
break;
614+
case SFID::DP_DC1:
615+
switch (getHdcMessageType()) {
616+
case DC1_A64_SCATTERED_READ:
617+
case DC1_A64_SCATTERED_WRITE:
618+
return (getBlockSize() == 1);
619+
default:
620+
break;
621+
}
622+
break;
623+
case SFID::DP_DC2:
624+
switch (getHdcMessageType()) {
625+
case DC2_A64_SCATTERED_READ:
626+
case DC2_A64_SCATTERED_WRITE:
627+
return (getBlockSize() == 1);
628+
case DC2_BYTE_SCATTERED_READ:
629+
case DC2_BYTE_SCATTERED_WRITE:
630+
return true;
631+
default:
632+
break;
633+
}
634+
break;
635+
default:
636+
break;
637+
}
638+
return false;
639+
}
640+
641+
bool G4_SendDescRaw::isDWScatterRW() const
642+
{
643+
auto funcID = getSFID();
644+
switch (funcID) {
645+
case SFID::DP_DC0:
646+
switch (getHdcMessageType()) {
647+
case DC_DWORD_SCATTERED_READ:
648+
case DC_DWORD_SCATTERED_WRITE:
649+
return true;
650+
default:
651+
break;
652+
}
653+
break;
654+
case SFID::DP_DC1:
655+
switch (getHdcMessageType()) {
656+
case DC1_A64_SCATTERED_READ:
657+
case DC1_A64_SCATTERED_WRITE:
658+
return (getBlockSize() == 4);
659+
default:
660+
break;
661+
}
662+
break;
663+
case SFID::DP_DC2:
664+
switch (getHdcMessageType()) {
665+
case DC2_A64_SCATTERED_READ:
666+
case DC2_A64_SCATTERED_WRITE:
667+
return (getBlockSize() == 4);
668+
default:
669+
break;
670+
}
671+
break;
672+
default:
673+
break;
674+
}
675+
return false;
676+
}
677+
678+
bool G4_SendDescRaw::isQWScatterRW() const
679+
{
680+
auto funcID = getSFID();
681+
switch (funcID) {
682+
case SFID::DP_DC0:
683+
switch (getHdcMessageType()) {
684+
default:
685+
break;
686+
}
687+
break;
688+
case SFID::DP_DC1:
689+
switch (getHdcMessageType()) {
690+
case DC1_A64_SCATTERED_READ:
691+
case DC1_A64_SCATTERED_WRITE:
692+
return (getBlockSize() == 8);
693+
default:
694+
break;
695+
}
696+
break;
697+
case SFID::DP_DC2:
698+
switch (getHdcMessageType()) {
699+
case DC2_A64_SCATTERED_READ:
700+
case DC2_A64_SCATTERED_WRITE:
701+
return (getBlockSize() == 8);
702+
default:
703+
break;
704+
}
705+
break;
706+
default:
707+
break;
708+
}
709+
return false;
710+
}
711+
712+
bool G4_SendDescRaw::isUntypedRW() const
713+
{
714+
auto funcID = getSFID();
715+
switch (funcID) {
716+
case SFID::DP_DC1:
717+
switch (getHdcMessageType()) {
718+
case DC1_UNTYPED_SURFACE_READ:
719+
case DC1_UNTYPED_SURFACE_WRITE:
720+
case DC1_A64_UNTYPED_SURFACE_READ:
721+
case DC1_A64_UNTYPED_SURFACE_WRITE:
722+
return true;
723+
default:
724+
break;
725+
}
726+
break;
727+
case SFID::DP_DC2:
728+
switch (getHdcMessageType()) {
729+
case DC2_UNTYPED_SURFACE_READ:
730+
case DC2_UNTYPED_SURFACE_WRITE:
731+
case DC2_A64_UNTYPED_SURFACE_READ:
732+
case DC2_A64_UNTYPED_SURFACE_WRITE:
733+
return true;
734+
default:
735+
break;
736+
}
737+
break;
738+
default:
739+
break;
740+
}
741+
return false;
742+
}
743+
589744
bool G4_SendDescRaw::isA64Message() const
590745
{
591746
if (!isHDC()) {
@@ -882,6 +1037,24 @@ size_t G4_SendDescRaw::getDstLenBytes() const
8821037
return 32 * getScratchRWSize(); // HWords
8831038
} else if (isOwordLoad()) {
8841039
return 16 * getOwordsAccessed(); // OWords
1040+
#if 0
1041+
// Use macro fo easy testing.
1042+
} else if (isByteScatterRW()) {
1043+
uint16_t nbytes = getBlockNum();
1044+
// assume 4 at least
1045+
nbytes = (nbytes >= 4 ? nbytes : 4);
1046+
assert(getExecSize() != g4::SIMD_UNDEFINED);
1047+
return nbytes * getExecSize();
1048+
} else if (isDWScatterRW()) {
1049+
assert(getExecSize() != g4::SIMD_UNDEFINED);
1050+
return 4 * getBlockNum() * getExecSize();
1051+
} else if (isQWScatterRW()) {
1052+
assert(getExecSize() != g4::SIMD_UNDEFINED);
1053+
return 8 * getBlockNum() * getExecSize();
1054+
} else if (isUntypedRW()) {
1055+
assert(getExecSize() != g4::SIMD_UNDEFINED);
1056+
return 4 * getEnabledChannelNum() * getExecSize();
1057+
#endif
8851058
} else {
8861059
// fallback to the raw GRF count
8871060
return ResponseLength() * (size_t)getGRFSize();

visa/G4_SendDescs.hpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,38 @@ static inline ElemsPerAddr::Chs operator|(
179179

180180
class G4_Operand;
181181

182-
// Base class for all send descriptors
182+
// Base class for all send descriptors.
183+
// (Note that G4_SendDesc could be reused by more than one instruction.)
183184
class G4_SendDesc
184185
{
186+
friend class G4_InstSend;
187+
188+
protected:
189+
// The execution size for this message.
190+
G4_ExecSize execSize;
191+
192+
// Limit access to G4_InstSend and any derived classes.
193+
void setExecSize(G4_ExecSize v) { execSize = v; }
194+
185195
public:
186196
enum class Kind {INVALID, RAW, LDST};
187197

188198
Kind kind;
189199

190200
SFID sfid;
191201

192-
G4_SendDesc(Kind k, SFID _sfid) : kind(k), sfid(_sfid) { }
202+
G4_SendDesc(Kind k, SFID _sfid) : kind(k), sfid(_sfid), execSize(g4::SIMD_UNDEFINED) { }
203+
G4_SendDesc(Kind k, SFID _sfid, G4_ExecSize _execSize)
204+
: kind(k),
205+
sfid(_sfid),
206+
execSize(_execSize)
207+
{}
193208

194209
SFID getSFID() const {return sfid;}
195210

211+
// execSize: need to set it in the ctor
212+
G4_ExecSize getExecSize() const { return execSize; }
213+
196214
bool isRaw() const {return kind == Kind::RAW;}
197215
bool isLdSt() const {return kind == Kind::LDST;}
198216
//
@@ -274,9 +292,6 @@ struct G4_SendDescLdSt : G4_SendDesc {
274292
// The message op
275293
LdStOp op;
276294

277-
// The execution size for this message.
278-
G4_ExecSize execSize;
279-
280295
// E.g. flat, bti, ...
281296
AddrType addrType;
282297
//
@@ -491,6 +506,18 @@ class G4_SendDescRaw : public G4_SendDesc
491506
G4_Operand *bti,
492507
bool isValidFuncCtrl);
493508

509+
// Preferred constructor takes an explicit SFID and src1 length
510+
// Need execSize, so it is created for a particular send.
511+
G4_SendDescRaw(
512+
SFID sfid,
513+
uint32_t desc,
514+
uint32_t extDesc,
515+
int src1Len,
516+
SendAccess access,
517+
G4_Operand* bti,
518+
G4_ExecSize execSize,
519+
bool isValidFuncCtrl);
520+
494521
void *operator new(size_t sz, Mem_Manager &m) { return m.alloc(sz); }
495522

496523
static uint32_t createExtDesc(SFID funcID, bool isEot = false)
@@ -609,6 +636,10 @@ class G4_SendDescRaw : public G4_SendDesc
609636
uint16_t bitV = ((getFuncCtrl() & 0x3000u) >> 12);
610637
return 0x1 << bitV;
611638
}
639+
bool isByteScatterRW() const;
640+
bool isDWScatterRW() const;
641+
bool isQWScatterRW() const;
642+
bool isUntypedRW() const;
612643

613644
bool isA64Message() const;
614645

visa/SendFusion.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ void SendFusion::simplifyMsg(INST_LIST_ITER SendIter)
581581
desc->getExtendedDesc(),
582582
desc->extMessageLength(),
583583
desc->getAccess(),
584-
desc->getBti());
584+
desc->getBti(),
585+
desc->getExecSize());
585586
Send->setMsgDesc(newDesc);
586587

587588
// If addI or movI is dead, remove them.

0 commit comments

Comments
 (0)