Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5955,29 +5955,28 @@ void CodeGen::genCompareInt(GenTree* treeNode)
}
else if (op1->isUsedFromReg() && op2->IsIntegralConst(0))
{
emitAttr targetSize = emitActualTypeSize(op1->TypeGet());
emitAttr op1Size = emitActualTypeSize(op1->TypeGet());

// Optimize "x<0" and "x>=0" to "x>>31" if "x" is not a jump condition and in a reg.
// Morph/Lowering are responsible to rotate "0<x" to "x>0" so we won't handle it here.
if ((targetSize >= 4) && (op1Size >= 4) && (targetReg != REG_NA) && tree->OperIs(GT_LT, GT_GE))
if (compiler->opts.OptimizationEnabled())
{
if (targetReg != op1->GetRegNum())
{
inst_RV_RV(INS_mov, targetReg, op1->GetRegNum(), op1->TypeGet());
}
if (tree->OperIs(GT_GE))
emitAttr op1Size = emitActualTypeSize(op1->TypeGet());
assert((int)op1Size >= 4);

// Optimize "x<0" and "x>=0" to "x>>31" if "x" is not a jump condition and in a reg.
// Morph/Lowering are responsible to rotate "0<x" to "x>0" so we won't handle it here.
if ((targetReg != REG_NA) && tree->OperIs(GT_LT, GT_GE) && !tree->IsUnsigned())
{
// emit "not" for "x>=0" case
inst_RV(INS_not, targetReg, tree->TypeGet(), op1Size);
if (targetReg != op1->GetRegNum())
{
inst_RV_RV(INS_mov, targetReg, op1->GetRegNum(), op1->TypeGet());
}
if (tree->OperIs(GT_GE))
{
// emit "not" for "x>=0" case
inst_RV(INS_not, targetReg, op1->TypeGet());
}
inst_RV_IV(INS_shr_N, targetReg, (int)op1Size * 8 - 1, op1Size);
genProduceReg(tree);
return;
}
inst_RV_IV(INS_shr_N, targetReg, (int)op1Size * 8 - 1, op1Size);
genProduceReg(tree);
return;
}

if (compiler->opts.OptimizationEnabled())
{
canReuseFlags = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ public void RuntimeExpression(object x, object y, ExpressionType type, object re
[MemberData(nameof(UInt64TestNotEquals))]
[MemberData(nameof(UInt64TestSubtractions))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/26798", TargetFrameworkMonikers.NetFramework)]
[SkipOnCoreClr("https://github.com/dotnet/runtime/issues/42719", RuntimeConfiguration.Checked)]
public void ConstantExpressions(object x, object y, ExpressionType type, object result, bool shouldSucceedChecked)
{
var callsite = GetBinaryOperationCallSite(type, false, true, true);
Expand Down
18 changes: 18 additions & 0 deletions src/tests/JIT/opt/JitMinOpts/Regression/GitHub_42719.il
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

.assembly extern mscorlib { }
.assembly GitHub_42719 {}
.module GitHub_42719.exe
.method public static int32 Main() cil managed
{
.entrypoint
.maxstack 5
// "0 u> -1" shouldn't be optimized into "-1 >> 31"
ldc.i4.s 100
ldc.i4.0
ldc.i4.m1
cgt.un
add
ret
}
9 changes: 9 additions & 0 deletions src/tests/JIT/opt/JitMinOpts/Regression/GitHub_42719.ilproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.IL">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>False</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="GitHub_42719.il" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.IL">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="GitHub_42719.il" />
</ItemGroup>
</Project>