Skip to content

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

Closed

Description

@jakobbotsch

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

Activity

  1. ghost added
    area-CodeGen-coreclr
    on Mar 16, 2022
  2. ghost added
    untriaged
    on Mar 16, 2022
  3. added this to the 7.0.0 milestone on Mar 16, 2022
  4. deeprobin commented on Mar 16, 2022

    @deeprobin
    Contributor
  5. jakobbotsch commented on Mar 16, 2022

    @jakobbotsch
    MemberAuthor

    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.

  6. deeprobin commented on Mar 16, 2022

    @deeprobin
    Contributor

    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

  7. EgorBo commented on Mar 16, 2022

    @EgorBo
    Member

    @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

  8. hez2010 commented on Mar 16, 2022

    @hez2010
    Contributor

    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

  9. hez2010 commented on Mar 16, 2022

    @hez2010
    Contributor

    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
  10. Wraith2 commented on Mar 16, 2022

    @Wraith2
    Contributor

    I'll take a look.

  11. removed
    untriaged
    on Mar 16, 2022
  12. Wraith2 commented on Mar 16, 2022

    @Wraith2
    Contributor

    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.

  13. jakobbotsch commented on Mar 16, 2022

    @jakobbotsch
    MemberAuthor

    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.

  14. jakobbotsch commented on Mar 16, 2022

    @jakobbotsch
    MemberAuthor

    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).

  15. ghost added
    in-pr
    on Mar 16, 2022
  16. ghost removed
    in-pr
    on Mar 20, 2022
  17. ghost locked as resolved and limited conversation to collaborators on Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arch-x86area-CodeGen-coreclrbug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions