Skip to content

Commit 6279ead

Browse files
committed
On x86 for int64 compare, we need to compare the low bits using unsigned comparisons.
This removes the need for the hack to prevent cmp src swapping.
1 parent a7ebceb commit 6279ead

4 files changed

Lines changed: 33 additions & 20 deletions

File tree

lib/Backend/IR.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,6 @@ class BranchInstr : public Instr
736736
bool m_isAirlock : 1;
737737
bool m_isSwitchBr : 1;
738738
bool m_isOrphanedLeave : 1; // A Leave in a loop body in a try, most likely generated because of a return statement.
739-
bool m_areCmpRegisterFlagsUsedLater : 1; // Indicate that this branch is not the only instr using the register flags set by cmp
740739
#if DBG
741740
bool m_isMultiBranch;
742741
bool m_isHelperToNonHelperBranch;
@@ -748,7 +747,7 @@ class BranchInstr : public Instr
748747
static BranchInstr * New(Js::OpCode opcode, Opnd* destOpnd, LabelInstr * branchTarget, Opnd *srcOpnd, Func *func);
749748
static BranchInstr * New(Js::OpCode opcode, LabelInstr * branchTarget, Opnd *src1Opnd, Opnd *src2Opnd, Func *func);
750749

751-
BranchInstr(bool hasBailOutInfo = false) : Instr(hasBailOutInfo), m_branchTarget(nullptr), m_isAirlock(false), m_isSwitchBr(false), m_isOrphanedLeave(false), m_areCmpRegisterFlagsUsedLater(false)
750+
BranchInstr(bool hasBailOutInfo = false) : Instr(hasBailOutInfo), m_branchTarget(nullptr), m_isAirlock(false), m_isSwitchBr(false), m_isOrphanedLeave(false)
752751
{
753752
#if DBG
754753
m_isMultiBranch = false;

lib/Backend/LowerMDShared.cpp

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,22 +2856,6 @@ void LowererMD::GenerateFastCmXx(IR::Instr *instr)
28562856
done->InsertBefore(newInstr);
28572857
}
28582858

2859-
#ifndef _M_X64
2860-
if (isInt64Src)
2861-
{
2862-
IR::LabelInstr* skipLow = IR::LabelInstr::New(Js::OpCode::Label, m_func);
2863-
newInstr = IR::BranchInstr::New(Js::OpCode::JNE, skipLow, this->m_func);
2864-
newInstr->AsBranchInstr()->m_areCmpRegisterFlagsUsedLater = true;
2865-
done->InsertBefore(newInstr);
2866-
2867-
newInstr = IR::Instr::New(cmpOp, this->m_func);
2868-
newInstr->SetSrc1(src1Pair.low);
2869-
newInstr->SetSrc2(src2Pair.low);
2870-
done->InsertBefore(newInstr);
2871-
done->InsertBefore(skipLow);
2872-
}
2873-
#endif
2874-
28752859
if (!isIntDst)
28762860
{
28772861
opnd = this->m_lowerer->LoadLibraryValueOpnd(instr, LibraryValue::ValueFalse);
@@ -2950,6 +2934,36 @@ void LowererMD::GenerateFastCmXx(IR::Instr *instr)
29502934
}
29512935
done->InsertBefore(newInstr);
29522936

2937+
#ifndef _M_X64
2938+
if (isInt64Src)
2939+
{
2940+
IR::LabelInstr* skipLow = IR::LabelInstr::New(Js::OpCode::Label, m_func);
2941+
newInstr = IR::BranchInstr::New(Js::OpCode::JNE, skipLow, this->m_func);
2942+
done->InsertBefore(newInstr);
2943+
2944+
newInstr = IR::Instr::New(cmpOp, this->m_func);
2945+
newInstr->SetSrc1(src1Pair.low);
2946+
newInstr->SetSrc2(src2Pair.low);
2947+
done->InsertBefore(newInstr);
2948+
2949+
Js::OpCode lowUseCC = useCC;
2950+
// Need to do an unsigned compare for the lower part
2951+
switch (instr->m_opcode)
2952+
{
2953+
case Js::OpCode::CmGe_I4: lowUseCC = Js::OpCode::SETAE; break;
2954+
case Js::OpCode::CmGt_I4: lowUseCC = Js::OpCode::SETA; break;
2955+
case Js::OpCode::CmLe_I4: lowUseCC = Js::OpCode::SETBE; break;
2956+
case Js::OpCode::CmLt_I4: lowUseCC = Js::OpCode::SETB; break;
2957+
}
2958+
2959+
// tmp.i8 = SetCC tmp.i8
2960+
IR::Opnd *tmp_i8 = tmp->UseWithNewType(TyInt8, this->m_func);
2961+
newInstr = IR::Instr::New(lowUseCC, tmp_i8, tmp_i8, this->m_func);
2962+
done->InsertBefore(newInstr);
2963+
done->InsertBefore(skipLow);
2964+
}
2965+
#endif
2966+
29532967
if (tmp != dst)
29542968
{
29552969
newInstr = IR::Instr::New(Js::OpCode::MOV, dst, tmp, this->m_func);

lib/Backend/amd64/EncoderMD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,7 @@ bool EncoderMD::TryFold(IR::Instr *instr, IR::RegOpnd *regOpnd)
18851885
{
18861886
IR::Instr *instrNext = instr->GetNextRealInstrOrLabel();
18871887

1888-
if (instrNext->IsBranchInstr() && instrNext->AsBranchInstr()->IsConditional() && !instrNext->AsBranchInstr()->m_areCmpRegisterFlagsUsedLater)
1888+
if (instrNext->IsBranchInstr() && instrNext->AsBranchInstr()->IsConditional())
18891889
{
18901890
// Swap src and reverse branch
18911891
src2 = instr->UnlinkSrc1();

lib/Backend/i386/EncoderMD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ bool EncoderMD::TryFold(IR::Instr *instr, IR::RegOpnd *regOpnd)
17001700
{
17011701
IR::Instr *instrNext = instr->GetNextRealInstrOrLabel();
17021702

1703-
if (instrNext->IsBranchInstr() && instrNext->AsBranchInstr()->IsConditional() && !instrNext->AsBranchInstr()->m_areCmpRegisterFlagsUsedLater)
1703+
if (instrNext->IsBranchInstr() && instrNext->AsBranchInstr()->IsConditional())
17041704
{
17051705
// Swap src and reverse branch
17061706
src2 = instr->UnlinkSrc1();

0 commit comments

Comments
 (0)