Skip to content

Commit cc3035f

Browse files
committed
Perform type specialization when either source is float. Update destination value to boolean.
1 parent 704e088 commit cc3035f

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

lib/Backend/GlobOpt.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10473,6 +10473,7 @@ GlobOpt::TypeSpecializeFloatBinary(IR::Instr *instr, Value *src1Val, Value *src2
1047310473
bool skipSrc1 = false;
1047410474
bool skipSrc2 = false;
1047510475
bool skipDst = false;
10476+
bool convertDstToBool = false;
1047610477

1047710478
if (!this->DoFloatTypeSpec())
1047810479
{
@@ -10544,6 +10545,19 @@ GlobOpt::TypeSpecializeFloatBinary(IR::Instr *instr, Value *src1Val, Value *src2
1054410545
skipDst = true;
1054510546
break;
1054610547

10548+
case Js::OpCode::CmEq_A:
10549+
case Js::OpCode::CmSrEq_A:
10550+
case Js::OpCode::CmNeq_A:
10551+
case Js::OpCode::CmSrNeq_A:
10552+
case Js::OpCode::CmLe_A:
10553+
case Js::OpCode::CmLt_A:
10554+
case Js::OpCode::CmGe_A:
10555+
case Js::OpCode::CmGt_A:
10556+
{
10557+
convertDstToBool = true;
10558+
break;
10559+
}
10560+
1054710561
default:
1054810562
return false;
1054910563
}
@@ -10589,13 +10603,19 @@ GlobOpt::TypeSpecializeFloatBinary(IR::Instr *instr, Value *src1Val, Value *src2
1058910603
if (!skipDst)
1059010604
{
1059110605
dst = instr->GetDst();
10592-
1059310606
if (dst)
1059410607
{
10595-
*pDstVal = CreateDstUntransferredValue(ValueType::Float, instr, src1Val, src2Val);
10596-
10597-
AssertMsg(dst->IsRegOpnd(), "What else?");
10598-
this->ToFloat64Dst(instr, dst->AsRegOpnd(), this->currentBlock);
10608+
if (convertDstToBool)
10609+
{
10610+
*pDstVal = CreateDstUntransferredValue(ValueType::Boolean, instr, src1Val, src2Val);
10611+
ToVarRegOpnd(dst->AsRegOpnd(), currentBlock);
10612+
}
10613+
else
10614+
{
10615+
*pDstVal = CreateDstUntransferredValue(ValueType::Float, instr, src1Val, src2Val);
10616+
AssertMsg(dst->IsRegOpnd(), "What else?");
10617+
this->ToFloat64Dst(instr, dst->AsRegOpnd(), this->currentBlock);
10618+
}
1059910619
}
1060010620
}
1060110621

lib/Backend/LowerMDShared.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2653,9 +2653,7 @@ void LowererMD::GenerateFastCmXx(IR::Instr *instr)
26532653
bool isFloatSrc = src1->IsFloat();
26542654
bool isInt64Src = src1->IsInt64();
26552655
Assert(!isFloatSrc || src2->IsFloat());
2656-
Assert(!isFloatSrc || isIntDst);
26572656
Assert(!isInt64Src || src2->IsInt64());
2658-
Assert(!isInt64Src || isIntDst);
26592657
Assert(!isFloatSrc || AutoSystemInfo::Data.SSE2Available());
26602658
IR::Opnd *opnd;
26612659
IR::Instr *newInstr;
@@ -2684,16 +2682,18 @@ void LowererMD::GenerateFastCmXx(IR::Instr *instr)
26842682
done = instr;
26852683
}
26862684

2685+
bool isNegOpt = instr->m_opcode == Js::OpCode::CmNeq_A || instr->m_opcode == Js::OpCode::CmSrNeq_A;
26872686
if (isIntDst)
26882687
{
2688+
// Fast path for float src when destination is type specialized to int
26892689
// reg = MOV 0 will get peeped to XOR reg, reg which sets the flags.
26902690
// Put the MOV before the CMP, but use a tmp if dst == src1/src2
26912691
if (dst->IsEqual(src1) || dst->IsEqual(src2))
26922692
{
26932693
tmp = IR::RegOpnd::New(dst->GetType(), this->m_func);
26942694
}
26952695
// dst = MOV 0
2696-
if (isFloatSrc && instr->m_opcode == Js::OpCode::CmNeq_A)
2696+
if (isFloatSrc && isNegOpt)
26972697
{
26982698
opnd = IR::IntConstOpnd::New(1, TyInt32, this->m_func);
26992699
}
@@ -2703,6 +2703,20 @@ void LowererMD::GenerateFastCmXx(IR::Instr *instr)
27032703
}
27042704
m_lowerer->InsertMove(tmp, opnd, done);
27052705
}
2706+
else if (isFloatSrc)
2707+
{
2708+
// Fast path for float src when destination is not type specialized to int
2709+
// Assign default value for destination in case either src is NaN
2710+
if (isNegOpt)
2711+
{
2712+
opnd = this->m_lowerer->LoadLibraryValueOpnd(instr, LibraryValue::ValueTrue);
2713+
}
2714+
else
2715+
{
2716+
opnd = this->m_lowerer->LoadLibraryValueOpnd(instr, LibraryValue::ValueFalse);
2717+
}
2718+
Lowerer::InsertMove(tmp, opnd, done);
2719+
}
27062720

27072721
Js::OpCode cmpOp;
27082722
if (isFloatSrc)
@@ -2744,11 +2758,13 @@ void LowererMD::GenerateFastCmXx(IR::Instr *instr)
27442758
{
27452759
case Js::OpCode::CmEq_I4:
27462760
case Js::OpCode::CmEq_A:
2761+
case Js::OpCode::CmSrEq_A:
27472762
useCC = isIntDst ? Js::OpCode::SETE : Js::OpCode::CMOVE;
27482763
break;
27492764

27502765
case Js::OpCode::CmNeq_I4:
27512766
case Js::OpCode::CmNeq_A:
2767+
case Js::OpCode::CmSrNeq_A:
27522768
useCC = isIntDst ? Js::OpCode::SETNE : Js::OpCode::CMOVNE;
27532769
break;
27542770

0 commit comments

Comments
 (0)