Skip to content

JIT: Combine before OR in OptimizeBools #125585

@BoyBaykiller

Description

@BoyBaykiller

A case from https://devblogs.microsoft.com/cppblog/c-performance-improvements-in-msvc-build-tools-v14-51/#ternary-operator-optimization.

https://godbolt.org/z/bvc7Gaq9G

void TernaryOperator(uint x, uint y)
{
    // Expected:
    // if ((x | y) < 0x10000u)
    //    or      edi, esi
    //    cmp     edi, 65536
    //    jae     void bar(void)

    uint a = x < 0x10000u ? 0u : 1u;
    uint b = y < 0x10000u ? 0u : 1u;

    if ((a | b) != 0) {
        Consume(0);
    }
}

Currently is after OptimizeBools:

[000015] -----+-----                         *  JTRUE     void   $VN.Void
[000014] J----+-N---                         \--*  EQ        int    $103
[000012] -----+-----                            +--*  OR        int    $102
[000002] N----+---U-                            |  +--*  GE        int    $100
[000000] -----+-----                            |  |  +--*  LCL_VAR   int    V01 arg1         u:1 (last use) $80
[000001] -----+-----                            |  |  \--*  CNS_INT   int    0x10000 $43
[000007] N----+---U-                            |  \--*  GE        int    $101
[000005] -----+-----                            |     +--*  LCL_VAR   int    V02 arg2         u:1 (last use) $81
[000006] -----+-----                            |     \--*  CNS_INT   int    0x10000 $43
[000013] -----+-----                            \--*  CNS_INT   int    0 $44

Could be:

[000005] -----+-----                         *  JTRUE     void   $VN.Void
[000004] N----+-N-U-                         \--*  GE        int    $101
[000002] -----+-----                            +--*  OR        int    $100
[000000] -----+-----                            |  +--*  LCL_VAR   int    V01 arg1         u:1 (last use) $80
[000001] -----+-----                            |  \--*  LCL_VAR   int    V02 arg2         u:1 (last use) $81
[000003] -----+-----                            \--*  CNS_INT   int    0x10000 $44

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions