Skip to content

Commit

Permalink
optimize: Handle path-excluded Core.ifelse arguments
Browse files Browse the repository at this point in the history
It's possible for PiNodes to effectively imply statically the condition
of a Core.ifelse. For example:
```julia
    23 ─ %60  = Core.ifelse(%47, false, true)::Bool
    │    %61  = Core.ifelse(%47, %58, false)::Union{Missing, Bool}
    25 ─        goto JuliaLang#27 if not %60
    26 ─ %65  = π (%61, Bool)
    └───        ...
```

In basic block JuliaLang#26, the PiNode gives us enough information to conclude
that `%47 === false` if control flow reaches that point. The previous
code incorrectly assumed that this kind of pruning would only be done
for PhiNodes.

Resolves JuliaLang#50276.
  • Loading branch information
topolarity committed Jun 27, 2023
1 parent 0e147eb commit ed47b3e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,11 @@ function perform_lifting!(compact::IncrementalCompact,
else_result = lifted_value(compact, old_node_ssa, else_result,
lifted_philikes, lifted_leaves, reverse_mapping)

# In cases where the Core.ifelse condition is statically-known, e.g., thanks
# to a PiNode from a guarding conditional, we replace with the other branch.
then_result === SKIP_TOKEN && (then_result = else_result)
else_result === SKIP_TOKEN && (else_result = then_result)

@assert then_result !== SKIP_TOKEN && then_result !== UNDEF_TOKEN
@assert else_result !== SKIP_TOKEN && else_result !== UNDEF_TOKEN

Expand Down

0 comments on commit ed47b3e

Please sign in to comment.