Skip to content

Commit b9f301d

Browse files
jfuentessys_zuul
authored andcommitted
Make sure cmp is correctly split in vISA.
Change-Id: If1b30c4e1160e7b033645a2efbfe5f8c4a31c8ef
1 parent a583088 commit b9f301d

File tree

4 files changed

+33
-74
lines changed

4 files changed

+33
-74
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 18 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -560,79 +560,28 @@ namespace IGC
560560
flagDst = true;
561561
}
562562

563-
unsigned numParts = 0;
563+
VISA_VectorOpnd* opnd0 = GetSourceOperand(src0, m_encoderState.m_srcOperand[0]);
564+
VISA_VectorOpnd* opnd1 = GetSourceOperand(src1, m_encoderState.m_srcOperand[1]);
564565

565-
// Due to a simulator quirk, we need to split the instruction even if the
566-
// dst operand of the compare is null, if it "looks" too large,
567-
// that is, if the execution size is 16 and the comparison type
568-
// is QW.
569-
bool bNeedSplitting = false;
570-
if (flagDst && needsSplitting(GetAluExecSize(dst)) &&
571-
(src0->GetElemSize() > 4 || src1->GetElemSize() > 4))
566+
if (flagDst)
572567
{
573-
bNeedSplitting = true;
574-
numParts = 2;
568+
V(vKernel->AppendVISAComparisonInst(
569+
subOp,
570+
GetAluEMask(dst),
571+
GetAluExecSize(dst),
572+
dst->visaPredVariable,
573+
opnd0,
574+
opnd1));
575575
}
576-
577-
bNeedSplitting = bNeedSplitting ||
578-
NeedSplitting(src0, m_encoderState.m_srcOperand[0], numParts, true) ||
579-
NeedSplitting(src1, m_encoderState.m_srcOperand[1], numParts, true);
580-
581-
if (bNeedSplitting)
576+
else
582577
{
583-
VISA_EMask_Ctrl execMask = GetAluEMask(dst);
584-
VISA_Exec_Size fromExecSize = GetAluExecSize(dst);
585-
VISA_Exec_Size toExecSize = SplitExecSize(fromExecSize, numParts);
586-
587-
for (unsigned thePart = 0; thePart != numParts; ++thePart) {
588-
SModifier newSrc0Mod = SplitVariable(fromExecSize, toExecSize, thePart, src0, m_encoderState.m_srcOperand[0], true);
589-
SModifier newSrc1Mod = SplitVariable(fromExecSize, toExecSize, thePart, src1, m_encoderState.m_srcOperand[1], true);
590-
VISA_VectorOpnd* srcOpnd0 = GetSourceOperand(src0, newSrc0Mod);
591-
VISA_VectorOpnd* srcOpnd1 = GetSourceOperand(src1, newSrc1Mod);
592-
if (flagDst)
593-
{
594-
V(vKernel->AppendVISAComparisonInst(subOp,
595-
SplitEMask(fromExecSize, toExecSize, thePart, execMask),
596-
toExecSize,
597-
dst->visaPredVariable,
598-
srcOpnd0, srcOpnd1));
599-
}
600-
else
601-
{
602-
SModifier newDstMod = SplitVariable(fromExecSize, toExecSize, thePart, dst, m_encoderState.m_dstOperand);
603-
VISA_VectorOpnd* dstOpnd = GetDestinationOperand(dst, newDstMod);
604-
V(vKernel->AppendVISAComparisonInst(subOp,
605-
SplitEMask(fromExecSize, toExecSize, thePart, execMask),
606-
toExecSize,
607-
dstOpnd,
608-
srcOpnd0, srcOpnd1));
609-
}
610-
}
611-
}
612-
else {
613-
VISA_VectorOpnd* opnd0 = GetSourceOperand(src0, m_encoderState.m_srcOperand[0]);
614-
VISA_VectorOpnd* opnd1 = GetSourceOperand(src1, m_encoderState.m_srcOperand[1]);
615-
616-
if (flagDst)
617-
{
618-
V(vKernel->AppendVISAComparisonInst(
619-
subOp,
620-
GetAluEMask(dst),
621-
GetAluExecSize(dst),
622-
dst->visaPredVariable,
623-
opnd0,
624-
opnd1));
625-
}
626-
else
627-
{
628-
V(vKernel->AppendVISAComparisonInst(
629-
subOp,
630-
GetAluEMask(dst),
631-
GetAluExecSize(dst),
632-
GetDestinationOperand(dst, m_encoderState.m_dstOperand),
633-
opnd0,
634-
opnd1));
635-
}
578+
V(vKernel->AppendVISAComparisonInst(
579+
subOp,
580+
GetAluEMask(dst),
581+
GetAluExecSize(dst),
582+
GetDestinationOperand(dst, m_encoderState.m_dstOperand),
583+
opnd0,
584+
opnd1));
636585
}
637586
}
638587

