Skip to content

Commit ef32337

Browse files
authored
[RISC-V] Fix assertion for auipc and lui (#100578)
* [RISC-V] Fix assertion for auipc and lui * [RISC-V] Update codegenriscv64 * [RISC-V] Remove an assert
1 parent 2f189c1 commit ef32337

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/coreclr/jit/codegenriscv64.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -4290,8 +4290,8 @@ int CodeGenInterface::genCallerSPtoInitialSPdelta() const
42904290
// at the end
42914291
static void emitLoadConstAtAddr(emitter* emit, regNumber dstRegister, ssize_t imm)
42924292
{
4293-
ssize_t high = (imm >> 32) & 0xffffffff;
4294-
emit->emitIns_R_I(INS_lui, EA_PTRSIZE, dstRegister, (((high + 0x800) >> 12) & 0xfffff));
4293+
ssize_t high = imm >> 32;
4294+
emit->emitIns_R_I(INS_lui, EA_PTRSIZE, dstRegister, (high + 0x800) >> 12);
42954295
emit->emitIns_R_R_I(INS_addi, EA_PTRSIZE, dstRegister, dstRegister, (high & 0xfff));
42964296

42974297
ssize_t low = imm & 0xffffffff;
@@ -5197,7 +5197,7 @@ void CodeGen::genEmitGSCookieCheck(bool pushReg)
51975197
UINT32 high = ((ssize_t)compiler->gsGlobalSecurityCookieAddr) >> 32;
51985198
if (((high + 0x800) >> 12) != 0)
51995199
{
5200-
GetEmitter()->emitIns_R_I(INS_lui, EA_PTRSIZE, regGSConst, (((high + 0x800) >> 12) & 0xfffff));
5200+
GetEmitter()->emitIns_R_I(INS_lui, EA_PTRSIZE, regGSConst, ((int32_t)(high + 0x800)) >> 12);
52015201
}
52025202
if ((high & 0xFFF) != 0)
52035203
{

src/coreclr/jit/emitriscv64.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ void emitter::emitIns_R_I(instruction ins, emitAttr attr, regNumber reg, ssize_t
479479
case INS_auipc:
480480
assert(reg != REG_R0);
481481
assert(isGeneralRegister(reg));
482-
assert((((size_t)imm) >> 20) == 0);
482+
assert(isValidSimm20(imm));
483483

484484
code |= reg << 7;
485485
code |= (imm & 0xfffff) << 12;
@@ -1253,7 +1253,7 @@ void emitter::emitLoadImmediate(emitAttr size, regNumber reg, ssize_t imm)
12531253
// Since ADDIW use sign extension fo immediate
12541254
// we have to adjust higher 19 bit loaded by LUI
12551255
// for case when low part is bigger than 0x800.
1256-
UINT32 high19 = (high31 + 0x800) >> 12;
1256+
INT32 high19 = ((int32_t)(high31 + 0x800)) >> 12;
12571257

12581258
emitIns_R_I(INS_lui, size, reg, high19);
12591259
emitIns_R_R_I(INS_addiw, size, reg, reg, high31 & 0xFFF);

0 commit comments

Comments
 (0)