未验证 提交 a8c0d32d 编写于 作者: J Jakob Botsch Nielsen 提交者: GitHub

JIT: Fix EQ/NE(relop/SETCC, 0) optimization (#83144)

Fix #83140
上级 3db965d1
......@@ -3267,7 +3267,7 @@ GenTree* Lowering::OptimizeConstCompare(GenTree* cmp)
#endif // defined(TARGET_XARCH) || defined(TARGET_ARM64)
// Optimize EQ/NE(relop/SETCC, 0) into (maybe reversed) cond.
if (op2->IsIntegralConst(0) && (op1->OperIsCompare() || op1->OperIs(GT_SETCC)))
if (cmp->OperIs(GT_EQ, GT_NE) && op2->IsIntegralConst(0) && (op1->OperIsCompare() || op1->OperIs(GT_SETCC)))
{
LIR::Use use;
if (BlockRange().TryGetUse(cmp, &use))
......@@ -3278,6 +3278,10 @@ GenTree* Lowering::OptimizeConstCompare(GenTree* cmp)
assert(reversed == op1);
}
// Relops and SETCC can be either TYP_INT or TYP_LONG typed, so we
// may need to retype it.
op1->gtType = cmp->TypeGet();
GenTree* next = cmp->gtNext;
use.ReplaceWith(op1);
BlockRange().Remove(cmp->gtGetOp2());
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// Generated by Fuzzlyn v1.5 on 2023-03-07 17:55:15
// Run on X86 Windows
// Seed: 7526964204781879473
// Reduced from 425.4 KiB to 0.4 KiB in 00:12:20
// Debug: Prints 0 line(s)
// Release: Prints 1 line(s)
public struct S0
{
public ulong F1;
}
public class C0
{
public uint F0;
}
public class C1
{
public S0 F1;
}
public class Runtime_83140
{
public static C0 s_10 = new C0();
public static C1 s_64 = new C1();
public static int Main()
{
// We were optimizing GE(relop, 0) by reversing the relop, but the optimization is only valid for EQ/NE(relop, 0).
if (0 > (int)(s_10.F0 / 2699312582U))
{
var vr5 = s_64.F1.F1;
return -1;
}
return 100;
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
\ No newline at end of file
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// Generated by Fuzzlyn v1.5 on 2023-03-08 14:45:20
// Run on Arm64 MacOS
// Seed: 4799288502595168691
// Reduced from 173.8 KiB to 0.3 KiB in 00:00:42
// Hits JIT assert in Release:
// Assertion failed 'genTypeSize(op1Type) == genTypeSize(op2Type)' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Generate code' (IL size 76; hash 0xade6b36b; FullOpts)
//
// File: /Users/runner/work/1/s/src/coreclr/jit/codegenarm64.cpp Line: 4521
//
public class C0
{
public long F0;
public uint F1;
public sbyte F2;
}
public class Runtime_83140_2
{
public static C0 s_3 = new C0();
public static int Main()
{
// A case where produced incorrectly typed IR when optimizing NE(relop, 0) into relop
if ((s_3.F0 < s_3.F2) & ((s_3.F1 / 13548999118840769392UL) <= 0))
{
bool vr1 = 0 != s_3.F0++;
}
return 100;
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册