Skip to content

Commit b852e85

Browse files
Anton Sidorenkoigcbot
authored andcommitted
Tighten legalization rules for EU fusion platforms
If the module contains stack calls and target has fused EUs, legalization width must be less or equal 16.
1 parent 9c08756 commit b852e85

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXLegalization.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ SPDX-License-Identifier: MIT
236236
using namespace llvm;
237237
using namespace genx;
238238

239+
static cl::opt<bool> UseUpper16Lanes("vc-use-upper16-lanes", cl::init(true),
240+
cl::Hidden,
241+
cl::desc("Limit legalization width"));
242+
239243
namespace {
240244

241245
// Information on a part of a predicate.
@@ -355,6 +359,9 @@ class GenXLegalization : public FunctionPass {
355359
// Illegally sized predicate values that need splitting at the end of
356360
// processing the function.
357361
SetVector<Instruction *> IllegalPredicates;
362+
// Whether the function's module has stack calls or not. Used for making
363+
// legalization decisions.
364+
bool HasStackCalls = false;
358365

359366
public:
360367
static char ID;
@@ -538,6 +545,12 @@ bool GenXLegalization::runOnFunction(Function &F) {
538545
.getTM<GenXTargetMachine>()
539546
.getGenXSubtarget();
540547
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
548+
// FIXME: Non-optimal solution. FGs info or some stackcalls-related analysis
549+
// will be useful here.
550+
HasStackCalls =
551+
llvm::any_of(F.getParent()->functions(), [](const Function &MF) {
552+
return genx::requiresStackCall(MF);
553+
});
541554
// Check args for illegal predicates.
542555
for (Function::arg_iterator fi = F.arg_begin(), fe = F.arg_end(); fi != fe;
543556
++fi) {
@@ -1329,6 +1342,15 @@ unsigned GenXLegalization::determineWidth(unsigned WholeWidth,
13291342
// Prepare to keep track of whether an instruction with a minimum width
13301343
// (e.g. dp4) would be split too small, and whether we need to unbale.
13311344
unsigned ExecSizeAllowedBits = adjustTwiceWidthOrFixed4(B);
1345+
if (!UseUpper16Lanes || (HasStackCalls && ST->hasFusedEU()))
1346+
// Actually, we should legalize with these more strict requirements only FGs
1347+
// of indirectly called functions. But there are two design issues that make
1348+
// us legalize everything if the module has a stack call:
1349+
// * jmpi to goto transformation is appied in VISA and it transforms more
1350+
// than necessary
1351+
// * this legalization pass does not have access to FGs
1352+
ExecSizeAllowedBits &= 0x1f;
1353+
13321354
unsigned MainInstMinWidth =
13331355
1 << countTrailingZeros(ExecSizeAllowedBits, ZB_Undefined);
13341356
// Determine the vector width that we need to split into.

0 commit comments

Comments
 (0)