visa/InstSplit.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,19 @@ INST_LIST_ITER InstSplitPass::splitInstruction(INST_LIST_ITER it)
117117
// Handle split exceptions
118118
if (!doSplit)
119119
{
120-
if (ISA_Inst_Table[inst->opcode()].type == ISA_Inst_Compare)
120+
if (inst->opcode() == G4_cmp)
121+
{
121122
// Due to a simulator quirk, we need to split cmp instruction even if the
122123
// dst operand of the compare is null, if it "looks" too large,
123124
// that is, if the execution size is 16 and the comparison type
124125
// is QW.
125-
if (execSize >= 16 &&
126+
if (needSplitByExecSize(execSize) && inst->getDst()->isNullReg() &&
126127
(G4_Type_Table[inst->getSrc(0)->getType()].byteSize > 4 ||
127-
G4_Type_Table[inst->getSrc(1)->getType()].byteSize > 4 ))
128+
G4_Type_Table[inst->getSrc(1)->getType()].byteSize > 4))
128129
{
129130
doSplit = true;
130131
}
132+
}
131133
}
132134

133135
if (!doSplit)
@@ -273,6 +275,11 @@ INST_LIST_ITER InstSplitPass::splitInstruction(INST_LIST_ITER it)
273275
return newInstIterator;
274276
}
275277

278+
bool InstSplitPass::needSplitByExecSize(G4_ExecSize execSize) const
279+
{
280+
return execSize == g4::SIMD16;
281+
}
282+
276283
// Compare regRegion of source operand and destination.
277284
// We put this in a separate function since compareOperand from G4_DstRegRegion
278285
// and G4_SrcRegRegion don't handle regions that cross 2 GRFs.

visa/InstSplit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ namespace vISA
3939

4040
private:
4141
INST_LIST_ITER splitInstruction(INST_LIST_ITER it);
42+
bool needSplitByExecSize(G4_ExecSize ExecSize) const;
4243
G4_CmpRelation compareSrcDstRegRegion(G4_DstRegRegion* dstRegRegion, G4_Operand* opnd);
4344
void computeDstBounds(G4_DstRegRegion* dstRegion, uint32_t& leftBound, uint32_t& rightBound);
4445
void computeSrcBounds(G4_SrcRegRegion* srcRegion, uint32_t& leftBound, uint32_t& rightBound);

visa/IsaVerification.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,11 @@ void vISAVerifier::verifyRegion(
553553
}
554554

555555
// Check if the operand may touch more than 2 GRFs due to bad alignment
556-
// So far vISA is able to handle the splitting of: Moves
556+
// So far vISA is able to handle the splitting of:
557+
// moves, logic and cmp instructions
557558
if (ISA_Inst_Table[opcode].type != ISA_Inst_Mov &&
558-
ISA_Inst_Table[opcode].type != ISA_Inst_Logic)
559+
ISA_Inst_Table[opcode].type != ISA_Inst_Logic &&
560+
ISA_Inst_Table[opcode].type != ISA_Inst_Compare)
559561
{
560562
REPORT_INSTRUCTION(options, (COMMON_ISA_GRF_REG_SIZE * 2u) > last_region_elt_byte,
561563
"CISA operand region access out of 2 GRF boundary (within %d bytes): %d",

0 commit comments

Comments
 (0)