Closed shibaev closed 2 months ago
Repros with 9.0.100-preview.6.24313.50 as well (osx-arm64).
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in area-owners.md if you want to be subscribed.
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch See info in area-owners.md if you want to be subscribed.
This repros with DOTNET_TieredCompilation=0
with a JIT as well.
Looks to be optRemoveRedundantZeroInits
issue
Looks to be
optRemoveRedundantZeroInits
issue
More specifically, BB02
is not marked with BBF_BACKWARD_JUMP
that optRemoveRedundantZeroInits
is relying on to check whether some zero inits are necessary. Tail merging managed to get rid of the a = null
inside the loop by rewriting the loop as follows:
string s = "12151";
int i = 0;
char? a;
while (true)
{
a = null;
AfterNulling:;
string? res = get(s, ref i, ref a);
if (res != null)
{
Console.Write(res);
continue;
}
if (i >= s.Length)
break;
a = '.';
goto AfterNulling;
}
The a = null
at the beginning of the loop is in a block that tail merging created but did not mark with BBF_BACKWARD_JUMP
, and then optRemoveRedundantZeroInits
removes it.
I wonder if we can just reuse some of our flow graph analysis to make this determination during optRemoveRedundantZeroInits
. We have both the DFS tree and loops available at this point, though we still need to consider whether the block is part of any irreducible cycles. It seems very fragile to try to rely on something like BBF_BACKWARD_JUMP
this late.
cc @AndyAyersMS
@jakobbotsch Yes, I also diagnosed lack of BBF_BACKWARD_JUMP
yesterday due to tail merge - I didn't put up a fix because I was not sure how to fix it in place in fgTailMerge (around fgRedirectTargetEdge
call) since I couldn't just rely on, potentially, stale bbNum data. I was wondering if fgRenumberBlocks
should just set this flag
and looks like we can give up on BBF_BACKWARD_JUMP_SOURCE
and BBF_BACKWARD_JUMP_TARGET
since they're only used in importer. Overall I am surprised we've never hit this issue before - we do quite a few BB manipulations but we never set BBF_BACKWARD_JUMP
anywhere after importer, we only set it in various block splits.
Yes this is too fragile. We should audit the other uses of BBF_BACKWARD_JUMP
and make sure there aren't more that might cause problems.
Seems like we could just stop walking blocks when we hit a block that has a DFS backedge? It might miss a few cases we get now, but seems easier to understand.
Have a fix for this implemented for main, should have a PR up soon. It will need to be expressed differently in 8.0.
Description
A NativeAOT version of our project fails at runtime while the related managed version works. There are not publishing warnings and static analysis warnings.
The root cause is that the publishing removes some required code. The code is simple without reflection or any similar dynamic techniques.
Reproduction Steps
Program.cs
AotIssue.csproj
To publish the project, you can use the
dotnet publish -r win-x64 -c Release
command. Or similar publish profile:Expected behavior
The AOT version prints "1.1.1" like regular .NET version.
Actual behavior
The AOT version prints an infinite sequence of "1111111111111...". The loop never ends.
Regression?
No response
Known Workarounds
Uncomment the line
Console.Write(a);
. In this case, the code works as expected after publishing.Configuration
I reproduced the issue in the .NET 8 project with win-x64 target platform on Windows 10.
Other information
The line
a = null;
is removed from the published version.