-
Notifications
You must be signed in to change notification settings - Fork 5k
Fix relocs for linux-riscv64 AOT #112331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix relocs for linux-riscv64 AOT #112331
Conversation
GenTreeIntCon* con = op2->AsIntCon(); | ||
|
||
emitAttr attr = emitActualTypeSize(op2Type); | ||
// TODO-CQ: Currently we cannot do this for all handles because of | ||
// https://github.com/dotnet/runtime/issues/60712 | ||
if (con->ImmedValNeedsReloc(compiler)) | ||
{ | ||
attr = EA_SET_FLG(attr, EA_CNS_RELOC_FLG); | ||
} | ||
|
||
if (op2Type == TYP_BYREF) | ||
{ | ||
attr = EA_SET_FLG(attr, EA_BYREF_FLG); | ||
} | ||
|
||
instGen_Set_Reg_To_Imm(attr, REG_RA, imm, | ||
INS_FLAGS_DONT_CARE DEBUGARG(con->gtTargetHandle) DEBUGARG(con->gtFlags)); | ||
regSet.verifyRegUsed(REG_RA); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: looks like the CNS_INT case does the same (it's unused now). Can we just call genSetRegToConst?
runtime/src/coreclr/jit/codegenriscv64.cpp
Lines 1057 to 1085 in 02f99e5
void CodeGen::genSetRegToConst(regNumber targetReg, var_types targetType, GenTree* tree) | |
{ | |
switch (tree->gtOper) | |
{ | |
case GT_CNS_INT: | |
{ | |
// relocatable values tend to come down as a CNS_INT of native int type | |
// so the line between these two opcodes is kind of blurry | |
GenTreeIntCon* con = tree->AsIntCon(); | |
ssize_t cnsVal = con->IconValue(); | |
emitAttr attr = emitActualTypeSize(targetType); | |
// TODO-RISCV64-CQ: Currently we cannot do this for all handles because of | |
// https://github.com/dotnet/runtime/issues/60712 | |
if (con->ImmedValNeedsReloc(compiler)) | |
{ | |
attr = EA_SET_FLG(attr, EA_CNS_RELOC_FLG); | |
} | |
if (targetType == TYP_BYREF) | |
{ | |
attr = EA_SET_FLG(attr, EA_BYREF_FLG); | |
} | |
instGen_Set_Reg_To_Imm(attr, targetReg, cnsVal, | |
INS_FLAGS_DONT_CARE DEBUGARG(con->gtTargetHandle) DEBUGARG(con->gtFlags)); | |
regSet.verifyRegUsed(targetReg); | |
} | |
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is static_cast uint vs. int. If the value returned by op2->AsIntCon()->gtIconVal
is negative, cond.IsUnsigned()
is true, then cast to uint32_t
will reinterpret it as a large positive number and cast to int32_t
in else
will keep it negative.
I can't tell if ignoring the signedness has any side-effects in this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The relocatable constants should be pointer sized, so they will not be going through the EA_4BYTE
case with the casts above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jakobbotsch, instGen_Set_Reg_To_Imm(attr, REG_RA, imm,
is called for both EA_4BYTE
and EA_8BYTE
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. It seems like a RISCV64 version of genSetRegToConst
would need to come with an extra argument about whether 32-bit constants should be sign or zero extended given that the full 64-bit register is expected to be used by callers afterwards.
So I agree it probably can't be used directly here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let's leave it. Technically you could ABI-extend both sides (sign-extend from 32-bits up to full register, regardless of type's signedness), then the unsigned comparison on the whole register works correctly.
I hope to get to it this year, we've got plenty of unnecessary extension instructions, e.g. the register operand here is already ABI-extended in many cases.
13cfb9d is being scheduled for building and testingGIT: Release-FX-tests FAILEDbuildinfo.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handles can show up in a number of JIT nodes. It seems likely a similar fix will be needed in other places too.
* main: Code clean up in AP for NonNull* (dotnet#112027) JIT: Invalidate LSRA's DFS tree if we aren't running new layout phase (dotnet#112364) Update dependencies from https://github.com/dotnet/source-build-reference-packages build 20250204.2 (dotnet#112339) Add doc on OS onboarding (dotnet#112026) Add `TypeName` APIs to simplify metadata lookup. (dotnet#111598) Internal monitor impl not using coop mutex causing deadlocks on Android. (dotnet#112358) Do not run NAOT arm64 OSX testing on all PRs (dotnet#112342) Special-case empty enumerables in AsyncEnumerable (dotnet#112321) Have mono handle ConvertToIntegerNative for Double and Single (dotnet#112206) Update dependencies from https://github.com/dotnet/arcade build 20250206.4 (dotnet#112338) System.Configuration.ConfigurationManager.Tests: use Assembly.Location to determine ThisApplicationPath. (dotnet#112231) Force write of local file header when "version needed to extract" changes (dotnet#112032) JIT: Don't reorder handler blocks (dotnet#112292) [RISC-V] Synthesize some floating constants inline (dotnet#111529) Enable `SA1000`: Spacing around keywords (dotnet#112302) Fix relocs for linux-riscv64 AOT (dotnet#112331)
With this delta, we successfully reach the hello-world milestone.
#106223