Skip to content

Commit 1f688ed

Browse files
authored
[LoongArch64] Fix the assert error for genSetRegToIcon() (#76164)
* [LoongArch64] Fix the assert error for `genSetRegToIcon()` * delete the `genSetRegToIcon()` for LA64.
1 parent 0e13a02 commit 1f688ed

File tree

2 files changed

+19
-32
lines changed

2 files changed

+19
-32
lines changed

src/coreclr/jit/codegen.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ class CodeGen final : public CodeGenInterface
234234
void genJumpToThrowHlpBlk(emitJumpKind jumpKind, SpecialCodeKind codeKind, BasicBlock* failBlk = nullptr);
235235

236236
#ifdef TARGET_LOONGARCH64
237-
void genSetRegToIcon(regNumber reg, ssize_t val, var_types type);
238237
void genJumpToThrowHlpBlk_la(SpecialCodeKind codeKind,
239238
instruction ins,
240239
regNumber reg1,

src/coreclr/jit/codegenloongarch64.cpp

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,21 +1778,25 @@ void CodeGen::genSetRegToConst(regNumber targetReg, var_types targetType, GenTre
17781778
{
17791779
// relocatable values tend to come down as a CNS_INT of native int type
17801780
// so the line between these two opcodes is kind of blurry
1781-
GenTreeIntConCommon* con = tree->AsIntConCommon();
1782-
ssize_t cnsVal = con->IconValue();
1781+
GenTreeIntCon* con = tree->AsIntCon();
1782+
ssize_t cnsVal = con->IconValue();
17831783

1784-
// if (con->ImmedValNeedsReloc(compiler))
1785-
if (con->ImmedValNeedsReloc(compiler) && compiler->opts.compReloc)
1784+
emitAttr attr = emitActualTypeSize(targetType);
1785+
// TODO-CQ: Currently we cannot do this for all handles because of
1786+
// https://github.com/dotnet/runtime/issues/60712
1787+
if (con->ImmedValNeedsReloc(compiler))
17861788
{
1787-
// instGen_Set_Reg_To_Imm(EA_HANDLE_CNS_RELOC, targetReg, cnsVal);
1788-
assert(compiler->opts.compReloc);
1789-
GetEmitter()->emitIns_R_AI(INS_bl, EA_HANDLE_CNS_RELOC, targetReg, cnsVal);
1790-
regSet.verifyRegUsed(targetReg);
1789+
attr = EA_SET_FLG(attr, EA_CNS_RELOC_FLG);
17911790
}
1792-
else
1791+
1792+
if (targetType == TYP_BYREF)
17931793
{
1794-
genSetRegToIcon(targetReg, cnsVal, targetType);
1794+
attr = EA_SET_FLG(attr, EA_BYREF_FLG);
17951795
}
1796+
1797+
instGen_Set_Reg_To_Imm(attr, targetReg, cnsVal,
1798+
INS_FLAGS_DONT_CARE DEBUGARG(con->gtTargetHandle) DEBUGARG(con->gtFlags));
1799+
regSet.verifyRegUsed(targetReg);
17961800
}
17971801
break;
17981802

@@ -2366,7 +2370,7 @@ void CodeGen::genLclHeap(GenTree* tree)
23662370
{
23672371
regCnt = tree->ExtractTempReg();
23682372
}
2369-
genSetRegToIcon(regCnt, amount, ((unsigned int)amount == amount) ? TYP_INT : TYP_LONG);
2373+
instGen_Set_Reg_To_Imm(((unsigned int)amount == amount) ? EA_4BYTE : EA_8BYTE, regCnt, amount);
23702374
}
23712375

23722376
if (compiler->info.compInitMem)
@@ -5662,23 +5666,6 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
56625666
}
56635667
}
56645668

5665-
//------------------------------------------------------------------------
5666-
// genSetRegToIcon: Generate code that will set the given register to the integer constant.
5667-
//
5668-
void CodeGen::genSetRegToIcon(regNumber reg, ssize_t val, var_types type)
5669-
{
5670-
// Reg cannot be a FP reg
5671-
assert(!genIsValidFloatReg(reg));
5672-
5673-
// The only TYP_REF constant that can come this path is a managed 'null' since it is not
5674-
// relocatable. Other ref type constants (e.g. string objects) go through a different
5675-
// code path.
5676-
noway_assert((type != TYP_REF) || (val == 0));
5677-
5678-
GetEmitter()->emitIns_I_la(emitActualTypeSize(type), reg, val);
5679-
regSet.verifyRegUsed(reg);
5680-
}
5681-
56825669
//---------------------------------------------------------------------
56835670
// genSetGSSecurityCookie: Set the "GS" security cookie in the prolog.
56845671
//
@@ -5703,7 +5690,8 @@ void CodeGen::genSetGSSecurityCookie(regNumber initReg, bool* pInitRegZeroed)
57035690
{
57045691
noway_assert(compiler->gsGlobalSecurityCookieVal != 0);
57055692
// initReg = #GlobalSecurityCookieVal; [frame.GSSecurityCookie] = initReg
5706-
genSetRegToIcon(initReg, compiler->gsGlobalSecurityCookieVal, TYP_I_IMPL);
5693+
instGen_Set_Reg_To_Imm(EA_PTRSIZE, initReg, compiler->gsGlobalSecurityCookieVal);
5694+
57075695
GetEmitter()->emitIns_S_R(INS_st_d, EA_PTRSIZE, initReg, compiler->lvaGSSecurityCookie, 0);
57085696
}
57095697
else
@@ -5762,7 +5750,7 @@ void CodeGen::genEmitGSCookieCheck(bool pushReg)
57625750
{
57635751
// load the GS cookie constant into a reg
57645752
//
5765-
genSetRegToIcon(regGSConst, compiler->gsGlobalSecurityCookieVal, TYP_I_IMPL);
5753+
instGen_Set_Reg_To_Imm(EA_PTRSIZE, regGSConst, compiler->gsGlobalSecurityCookieVal);
57665754
}
57675755
else
57685756
{
@@ -6780,7 +6768,7 @@ void CodeGen::genCodeForIndexAddr(GenTreeIndexAddr* node)
67806768
else // we have to load the element size and use a MADD (multiply-add) instruction
67816769
{
67826770
// REG_R21 = element size
6783-
CodeGen::genSetRegToIcon(REG_R21, (ssize_t)node->gtElemSize, TYP_INT);
6771+
instGen_Set_Reg_To_Imm(EA_4BYTE, REG_R21, (ssize_t)node->gtElemSize);
67846772

67856773
// dest = index * REG_R21 + base
67866774
instruction ins;

0 commit comments

Comments
 (0)