Skip to content

Commit a9edea1

Browse files
KenoIan Atol
authored andcommitted
Allow branch folding to look at type information
Folds things like: ``` %a = complicated()::Const(true) goto if not %a ```
1 parent b57d2e1 commit a9edea1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

base/compiler/ssair/ir.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,13 @@ function process_node!(compact::IncrementalCompact, result_idx::Int, inst::Instr
10071007
stmt = renumber_ssa2!(stmt, ssa_rename, used_ssas, late_fixup, result_idx, do_rename_ssa)::GotoIfNot
10081008
result[result_idx][:inst] = stmt
10091009
cond = stmt.cond
1010-
if isa(cond, Bool) && compact.fold_constant_branches
1010+
if compact.fold_constant_branches
1011+
if !isa(cond, Bool)
1012+
condT = widenconditional(argextype(cond, compact))
1013+
isa(condT, Const) || @goto bail
1014+
cond = condT.val
1015+
isa(cond, Bool) || @goto bail
1016+
end
10111017
if cond
10121018
result[result_idx][:inst] = nothing
10131019
kill_edge!(compact, active_bb, active_bb, stmt.dest)
@@ -1018,6 +1024,7 @@ function process_node!(compact::IncrementalCompact, result_idx::Int, inst::Instr
10181024
result_idx += 1
10191025
end
10201026
else
1027+
@label bail
10211028
result[result_idx][:inst] = GotoIfNot(cond, compact.bb_rename_succ[stmt.dest])
10221029
result_idx += 1
10231030
end

0 commit comments

Comments
 (0)