Skip to content

JIT: Refactor optOptimizeBoolsCondBlock to be table-driven#128964

Open
EgorBo wants to merge 6 commits into
dotnet:mainfrom
EgorBo:cleanup-opt-bools
Open

JIT: Refactor optOptimizeBoolsCondBlock to be table-driven#128964
EgorBo wants to merge 6 commits into
dotnet:mainfrom
EgorBo:cleanup-opt-bools

Conversation

@EgorBo
Copy link
Copy Markdown
Member

@EgorBo EgorBo commented Jun 3, 2026

Refactors OptBoolsDsc::optOptimizeBoolsCondBlock from a long if/else cascade into a small table-driven matcher, plus a few drive-by cleanups in the same file.

Copilot AI review requested due to automatic review settings June 3, 2026 22:34
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 3, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the CoreCLR JIT boolean-conditional folding logic in OptBoolsDsc::optOptimizeBoolsCondBlock by replacing a nested if/else cascade with a small rule table and lookup, along with several small cleanups in the same compilation unit.

Changes:

  • Introduces a table-driven matcher (OptBoolsRule + s_optBoolsRules) to select (foldOp, cmpOp) based on adjacent BBJ_COND block patterns, including a normalization step to reuse the same table for both m_sameTarget cases.
  • Replaces ad-hoc debug printing with existing JITDUMP / DISPSTMT macros in the modified optimization path(s).
  • Performs small cleanups in optimizebools.cpp (e.g., log prefix fix, local cleanup, minor boolean/const handling tweaks).

Comment thread src/coreclr/jit/optimizebools.cpp
Copilot AI review requested due to automatic review settings June 4, 2026 00:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/coreclr/jit/optimizebools.cpp:1342

  • This blank line contains trailing whitespace. Please remove the spaces to avoid whitespace-only diffs and potential style checks.

Comment thread src/coreclr/jit/optimizebools.cpp Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/jit/optimizebools.cpp
Each row now reads literally as (sameTarget, sameLcl, op1, op2) -> (foldOp, cmpOp, requiresSigned) with no implicit normalization at the lookup site.
// Independent operands: fold to a single bitwise compare.
{ false, false, GT_EQ, GT_NE, GT_AND, GT_NE, false }, // !(c1==0) && c2!=0 -> (c1&c2)!=0
{ false, false, GT_LT, GT_GE, GT_OR, GT_GE, true }, // !(c1<0) && c2>=0 -> (c1|c2)>=0
{ false, false, GT_NE, GT_EQ, GT_OR, GT_EQ, false }, // !(c1!=0) && c2==0 -> (c1|c2)==0
Copy link
Copy Markdown
Member

@am11 am11 Jun 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggestions by the AI:

    // Same local: fold to a single signed compare.
    { true,     true,     GT_LT, GT_GT, GT_NONE,  GT_NE, true  }, // c1<0  || c1>0  -> c1!=0
    { true,     true,     GT_GT, GT_LT, GT_NONE,  GT_NE, true  }, // c1>0  || c1<0  -> c1!=0
    { true,     true,     GT_LT, GT_NE, GT_NONE,  GT_NE, true  }, // c1<0  || c1!=0 -> c1!=0
    { true,     true,     GT_NE, GT_LT, GT_NONE,  GT_NE, true  }, // c1!=0 || c1<0  -> c1!=0
    { true,     true,     GT_GT, GT_NE, GT_NONE,  GT_NE, true  }, // c1>0  || c1!=0 -> c1!=0
    { true,     true,     GT_NE, GT_GT, GT_NONE,  GT_NE, true  }, // c1!=0 || c1>0  -> c1!=0

    // Same local: fold to a single signed compare (AND form via negation).
    { false,    true,     GT_GE, GT_LE, GT_NONE,  GT_LT, true  }, // !(c1>=0) && c1<=0 -> c1<0
    { false,    true,     GT_LE, GT_GE, GT_NONE,  GT_GT, true  }, // !(c1<=0) && c1>=0 -> c1>0
    { false,    true,     GT_LT, GT_LE, GT_NONE,  GT_EQ, true  }, // !(c1<0)  && c1<=0 -> c1==0
    { false,    true,     GT_GT, GT_GE, GT_NONE,  GT_EQ, true  }, // !(c1>0)  && c1>=0 -> c1==0
    { false,    true,     GT_EQ, GT_NE, GT_NONE,  GT_NE, true  }, // !(c1==0) && c1!=0 -> c1!=0
    { false,    true,     GT_NE, GT_EQ, GT_NONE,  GT_EQ, true  }, // !(c1!=0) && c1==0 -> c1==0

    // Independent operands: fold to a single bitwise compare.
    { false,    false,    GT_GE, GT_LT, GT_OR,    GT_LT, true  }, // !(c1>=0) && c2<0  -> (c1|c2)<0
    { false,    false,    GT_LE, GT_GT, GT_OR,    GT_GT, true  }, // !(c1<=0) && c2>0  -> (c1|c2)>0
    { false,    false,    GT_GT, GT_LE, GT_OR,    GT_LE, true  }, // !(c1>0)  && c2<=0 -> (c1|c2)<=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants