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
6 changes: 4 additions & 2 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5907,8 +5907,10 @@ void Compiler::optRemoveRedundantZeroInits()
defsInBlock.Set(lclNum, 1);
}
}
else if (varTypeIsStruct(lclDsc) && ((tree->gtFlags & GTF_VAR_USEASG) == 0) &&
lvaGetPromotionType(lclDsc) != PROMOTION_TYPE_NONE)
// Here we treat both "full" and "partial" tracked field defs as defs
// (that is, we ignore the state of GTF_VAR_USEASG).
Comment on lines +5910 to +5911
Copy link

Copilot AI May 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider clarifying this comment by removing the quotes around full/partial and explicitly stating that checks for GTF_VAR_USEASG are intentionally omitted to unify all tracked-field stores as definitions.

Suggested change
// Here we treat both "full" and "partial" tracked field defs as defs
// (that is, we ignore the state of GTF_VAR_USEASG).
// Here we treat both full and partial tracked field definitions as definitions.
// Checks for GTF_VAR_USEASG are intentionally omitted to unify all tracked-field stores as definitions.

Copilot uses AI. Check for mistakes.
//
else if (varTypeIsStruct(lclDsc) && lvaGetPromotionType(lclDsc) != PROMOTION_TYPE_NONE)
{
for (unsigned i = lclDsc->lvFieldLclStart; i < lclDsc->lvFieldLclStart + lclDsc->lvFieldCnt;
++i)
Expand Down
61 changes: 61 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_115123/Runtime_115123.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Simplified from an Antigen test case

using System;
using System.Runtime.CompilerServices;
using Xunit;

public struct S1_D1_F2
{
public bool bool_1;
public bool bool_2;
}

public class Runtime_115123
{
[Fact]
public static void Test()
{
Problem(1);
}

[MethodImpl(MethodImplOptions.NoInlining)]
static void Problem(int a)
{
unchecked
{
bool b = false;
S1_D1_F2 s1_s1_d1_f2_1983 = new S1_D1_F2();
try
{
if (s1_s1_d1_f2_1983.bool_1 = (b = (s1_s1_d1_f2_1983.bool_1 = false) || (a == 0)))
{
SideEffect();
}
}
finally
{
switch (a)
{
case 0: SideEffect(); break;
case 1: SideEffect(); break;
case 2: SideEffect(); break;
case 3: SideEffect(); break;
case 4: SideEffect(); break;
default: SideEffect(); break;
}
}

Log("s1_s1_d1_f", s1_s1_d1_f2_1983);
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
static void Log(string varName, object varValue) {}

[MethodImpl(MethodImplOptions.NoInlining)]
static void SideEffect() {}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
Loading