Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Incorrect optimization of x & -x on x86 #66709

Closed
jakobbotsch opened this issue Mar 16, 2022 · 11 comments · Fixed by #66736
Closed

JIT: Incorrect optimization of x & -x on x86 #66709

jakobbotsch opened this issue Mar 16, 2022 · 11 comments · Fixed by #66736
Assignees
Labels
arch-x86 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI bug
Milestone

Comments

@jakobbotsch
Copy link
Member

Description

The following program gives an invalid result when optimizing on x86.

Reproduction Steps

// Generated by Fuzzlyn v1.5 on 2022-03-16 11:07:55
// Run on X86 Windows
// Seed: 13083630089409025722
// Reduced from 309.3 KiB to 0.2 KiB in 00:06:28
// Debug: Outputs 1
// Release: Outputs 4294967297
public class Program
{
    public static long s_61 = -1;
    public static void Main()
    {
        s_61 &= -s_61;
        System.Console.WriteLine(s_61);
    }
}

Expected behavior

Same result with and without optimizations.

Actual behavior

Different result.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

Probably some interaction between long decomposition and the new optimization added in #66193? cc @Wraith2 @dotnet/jit-contrib

@dotnet-issue-labeler dotnet-issue-labeler bot added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI untriaged New issue has not been triaged by the area owner labels Mar 16, 2022
@ghost
Copy link

ghost commented Mar 16, 2022

Tagging subscribers to this area: @JulieLeeMSFT
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

The following program gives an invalid result when optimizing on x86.

Reproduction Steps

// Generated by Fuzzlyn v1.5 on 2022-03-16 11:07:55
// Run on X86 Windows
// Seed: 13083630089409025722
// Reduced from 309.3 KiB to 0.2 KiB in 00:06:28
// Debug: Outputs 1
// Release: Outputs 4294967297
public class Program
{
    public static long s_61 = -1;
    public static void Main()
    {
        s_61 &= -s_61;
        System.Console.WriteLine(s_61);
    }
}

Expected behavior

Same result with and without optimizations.

Actual behavior

Different result.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

Probably some interaction between long decomposition and the new optimization added in #66193? cc @Wraith2 @dotnet/jit-contrib

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr, untriaged

Milestone: -

@jakobbotsch jakobbotsch added this to the 7.0.0 milestone Mar 16, 2022
@deeprobin
Copy link
Contributor

https://godbolt.org/z/bfEx84ovj
Godbolt does not show me any blsi optimization at all.

@jakobbotsch
Copy link
Member Author

https://godbolt.org/z/bfEx84ovj Godbolt does not show me any blsi optimization at all.

It's a new optimization added in #66193. It's not part of .NET 6.

@deeprobin
Copy link
Contributor

deeprobin commented Mar 16, 2022

https://godbolt.org/z/bfEx84ovj Godbolt does not show me any blsi optimization at all.

It's a new optimization added in #66193. It's not part of .NET 6.

As far as I know Godbolt always uses the daily builds, even if it says .NET 6.

Referring to C# Community Discord discussion with @EgorBo
image

@EgorBo
Copy link
Member

EgorBo commented Mar 16, 2022

@deeprobin I think it actually doesn't use daily builds, it uses some fixed version of .NET 7.0 daily build, probably a few month old

@hez2010
Copy link
Contributor

hez2010 commented Mar 16, 2022

it uses some fixed version of .NET 7.0 daily build, probably a few month old

No. Godbolt is currently using tag v6.0.1 as runtime, so it's .NET 6.

You can confirm the version here: https://github.com/compiler-explorer/infra/blob/main/bin/yaml/dotnet.yaml#L11

@hez2010
Copy link
Contributor

hez2010 commented Mar 16, 2022

https://godbolt.org/z/bfEx84ovj Godbolt does not show me any blsi optimization at all.

Note that your compile options are invalid. Godbolt only supports below compiler options/switches for dotnet languages:

  • --targetos: operating system, available options are windows, linux and osx. Default value is based on current platform, on complier explorer it's linux.
  • --targetarch: architecture, available options are arm, armel, arm64, x86 and x64. Default value is x64.
  • --instruction-set: instruction set for compilation. Default value is sse2.
    • The allowable values for the --instruction-set option are described in the table below. Each architecture has a different set of valid instruction sets, and multiple instruction sets may be specified by separating the instructions sets by a ,. For example avx2,bmi,lzcnt
    • Available instruction sets for each architecture:
      • arm: N/A
      • armel: N/A
      • arm64: base, neon, aes, crc, dotprod, rdma, sha1, sha2, lse
      • x86: base, sse, sse2, sse3, ssse3, sse4.1, sse4.2, avx, avx2, aes, bmi, bmi2, fma, lzcnt, pclmul, popcnt, avxvnni
      • x64: base, sse, sse2, sse3, ssse3, sse4.1, sse4.2, avx, avx2, aes, bmi, bmi2, fma, lzcnt, pclmul, popcnt, avxvnni
  • --singlemethodtypename: Type name for single method compilation
  • --singlemethodname: Name for single method compilation
  • --singlemethodindex: Index for single method compilation
  • --singlemethodgenericarg: Generic arguments for single method compilation
  • --codegenopt, --codegen-options: Code generation options passed to JIT
  • -O, --optimize: Enable optimizations (default)
  • --Od, --optimize-disabled: Disable optimizations
  • --Os, --optimize-size: Optimize code for size
  • --Ot, --optimize-time: Optimize code for speed

@Wraith2
Copy link
Contributor

Wraith2 commented Mar 16, 2022

I'll take a look.

@jakobbotsch jakobbotsch removed the untriaged New issue has not been triaged by the area owner label Mar 16, 2022
@Wraith2
Copy link
Contributor

Wraith2 commented Mar 16, 2022

By x86 do you mean then 32 bit build specifically? Because I can't get that to build locally. Or are we just talking x86 as in not arm.

@jakobbotsch
Copy link
Member Author

By x86 do you mean then 32 bit build specifically? Because I can't get that to build locally. Or are we just talking x86 as in not arm.

I mean the 32-bit build specifically.

@jakobbotsch
Copy link
Member Author

I can't get that to build locally.

What errors are you getting? The standard build commands (passing -arch x86) work fine for me (including build.cmd -vs coreclr.sln -arch x86).

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Mar 16, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Mar 20, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Apr 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-x86 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants