Optimize MIR CFG generation for chained logical operators (#83623)#157315
Optimize MIR CFG generation for chained logical operators (#83623)#157315sunny026 wants to merge 1 commit into
Conversation
|
Some changes occurred in coverage instrumentation. cc @Zalathar |
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
33084fa to
d5c3189
Compare
This comment has been minimized.
This comment has been minimized.
d5c3189 to
594756f
Compare
|
How does this fix the bug? From a glance it looks like it's making it worse. Do you have a test? |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
Fixes #83623
Description
This PR resolves the issue where chained logical operators (
&&and||) evaluated into a boolean destination generated suboptimal MIR. Previously, the AST lowering incompiler/rustc_mir_build/src/builder/expr/into.rsrecursively invokedexpr_into_dest, which allocated duplicatedestination = falsebasic blocks for every operator in the chain. This fractured control flow prevented LLVM'smem2regpass from recognizing the pattern and blocked auto-vectorization.Changes
ExprKind::LogicalOplowering insideinto.rsto route the entire expression throughthen_else_break.then_else_breakoptimally sharesif/then/elsescopes without creating temporary booleans, this natively collapses all short-circuiting branches into a single unified success block and a single unified failure block.Result
LLVM can now instantly convert the unified
gotofailures into SSA Phi nodes, enabling seamless SIMD vectorization for constructs like#[derive(PartialEq)]on large structs!