Skip to content

[mono] box+callvirt optimization incorrect when instructions are in different basic blocks #95347

@iXyles

Description

@iXyles

The box+callvirt optimization from #73456 is firing incorrectly when the box and the callvirt are consecutive IL instructions but in different basic blocks and there is another basic block that jumps to the callvirt.

See #95347 (comment) and the next 3 comments for repro and diagnosis

Original issue description below:


Description

Runtime behaviour changes in net8.0.
In net8.0 when running the code under/linked repo in Release mode on Mono (Android, ios, wasm) vs Debug it behaves different.
It also behaves different to release mode of a windows console app.

In net7.0 - both of them worked the same, in both debug and release mode

(nullableObject ?? false).ToString()

Reproduction Steps

  1. Checkout code - https://github.com/iXyles/net8-regression-bug (or copy the code part from it)
  2. Run console app in Release mode Should print 'False': False
  3. Run Andrioid app in Release mode Should print same, but instead it prints 'False': true

Optional:
4. Uninstall app from device
5. Run app in Debug mode - now it shows 'False': False (as expected)

Expected behavior

Should work the same as in previous versions.
Debug & Release mode should behave the same with the given code.
Output should be the same in Android, iOS & Windows console app

Actual behavior

Returns different values in Debug vs Release mode & works different on different platforms and previous net versions
Output value on Android & iOS: true
Output value on Windows console app: FALSE

Regression?

This works with previous net7.0 version (latest)

Known Workarounds

nullableObject != null ? nullableObject.ToString() : false.ToString() (in this sample)
or
Downgrade back to net7.0

Configuration

Android - Unsure
iOS - ARM64

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions