Skip to content

Commit

Permalink
Add codegen query for supporting LXA instructions
Browse files Browse the repository at this point in the history
Load indexed address register instructions are used to generate address to
access element in the array. This commit adds a code-gen query for using LXA
instruction to used at various places while doing pattern matching.

Signed-off-by: Rahil Shah <[email protected]>
  • Loading branch information
r30shah committed Jan 20, 2025
1 parent 3ba6ccd commit 0b0086b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
16 changes: 10 additions & 6 deletions compiler/z/codegen/OMRCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,17 +408,12 @@ OMR::Z::CodeGenerator::lowerTreeIfNeeded(
}
}

static const bool canEmulateLXA = TR::InstOpCode(TR::InstOpCode::LXAB).canEmulate() &&
TR::InstOpCode(TR::InstOpCode::LXAH).canEmulate() &&
TR::InstOpCode(TR::InstOpCode::LXAF).canEmulate() &&
TR::InstOpCode(TR::InstOpCode::LXAG).canEmulate() &&
TR::InstOpCode(TR::InstOpCode::LXAQ).canEmulate();
static bool disableLXAUncommoning = feGetEnv("TR_disableLXAUncommoning") != NULL;

if (!disableLXAUncommoning &&
(node->getOpCodeValue() == TR::aiadd || node->getOpCodeValue() == TR::aladd) &&
!parent->getOpCode().isLoad() &&
(canEmulateLXA || self()->comp()->target().cpu.isAtLeast(OMR_PROCESSOR_S390_ZNEXT)))
self()->getUseLXAInstructions())
{
// To enable generating more LXAs, perform uncommoning on trees that look like this:
// axadd
Expand Down Expand Up @@ -650,6 +645,15 @@ OMR::Z::CodeGenerator::initialize()
comp->setOption(TR_DisableVectorBCD);
}

static bool canEmulateLXA = TR::InstOpCode(TR::InstOpCode::LXAB).canEmulate() &&
TR::InstOpCode(TR::InstOpCode::LXAH).canEmulate() &&
TR::InstOpCode(TR::InstOpCode::LXAF).canEmulate() &&
TR::InstOpCode(TR::InstOpCode::LXAG).canEmulate() &&
TR::InstOpCode(TR::InstOpCode::LXAQ).canEmulate();
if (canEmulateLXA || comp->target().cpu.isAtLeast(OMR_PROCESSOR_S390_ZNEXT))
{
cg->setUseLXAInstructions(true);
}
// Be pessimistic until we can prove we don't exit after doing code-generation
cg->setExitPointsInMethod(true);

Expand Down
7 changes: 5 additions & 2 deletions compiler/z/codegen/OMRCodeGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ class OMR_EXTENSIBLE CodeGenerator : public OMR::CodeGenerator
bool getCondCodeShouldBePreserved() { return _cgFlags.testAny(S390CG_condCodeShouldBePreserved); }
void setCondCodeShouldBePreserved(bool b) { _cgFlags.set(S390CG_condCodeShouldBePreserved, b); }

bool getUseLXAInstructions() { return _cgFlags.testAny(S390CG_useLXAInstructions); }
void setUseLXAInstructions(bool b) { _cgFlags.set(S390CG_useLXAInstructions, b); }

uint8_t getFCondMoveBranchOpCond() { return fCondMoveBranchOpCond; }
void setFCondMoveBranchOpCond(TR::InstOpCode::S390BranchCondition b) { fCondMoveBranchOpCond = (getMaskForBranchCondition(b)) & 0xF; }

Expand Down Expand Up @@ -727,7 +730,7 @@ class OMR_EXTENSIBLE CodeGenerator : public OMR::CodeGenerator
*/
bool yankIndexScalingOp()
{
return false;
return !getUseLXAInstructions();
}

bool excludeInvariantsFromGRAEnabled();
Expand Down Expand Up @@ -836,7 +839,7 @@ class OMR_EXTENSIBLE CodeGenerator : public OMR::CodeGenerator
S390CG_condCodeShouldBePreserved = 0x00004000,
S390CG_enableBranchPreload = 0x00008000,
S390CG_globalStaticBaseRegisterOn = 0x00010000,
// Available = 0x00020000,
S390CG_useLXAInstructions = 0x00020000,
S390CG_canExceptByTrap = 0x00040000,
S390CG_enableTLHPrefetching = 0x00080000,
S390CG_enableBranchPreloadForCalls = 0x00100000,
Expand Down
7 changes: 1 addition & 6 deletions compiler/z/codegen/OMRTreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7877,13 +7877,8 @@ OMR::Z::TreeEvaluator::axaddEvaluator(TR::Node * node, TR::CodeGenerator * cg)
TR::MemoryReference * axaddMR = generateS390MemoryReference(cg);
TR::InstOpCode::Mnemonic loadOp;
static const bool disableLXAaxaddZNext = feGetEnv("TR_disableLXAaxaddZNext") != NULL;
static const bool canEmulateLXA = TR::InstOpCode(TR::InstOpCode::LXAB).canEmulate() &&
TR::InstOpCode(TR::InstOpCode::LXAH).canEmulate() &&
TR::InstOpCode(TR::InstOpCode::LXAF).canEmulate() &&
TR::InstOpCode(TR::InstOpCode::LXAG).canEmulate() &&
TR::InstOpCode(TR::InstOpCode::LXAQ).canEmulate();

axaddMR->populateAddTree(node, cg, &loadOp, !disableLXAaxaddZNext && (cg->comp()->target().cpu.isAtLeast(OMR_PROCESSOR_S390_ZNEXT) || canEmulateLXA));
axaddMR->populateAddTree(node, cg, &loadOp, !disableLXAaxaddZNext && cg->getUseLXAInstructions());
axaddMR->eliminateNegativeDisplacement(node, cg);
axaddMR->enforceDisplacementLimit(node, cg, NULL);

Expand Down

0 comments on commit 0b0086b

Please sign in to comment.