Skip to content

Commit 8b7db92

Browse files
igorban-inteligcbot
authored andcommitted
Do not emit cross-register access for rdregions
Do not emit cross-register access for rdregions
1 parent 28b91fe commit 8b7db92

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXDebugInfo.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -926,20 +926,20 @@ class GenXFunction final : public IGC::VISAModule {
926926
static constexpr unsigned RdNumOp =
927927
GenXIntrinsic::GenXRegion::OldValueOperandNum;
928928

929-
static const Value *
930-
calculateBaledLocation(const CallInst *UseInst,
931-
llvm::SmallVector<unsigned, 0> *Offsets,
932-
const GenXBaling &BA, const DataLayout &DL) {
929+
using OffsetsVector = llvm::SmallVector<unsigned, 0>;
930+
931+
std::tuple<const Value *, OffsetsVector>
932+
calculateBaledLocation(const CallInst *UseInst, const GenXBaling &BA,
933+
const DataLayout &DL) const {
933934
IGC_ASSERT(UseInst);
934-
IGC_ASSERT(Offsets);
935935
if (!GenXIntrinsic::isRdRegion(UseInst))
936-
return UseInst;
936+
return std::make_tuple(UseInst, OffsetsVector());
937937
auto BI = BA.getBaleInfo(UseInst);
938938

939939
if (BI.Type != genx::BaleInfo::RDREGION ||
940940
!dyn_cast<ConstantInt>(UseInst->getOperand(RdIndex)) ||
941941
BI.isOperandBaled(RdNumOp) || !BA.isBaled(UseInst))
942-
return UseInst;
942+
return std::make_tuple(UseInst, OffsetsVector());
943943

944944
auto GetSignConstant = [](Value *Operand) {
945945
auto *CI = cast<ConstantInt>(Operand);
@@ -953,7 +953,7 @@ class GenXFunction final : public IGC::VISAModule {
953953
auto *VTy = dyn_cast<IGCLLVM::FixedVectorType>(UseInst->getType());
954954
// TODO: Investigate scalar
955955
if (!VTy)
956-
return UseInst;
956+
return std::make_tuple(UseInst, OffsetsVector());
957957
auto Vstride = GetSignConstant(UseInst->getOperand(RdVstride));
958958
auto Width = GetSignConstant(UseInst->getOperand(RdWidth));
959959
auto Stride = GetSignConstant(UseInst->getOperand(RdStride));
@@ -963,17 +963,24 @@ class GenXFunction final : public IGC::VISAModule {
963963
auto ElSizeInBits = vc::getTypeSize(VTy->getElementType(), &DL).inBits();
964964
IGC_ASSERT(Width);
965965
unsigned NumElements = VTy->getNumElements() / Width;
966+
OffsetsVector Offsets;
966967

967968
for (unsigned I = 0; I < NumElements; ++I) {
968969
for (unsigned J = 0; J < Width; ++J) {
969970
auto CurrOffset = StartIdx + ElSizeInBits * (I * Vstride + J * Stride);
970971
// Check type overflow
971972
IGC_ASSERT(CurrOffset <= std::numeric_limits<unsigned>::max());
972-
Offsets->push_back(CurrOffset);
973+
if ((CurrOffset % getGRFSizeInBits()) + ElSizeInBits >
974+
getGRFSizeInBits()) {
975+
LLVM_DEBUG(dbgs() << " Fail to generate Bale location element has "
976+
"crossGRF access\n");
977+
return std::make_tuple(UseInst, OffsetsVector());
978+
}
979+
Offsets.push_back(CurrOffset);
973980
}
974981
}
975982
// Replace value to source of rdregion
976-
return UseInst->getOperand(RdNumOp);
983+
return std::make_tuple(UseInst->getOperand(RdNumOp), std::move(Offsets));
977984
}
978985

979986
IGC::VISAVariableLocation
@@ -999,10 +1006,10 @@ class GenXFunction final : public IGC::VISAModule {
9991006
const Value *DbgValue =
10001007
IGCLLVM::getVariableLocation(cast<DbgVariableIntrinsic>(DbgInst));
10011008

1002-
llvm::SmallVector<unsigned, 0> Offsets;
1009+
OffsetsVector Offsets;
10031010
if (auto *UseInst = dyn_cast_or_null<CallInst>(DbgValue)) {
1004-
DbgValue = calculateBaledLocation(UseInst, &Offsets, BA,
1005-
F.getParent()->getDataLayout());
1011+
std::tie(DbgValue, Offsets) =
1012+
calculateBaledLocation(UseInst, BA, F.getParent()->getDataLayout());
10061013
}
10071014

10081015
IGC_ASSERT(VarDescr);

0 commit comments

Comments
 (0)