Skip to content

Commit

Permalink
Merge pull request #7095 from jmesyou/refactor/const-div
Browse files Browse the repository at this point in the history
Simplify SupportsConst(I|L)Div to Supports(I|L)MulHigh
  • Loading branch information
knn-k authored Aug 23, 2023
2 parents 51ac424 + 1df35cd commit d458e29
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
3 changes: 3 additions & 0 deletions compiler/aarch64/codegen/OMRCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ OMR::ARM64::CodeGenerator::initialize()

cg->setSupportsAlignedAccessOnly();

cg->setSupportsIMulHigh();
cg->setSupportsLMulHigh();

if (!comp->getOption(TR_DisableTraps) && TR::Compiler->vm.hasResumableTrapHandler(comp))
{
_numberBytesReadInaccessible = 4096;
Expand Down
2 changes: 1 addition & 1 deletion compiler/arm/codegen/OMRCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ OMR::ARM::CodeGenerator::initialize()
cg->setSupportsAlignedAccessOnly();
cg->setSupportsPrimitiveArrayCopy();
cg->setSupportsReferenceArrayCopy();
cg->setSupportsLoweringConstIDiv();
cg->setSupportsIMulHigh();
cg->setSupportsNewInstanceImplOpt();

#ifdef J9_PROJECT_SPECIFIC
Expand Down
16 changes: 10 additions & 6 deletions compiler/codegen/OMRCodeGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1739,11 +1739,15 @@ class OMR_EXTENSIBLE CodeGenerator
bool getSupportsLDivAndLRemWithThreeChildren() {return _flags2.testAny(SupportsLDivAndLRemWithThreeChildren);}
void setSupportsLDivAndLRemWithThreeChildren() {_flags2.set(SupportsLDivAndLRemWithThreeChildren);}

bool getSupportsLoweringConstIDiv() {return _flags2.testAny(SupportsLoweringConstIDiv);}
void setSupportsLoweringConstIDiv() {_flags2.set(SupportsLoweringConstIDiv);}
bool getSupportsLoweringConstIDiv() {return getSupportsIMulHigh();}

bool getSupportsLoweringConstLDiv() {return _flags2.testAny(SupportsLoweringConstLDiv);}
void setSupportsLoweringConstLDiv() {_flags2.set(SupportsLoweringConstLDiv);}
bool getSupportsLoweringConstLDiv() {return getSupportsLMulHigh();}

bool getSupportsIMulHigh() {return _flags2.testAny(SupportsIMulHigh);}
void setSupportsIMulHigh() {_flags2.set(SupportsIMulHigh);}

bool getSupportsLMulHigh() {return _flags2.testAny(SupportsLMulHigh);}
void setSupportsLMulHigh() {_flags2.set(SupportsLMulHigh);}

bool getSupportsLoweringConstLDivPower2() {return _flags2.testAny(SupportsLoweringConstLDivPower2);}
void setSupportsLoweringConstLDivPower2() {_flags2.set(SupportsLoweringConstLDivPower2);}
Expand Down Expand Up @@ -1842,8 +1846,8 @@ class OMR_EXTENSIBLE CodeGenerator
SupportsVirtualGuardNOPing = 0x00000008,
SupportsEfficientNarrowIntComputation = 0x00000010,
SupportsNewInstanceImplOpt = 0x00000020,
SupportsLoweringConstIDiv = 0x00000040,
SupportsLoweringConstLDiv = 0x00000080,
SupportsIMulHigh = 0x00000040,
SupportsLMulHigh = 0x00000080,
SupportsArrayTranslate = 0x00000100,
HasDoubleWordAlignedStack = 0x00000200,
SupportsReadOnlyLocks = 0x00000400,
Expand Down
8 changes: 4 additions & 4 deletions compiler/optimizer/OMRSimplifierHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8690,7 +8690,7 @@ TR::Node *idivSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s)
}
node->getFirstChild()->incReferenceCount();
}
else if (s->cg()->getSupportsLoweringConstIDiv() && !isPowerOf2(divisor) &&
else if (s->cg()->getSupportsIMulHigh() && !isPowerOf2(divisor) &&
performTransformation(s->comp(), "%sMagic number idiv opt in node %p\n", s->optDetailString(), node))
{
// leave idiv as is if the divisor is 2^n. CodeGen generates a fast instruction squence for it.
Expand Down Expand Up @@ -8981,7 +8981,7 @@ TR::Node *ldivSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s)
node->getFirstChild()->incReferenceCount();
}
} // end power of 2
else if (s->cg()->getSupportsLoweringConstLDiv() && !isPowerOf2(divisor))
else if (s->cg()->getSupportsLMulHigh() && !isPowerOf2(divisor))
{
// otherwise, expose the magic number squence to allow optimization
// lowered tree will look like this:
Expand Down Expand Up @@ -9322,7 +9322,7 @@ TR::Node *iremSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s)
}
}
else if (node->getOpCodeValue() == TR::irem &&
s->cg()->getSupportsLoweringConstIDiv() && !isPowerOf2(divisor) &&
s->cg()->getSupportsIMulHigh() && !isPowerOf2(divisor) &&
!skipRemLowering(divisor, s) &&
performTransformation(s->comp(), "%sMagic number irem opt in node %p\n", s->optDetailString(), node))
{
Expand Down Expand Up @@ -9447,7 +9447,7 @@ TR::Node *lremSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s)
}
// Disabled pending approval of design 1055.
#ifdef TR_DESIGN_1055
else if (s->cg()->getSupportsLoweringConstLDiv() && !isPowerOf2(divisor) && !skipRemLowering(divisor, s))
else if (s->cg()->getSupportsLMulHigh() && !isPowerOf2(divisor) && !skipRemLowering(divisor, s))
{
// otherwise, expose the magic number squence to allow optimization
// lowered tree will look like this:
Expand Down
4 changes: 2 additions & 2 deletions compiler/p/codegen/OMRCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ OMR::Power::CodeGenerator::initialize()
cg->setSupportsJavaFloatSemantics();

cg->setSupportsDivCheck();
cg->setSupportsLoweringConstIDiv();
cg->setSupportsIMulHigh();
if (comp->target().is64Bit())
cg->setSupportsLoweringConstLDiv();
cg->setSupportsLMulHigh();
cg->setSupportsLoweringConstLDivPower2();

static bool disableDCAS = (feGetEnv("TR_DisablePPCDCAS") != NULL);
Expand Down
4 changes: 2 additions & 2 deletions compiler/x/codegen/OMRCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,10 @@ OMR::X86::CodeGenerator::initializeX86(TR::Compilation *comp)
static char * enableMulHigh = feGetEnv("TR_X86MulHigh");
if (enableMulHigh)
{
self()->setSupportsLoweringConstIDiv();
self()->setSupportsIMulHigh();

if (comp->target().is64Bit())
self()->setSupportsLoweringConstLDiv();
self()->setSupportsLMulHigh();
}

self()->setSpillsFPRegistersAcrossCalls(); // TODO:AMD64: Are the preserved XMMRs relevant here?
Expand Down
2 changes: 1 addition & 1 deletion compiler/z/codegen/OMRCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ OMR::Z::CodeGenerator::initialize()

cg->setUsesRegisterPairsForLongs();
cg->setSupportsDivCheck();
cg->setSupportsLoweringConstIDiv();
cg->setSupportsIMulHigh();
cg->setSupportsTestUnderMask();

// Initialize to be 8 bytes for bodyInfo / methodInfo
Expand Down

0 comments on commit d458e29

Please sign in to comment.