Skip to content

Commit

Permalink
Merge pull request #6937 from BradleyWood/stkmr
Browse files Browse the repository at this point in the history
Fix Large VFP-relative memory-references
  • Loading branch information
0xdaryl authored May 5, 2023
2 parents de6212d + cf7b216 commit e4f52d2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
34 changes: 14 additions & 20 deletions compiler/x/amd64/codegen/OMRMemoryReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ void OMR::X86::AMD64::MemoryReference::finishInitialization(
{
mightNeedAddressRegister = true;
}
else if (sr.getSymbol() != NULL && (sr.isUnresolved() || (sr.stackAllocatedArrayAccess() && !IS_32BIT_SIGNED(self()->getDisplacement()))))
{
// Once resolved, the address could be anything, so be conservative.
//
mightNeedAddressRegister = true;
}
else if (self()->getBaseRegister() == cg->getFrameRegister())
{
// We should never see stack frames 2GB in size, so don't waste a register.
Expand All @@ -198,12 +204,6 @@ void OMR::X86::AMD64::MemoryReference::finishInitialization(
//
mightNeedAddressRegister = false;
}
else if (sr.getSymbol() != NULL && sr.isUnresolved())
{
// Once resolved, the address could be anything, so be conservative.
//
mightNeedAddressRegister = true;
}
else if (comp->getOption(TR_EnableHCR) && sr.getSymbol() && sr.getSymbol()->isClassObject())
{
// Can't do any displacement-based tests because the displacement can change
Expand Down Expand Up @@ -379,18 +379,14 @@ uint32_t OMR::X86::AMD64::MemoryReference::estimateBinaryLength(TR::CodeGenerato
_addressRegister = NULL;
}

if (_addressRegister == NULL)
{
// Just use inherited logic
//
estimate = OMR::X86::MemoryReference::estimateBinaryLength(cg);
estimate = OMR::X86::MemoryReference::estimateBinaryLength(cg);

// For [disp32], AMD64 needs a SIB byte
//
if (_baseRegister == NULL && _indexRegister == NULL)
estimate += 1;
}
else
// For [disp32], AMD64 needs a SIB byte
//
if (_baseRegister == NULL && _indexRegister == NULL)
estimate += 1;

if (_addressRegister != NULL)
{

// TODO:AMD64: Should be able to do a tighter estimate than this
Expand All @@ -399,12 +395,10 @@ uint32_t OMR::X86::AMD64::MemoryReference::estimateBinaryLength(TR::CodeGenerato
// great big load instruction. Thus, the size we use for the estimate is
// the size after adding the big load instruction.)
//
estimate = IMM64_LOAD_SIZE + MAX_MEMREF_SIZE;

estimate += IMM64_LOAD_SIZE;
}

return estimate;

}


Expand Down
6 changes: 3 additions & 3 deletions compiler/x/codegen/OMRMemoryReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ OMR::X86::MemoryReference::assignRegisters(
{
// Note: a MemRef can be used only once -- if you want to reuse make a copy using
// generateX86MemoryReference(OMR::X86::MemoryReference &, intptr_t, TR::CodeGenerator *cg).
TR_ASSERT(!_baseRegister->getRealRegister(),"_baseRegister is a Real Register already, are you reusing a Memory Reference?");
TR_ASSERT_FATAL(!_baseRegister->getRealRegister(),"_baseRegister is a Real Register already, are you reusing a Memory Reference?");
assignedBaseRegister = assignGPRegister(currentInstruction, _baseRegister, TR_WordReg, cg);
}

Expand Down Expand Up @@ -1588,7 +1588,7 @@ OMR::X86::MemoryReference::generateBinaryEncoding(

if (baseRegisterNumber == TR::RealRegister::vfp)
{
TR_ASSERT(cg->machine()->getRealRegister(baseRegisterNumber)->getAssignedRealRegister(),
TR_ASSERT_FATAL(cg->machine()->getRealRegister(baseRegisterNumber)->getAssignedRealRegister(),
"virtual frame pointer must be assigned before binary encoding!\n");

base = toRealRegister(cg->machine()->
Expand All @@ -1605,7 +1605,7 @@ OMR::X86::MemoryReference::generateBinaryEncoding(
}

displacement = self()->getDisplacement();
TR_ASSERT(IS_32BIT_SIGNED(displacement), "64-bit displacement should have been replaced in TR_AMD64MemoryReference::generateBinaryEncoding");
TR_ASSERT_FATAL(IS_32BIT_SIGNED(displacement), "64-bit displacement should have been replaced in TR_AMD64MemoryReference::generateBinaryEncoding");

if (!isForceWideDisplacement() && isEvex && (displacement % displacementDivisor) == 0 && IS_8BIT_SIGNED(displacement / displacementDivisor))
{
Expand Down
5 changes: 5 additions & 0 deletions compiler/x/codegen/OMRMemoryReference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,14 @@ class OMR_EXTENSIBLE MemoryReference : public OMR::MemoryReference
//
TR::Register *baseRegister;
if (toRealRegister(_baseRegister)->getRegisterNumber() == TR::RealRegister::vfp)
{
baseRegister = toRealRegister(_baseRegister)->getAssignedRealRegister();
TR_ASSERT_FATAL(baseRegister, "virtual frame pointer must be assigned before binary encoding!\n");
}
else
{
baseRegister = _baseRegister;
}
rxbBits |= toRealRegister(baseRegister)->rexBits(TR::RealRegister::REX_B, false);
}
if (_indexRegister)
Expand Down

0 comments on commit e4f52d2

Please sign in to comment.