Skip to content

Commit

Permalink
[LoongArch64] Fix some bugs in the test sets 'System.Runtime.Tests' a…
Browse files Browse the repository at this point in the history
…nd 'System.Linq.Expressions.Tests' for loongarch64. (#86435)

* Fix the error of the Truncate/Saturate convert from Float/Double NAN to UINT32/UINT64.
* fix some random failed testcases in System.Runtime.Tests.

* Update codegenloongarch64.cpp

Fix the RangeCheck bug of the TYP_INT case in CodeGen::genRangeCheck().
  • Loading branch information
LuckyXu-HF authored May 22, 2023
1 parent f11e9ac commit b380e2c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5827,7 +5827,7 @@ void CodeGen::genFnProlog()
//
extraFrameSize = compiler->compCalleeRegsPushed * REGSIZE_BYTES;
}
#endif // TARGET_ARM64
#endif // TARGET_AMD64

if (doubleAlignOrFramePointerUsed())
{
Expand Down
29 changes: 23 additions & 6 deletions src/coreclr/jit/codegenloongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3877,17 +3877,24 @@ void CodeGen::genFloatToIntCast(GenTree* treeNode)
}

if (srcType == TYP_DOUBLE)
{
GetEmitter()->emitIns_R_R_I(INS_lu52i_d, EA_8BYTE, REG_R21, REG_R0, imm >> 8);
}
else
{
GetEmitter()->emitIns_R_I(INS_lu12i_w, EA_PTRSIZE, REG_R21, imm);
}

GetEmitter()->emitIns_R_R(srcType == TYP_DOUBLE ? INS_movgr2fr_d : INS_movgr2fr_w, EA_8BYTE, tmpReg, REG_R21);

GetEmitter()->emitIns_R_R_I(srcType == TYP_DOUBLE ? INS_fcmp_clt_d : INS_fcmp_clt_s, EA_8BYTE, op1->GetRegNum(),
tmpReg, 2);
tmpReg, 2); // cc=2

GetEmitter()->emitIns_R_R_I(srcType == TYP_DOUBLE ? INS_fcmp_ceq_d : INS_fcmp_ceq_s, EA_8BYTE, op1->GetRegNum(),
tmpReg, 3); // cc=3

GetEmitter()->emitIns_R_R_I(INS_ori, EA_PTRSIZE, REG_R21, REG_R0, 0);
GetEmitter()->emitIns_I_I(INS_bcnez, EA_PTRSIZE, 2, 4 << 2);
GetEmitter()->emitIns_I_I(INS_bcnez, EA_PTRSIZE, 2, 4 << 2); // cc=2

GetEmitter()->emitIns_R_R_R(srcType == TYP_DOUBLE ? INS_fsub_d : INS_fsub_s, EA_8BYTE, tmpReg, op1->GetRegNum(),
tmpReg);
Expand All @@ -3901,6 +3908,9 @@ void CodeGen::genFloatToIntCast(GenTree* treeNode)
GetEmitter()->emitIns_R_R(ins1, dstSize, tmpReg, tmpReg);
GetEmitter()->emitIns_R_R(ins2, dstSize, treeNode->GetRegNum(), tmpReg);

GetEmitter()->emitIns_I_I(INS_bcnez, EA_PTRSIZE, 3, 2 << 2); // cc=3
GetEmitter()->emitIns_R_I(INS_beqz, EA_PTRSIZE, treeNode->GetRegNum(), 2 << 2);

GetEmitter()->emitIns_R_R_R(INS_or, dstSize, treeNode->GetRegNum(), REG_R21, treeNode->GetRegNum());
}
else
Expand Down Expand Up @@ -4104,20 +4114,22 @@ void CodeGen::genCodeForCompare(GenTreeOp* tree)
switch (cmpSize)
{
case EA_4BYTE:
{
regNumber tmpRegOp1 = REG_R21;
assert(regOp1 != tmpRegOp1);
if (IsUnsigned)
{
imm = static_cast<uint32_t>(imm);

regNumber tmpRegOp1 = REG_R21;
assert(regOp1 != tmpRegOp1);
emit->emitIns_R_R_I_I(INS_bstrpick_d, EA_8BYTE, tmpRegOp1, regOp1, 31, 0);
regOp1 = tmpRegOp1;
}
else
{
imm = static_cast<int32_t>(imm);
emit->emitIns_R_R_I(INS_slli_w, EA_8BYTE, tmpRegOp1, regOp1, 0);
}
regOp1 = tmpRegOp1;
break;
}
case EA_8BYTE:
break;
case EA_1BYTE:
Expand Down Expand Up @@ -5932,6 +5944,11 @@ void CodeGen::genRangeCheck(GenTree* oper)
}
else
{
if (genActualType(src1->TypeGet()) == TYP_INT)
{
GetEmitter()->emitIns_R_R_I(INS_slli_w, EA_4BYTE, REG_R21, reg1, 0);
reg1 = REG_R21;
}
reg2 = src2->GetRegNum();
}
}
Expand Down

0 comments on commit b380e2c

Please sign in to comment.