Skip to content

Commit 0682b04

Browse files
authored
[RISC-V] Extend register for slti (#114900)
* Extend register for slti * add test
1 parent 4158fca commit 0682b04

File tree

6 files changed

+65
-16
lines changed

6 files changed

+65
-16
lines changed

src/coreclr/jit/codegenriscv64.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,22 +3208,23 @@ void CodeGen::genCodeForCompare(GenTreeOp* tree)
32083208
switch (cmpSize)
32093209
{
32103210
case EA_4BYTE:
3211+
{
3212+
regNumber tmpRegOp1 = internalRegisters.GetSingle(tree);
3213+
assert(regOp1 != tmpRegOp1);
32113214
if (isUnsigned)
32123215
{
32133216
imm = static_cast<uint32_t>(imm);
3214-
3215-
regNumber tmpRegOp1 = internalRegisters.GetSingle(tree);
3216-
assert(regOp1 != tmpRegOp1);
3217-
32183217
emit->emitIns_R_R_I(INS_slli, EA_8BYTE, tmpRegOp1, regOp1, 32);
32193218
emit->emitIns_R_R_I(INS_srli, EA_8BYTE, tmpRegOp1, tmpRegOp1, 32);
3220-
regOp1 = tmpRegOp1;
32213219
}
32223220
else
32233221
{
32243222
imm = static_cast<int32_t>(imm);
3223+
emit->emitIns_R_R(INS_sext_w, EA_8BYTE, tmpRegOp1, regOp1);
32253224
}
3225+
regOp1 = tmpRegOp1;
32263226
break;
3227+
}
32273228
case EA_8BYTE:
32283229
break;
32293230
default:

src/coreclr/jit/lsrariscv64.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,8 @@ int LinearScan::BuildNode(GenTree* tree)
445445
if (!varTypeIsFloating(op1Type))
446446
{
447447
emitAttr cmpSize = EA_ATTR(genTypeSize(op1Type));
448-
if (tree->gtGetOp2()->isContainedIntOrIImmed())
449-
{
450-
bool isUnsigned = (tree->gtFlags & GTF_UNSIGNED) != 0;
451-
if (cmpSize == EA_4BYTE && isUnsigned)
452-
buildInternalIntRegisterDefForNode(tree);
453-
}
454-
else
455-
{
456-
if (cmpSize == EA_4BYTE)
457-
buildInternalIntRegisterDefForNode(tree);
458-
}
448+
if (cmpSize == EA_4BYTE)
449+
buildInternalIntRegisterDefForNode(tree);
459450
}
460451
buildInternalRegisterUses();
461452
}

src/tests/JIT/Directed/Directed_2.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<MergedWrapperProjectReference Include="perffix/**/*.??proj" />
55
<MergedWrapperProjectReference Include="PREFIX/**/*.??proj" />
66
<MergedWrapperProjectReference Include="shift/**/*.??proj" />
7+
<MergedWrapperProjectReference Include="compare/**/*.??proj" />
78
</ItemGroup>
89

910
<Import Project="$(TestSourceDir)MergedTestRunner.targets" />

src/tests/JIT/Directed/Directed_3.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<MergedWrapperProjectReference Remove="perffix/**/*.??proj" />
1212
<MergedWrapperProjectReference Remove="PREFIX/**/*.??proj" />
1313
<MergedWrapperProjectReference Remove="shift/**/*.??proj" />
14+
<MergedWrapperProjectReference Remove="compare/**/*.??proj" />
1415
</ItemGroup>
1516

1617
<Import Project="$(TestSourceDir)MergedTestRunner.targets" />
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
//
4+
5+
using System.Runtime.CompilerServices;
6+
using Xunit;
7+
8+
public class CompareTest
9+
{
10+
[MethodImplAttribute(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
11+
public static bool Lt2((int, float) x) => (x.Item1 < 2);
12+
13+
[MethodImplAttribute(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
14+
public static bool Gt2((int, float) x) => (x.Item1 > 2);
15+
16+
[MethodImplAttribute(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
17+
public static bool Le2((int, float) x) => (x.Item1 <= 2);
18+
19+
[MethodImplAttribute(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
20+
public static bool Ge2((int, float) x) => (x.Item1 >= 2);
21+
22+
[MethodImplAttribute(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
23+
public static bool Eq0((int, float) x) => (x.Item1 == 0);
24+
25+
[MethodImplAttribute(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
26+
public static bool Ne0((int, float) x) => (x.Item1 != 0);
27+
28+
[Fact]
29+
public static void Test()
30+
{
31+
// The integer field of a struct passed in a register according to RISC-V floating-point calling convention is
32+
// not extended. Comparisons on RISC-V, however, always operate on full registers.
33+
// Note: reflection calls poison the undefined bits in runtime debug mode making it a better repro.
34+
var type = typeof(CompareTest);
35+
var args = new object[] {(2, 0f)};
36+
Assert.False((bool)type.GetMethod("Lt2").Invoke(null, args));
37+
Assert.False((bool)type.GetMethod("Gt2").Invoke(null, args));
38+
Assert.True((bool)type.GetMethod("Le2").Invoke(null, args));
39+
Assert.True((bool)type.GetMethod("Ge2").Invoke(null, args));
40+
args = new object[] {(0, 0f)};
41+
Assert.True((bool)type.GetMethod("Eq0").Invoke(null, args));
42+
Assert.False((bool)type.GetMethod("Ne0").Invoke(null, args));
43+
}
44+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<CLRTestPriority>1</CLRTestPriority>
4+
</PropertyGroup>
5+
<PropertyGroup>
6+
<Optimize>True</Optimize>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<Compile Include="int32.cs" />
10+
</ItemGroup>
11+
</Project>

0 commit comments

Comments
 (0)