Skip to content

Commit

Permalink
Merge pull request #5263 from knn-k/aarch64cmnimm
Browse files Browse the repository at this point in the history
AArch64: Allow negative constant for generateCompareImmInstruction()
  • Loading branch information
0xdaryl authored Jun 2, 2020
2 parents 2ad3c23 + 3504807 commit 16d5a51
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
22 changes: 19 additions & 3 deletions compiler/aarch64/codegen/ARM64Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,15 +916,31 @@ TR_Debug::print(TR::FILE *pOutFile, TR::ARM64Trg1Src1ImmInstruction *instr)
printPrefix(pOutFile, instr);
TR::InstOpCode::Mnemonic op = instr->getOpCodeValue();
bool done = false;
if (op == TR::InstOpCode::subsimmx || op == TR::InstOpCode::subsimmw)
if (op == TR::InstOpCode::subsimmx || op == TR::InstOpCode::subsimmw ||
op == TR::InstOpCode::addsimmx || op == TR::InstOpCode::addsimmw)
{
TR::Register *r = instr->getTargetRegister();
if (r && r->getRealRegister()
&& toRealRegister(r)->getRegisterNumber() == TR::RealRegister::xzr)
{
// cmp alias
// cmp/cmn alias
char *mnemonic = NULL;
done = true;
trfprintf(pOutFile, "cmpimm%c \t", (op == TR::InstOpCode::subsimmx) ? 'x' : 'w');
switch (op)
{
case TR::InstOpCode::subsimmx:
mnemonic = "cmpimmx";
break;
case TR::InstOpCode::subsimmw:
mnemonic = "cmpimmw";
break;
case TR::InstOpCode::addsimmx:
mnemonic = "cmnimmx";
break;
case TR::InstOpCode::addsimmw:
mnemonic = "cmnimmw";
}
trfprintf(pOutFile, "%s \t", mnemonic);
print(pOutFile, instr->getSource1Register(), TR_WordReg);
trfprintf(pOutFile, ", %d", instr->getSourceImmediate());
}
Expand Down
10 changes: 10 additions & 0 deletions compiler/aarch64/codegen/ControlFlowEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ if (cg->profiledPointersRequireRelocation() && secondChild->getOpCodeValue() ==
generateCompareImmInstruction(cg, node, src1Reg, value, is64bit);
useRegCompare = false;
}
else if (constantIsUnsignedImm12(-value))
{
generateCompareImmInstruction(cg, node, src1Reg, value, is64bit);
useRegCompare = false;
}
}

if (useRegCompare)
Expand Down Expand Up @@ -332,6 +337,11 @@ static TR::Register *icmpHelper(TR::Node *node, TR::ARM64ConditionCode cc, bool
generateCompareImmInstruction(cg, node, src1Reg, value, is64bit);
useRegCompare = false;
}
else if (constantIsUnsignedImm12(-value))
{
generateCompareImmInstruction(cg, node, src1Reg, value, is64bit);
useRegCompare = false;
}
}

if (useRegCompare)
Expand Down
19 changes: 15 additions & 4 deletions compiler/aarch64/codegen/GenerateInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,21 @@ static TR::Instruction *generateZeroSrc1ImmInstruction(TR::CodeGenerator *cg, TR
TR::Instruction *generateCompareImmInstruction(TR::CodeGenerator *cg, TR::Node *node,
TR::Register *sreg, int32_t imm, bool is64bit, TR::Instruction *preced)
{
/* Alias of SUBS instruction */

TR::InstOpCode::Mnemonic op = is64bit ? TR::InstOpCode::subsimmx : TR::InstOpCode::subsimmw;
TR_ASSERT_FATAL(constantIsUnsignedImm12(imm), "Immediate value is out of range for subsimm");
TR::InstOpCode::Mnemonic op;

if (constantIsUnsignedImm12(imm))
{
/* Alias of SUBS instruction */
op = is64bit ? TR::InstOpCode::subsimmx : TR::InstOpCode::subsimmw;
}
else
{
TR_ASSERT_FATAL(constantIsUnsignedImm12(-imm), "Immediate value is out of range for cmp/cmn");

/* Alias of ADDS instruction */
op = is64bit ? TR::InstOpCode::addsimmx : TR::InstOpCode::addsimmw;
imm = -imm;
}

return generateZeroSrc1ImmInstruction(cg, op, node, sreg, imm, preced);
}
Expand Down

0 comments on commit 16d5a51

Please sign in to comment.