Skip to content

Commit eacb2f3

Browse files
authored
Fix 'x < 0' for unsigned (#83656)
1 parent aacebbd commit eacb2f3

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/coreclr/jit/codegenarm64.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4536,7 +4536,8 @@ void CodeGen::genCodeForCompare(GenTreeOp* tree)
45364536
regNumber op1Reg = op1->GetRegNum();
45374537

45384538
if (compiler->opts.OptimizationEnabled() && (ins == INS_cmp) && (targetReg != REG_NA) &&
4539-
tree->OperIs(GT_LT) && intConst->IsIntegralConst(0) && ((cmpSize == EA_4BYTE) || (cmpSize == EA_8BYTE)))
4539+
tree->OperIs(GT_LT) && !tree->IsUnsigned() && intConst->IsIntegralConst(0) &&
4540+
((cmpSize == EA_4BYTE) || (cmpSize == EA_8BYTE)))
45404541
{
45414542
emit->emitIns_R_R_I(INS_lsr, cmpSize, targetReg, op1Reg, (int)cmpSize * 8 - 1);
45424543
genProduceReg(tree);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
// Generated by Fuzzlyn v1.5 on 2023-03-19 17:44:38
5+
// Run on Arm64 Linux
6+
// Seed: 516098027771570682
7+
public class C0
8+
{
9+
public uint F1;
10+
public C0(uint f1)
11+
{
12+
F1 = f1;
13+
}
14+
}
15+
16+
public class Program
17+
{
18+
// This test was testing an ARM64 regression when optimizing 'x < 0' when it didn't take into account an unsigned operation.
19+
public static int Main()
20+
{
21+
var vr1 = new C0(4294967295U);
22+
bool vr3 = !(vr1.F1 > -1);
23+
if (!vr3)
24+
return 100;
25+
else
26+
return 0;
27+
}
28+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
</PropertyGroup>
5+
<PropertyGroup>
6+
<DebugType>None</DebugType>
7+
<Optimize>True</Optimize>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Include="$(MSBuildProjectName).cs" />
11+
</ItemGroup>
12+
</Project>

0 commit comments

Comments
 (0)