@@ -8127,28 +8127,44 @@ void LowererMD::GenerateFastInlineBuiltInCall(IR::Instr* instr, IR::JnHelperMeth
8127
8127
8128
8128
bool min = instr->m_opcode == Js::OpCode::InlineMathMin ? true : false ;
8129
8129
8130
+ bool dstEqualsSrc1 = dst->IsEqual (src1);
8131
+ bool dstEqualsSrc2 = dst->IsEqual (src2);
8132
+
8133
+ IR::Opnd * otherSrc = src2;
8134
+ IR::Opnd * compareSrc1 = src1;
8135
+ IR::Opnd * compareSrc2 = src2;
8136
+
8137
+ if (dstEqualsSrc2)
8138
+ {
8139
+ otherSrc = src1;
8140
+ compareSrc1 = src2;
8141
+ compareSrc2 = src1;
8142
+ }
8143
+ if (!dstEqualsSrc1 && !dstEqualsSrc2)
8144
+ {
8145
+ // MOV dst, src1;
8146
+ this ->m_lowerer ->InsertMove (dst, src1, instr);
8147
+ }
8148
+
8130
8149
// CMP src1, src2
8131
8150
if (dst->IsInt32 ())
8132
- {
8133
- // MOV dst, src2;
8134
- Assert (!dst->IsEqual (src2));
8135
- this ->m_lowerer ->InsertMove (dst, src2, instr);
8151
+ {
8136
8152
if (min)
8137
8153
{
8138
8154
// JLT $continueLabel
8139
- branchInstr = IR::BranchInstr::New (Js::OpCode::BrGt_I4 , doneLabel, src1, src2 , instr->m_func );
8155
+ branchInstr = IR::BranchInstr::New (Js::OpCode::BrLt_I4 , doneLabel, compareSrc1, compareSrc2 , instr->m_func );
8140
8156
instr->InsertBefore (branchInstr);
8141
8157
LowererMDArch::EmitInt4Instr (branchInstr);
8142
8158
}
8143
8159
else
8144
8160
{
8145
8161
// JGT $continueLabel
8146
- branchInstr = IR::BranchInstr::New (Js::OpCode::BrLt_I4 , doneLabel, src1, src2 , instr->m_func );
8162
+ branchInstr = IR::BranchInstr::New (Js::OpCode::BrGt_I4 , doneLabel, compareSrc1, compareSrc2 , instr->m_func );
8147
8163
instr->InsertBefore (branchInstr);
8148
8164
LowererMDArch::EmitInt4Instr (branchInstr);
8149
8165
}
8150
8166
// MOV dst, src1
8151
- this ->m_lowerer ->InsertMove (dst, src1 , instr);
8167
+ this ->m_lowerer ->InsertMove (dst, otherSrc , instr);
8152
8168
}
8153
8169
else if (dst->IsFloat ())
8154
8170
{
@@ -8177,33 +8193,29 @@ void LowererMD::GenerateFastInlineBuiltInCall(IR::Instr* instr, IR::JnHelperMeth
8177
8193
//
8178
8194
// $doneLabel
8179
8195
8180
- // MOVSD/MOVSS dst, src1;
8181
- Assert (!dst->IsEqual (src1));
8182
-
8183
- this ->m_lowerer ->InsertMove (dst, src1, instr);
8184
8196
if (min)
8185
8197
{
8186
- this ->m_lowerer ->InsertCompareBranch (src1, src2 , Js::OpCode::BrLt_A, doneLabel, instr); // Lowering of BrLt_A for floats is done to JA with operands swapped
8198
+ this ->m_lowerer ->InsertCompareBranch (compareSrc1, compareSrc2 , Js::OpCode::BrLt_A, doneLabel, instr); // Lowering of BrLt_A for floats is done to JA with operands swapped
8187
8199
}
8188
8200
else
8189
8201
{
8190
- this ->m_lowerer ->InsertCompareBranch (src1, src2 , Js::OpCode::BrGt_A, doneLabel, instr);
8202
+ this ->m_lowerer ->InsertCompareBranch (compareSrc1, compareSrc2 , Js::OpCode::BrGt_A, doneLabel, instr);
8191
8203
}
8192
8204
8193
8205
instr->InsertBefore (IR::BranchInstr::New (Js::OpCode::JEQ, labelNegZeroAndNaNCheckHelper, instr->m_func ));
8194
8206
8195
- this ->m_lowerer ->InsertMove (dst, src2 , instr);
8207
+ this ->m_lowerer ->InsertMove (dst, otherSrc , instr);
8196
8208
instr->InsertBefore (IR::BranchInstr::New (Js::OpCode::JMP, doneLabel, instr->m_func ));
8197
8209
8198
8210
instr->InsertBefore (labelNegZeroAndNaNCheckHelper);
8199
8211
8200
8212
instr->InsertBefore (IR::BranchInstr::New (Js::OpCode::JP, labelNaNHelper, instr->m_func ));
8201
8213
8202
8214
IR::LabelInstr *isNeg0Label = IR::LabelInstr::New (Js::OpCode::Label, m_func, true );
8203
- NegZeroBranching (min ? src2 : src1 , instr, isNeg0Label, doneLabel);
8215
+ NegZeroBranching (min ? compareSrc2 : compareSrc1 , instr, isNeg0Label, doneLabel);
8204
8216
instr->InsertBefore (isNeg0Label);
8205
8217
8206
- this ->m_lowerer ->InsertMove (dst, src2 , instr);
8218
+ this ->m_lowerer ->InsertMove (dst, otherSrc , instr);
8207
8219
instr->InsertBefore (IR::BranchInstr::New (Js::OpCode::JMP, doneLabel, instr->m_func ));
8208
8220
8209
8221
instr->InsertBefore (labelNaNHelper);
0 commit comments