Skip to content

Commit 5b49d06

Browse files
committed
ssair: compact! constant PiNode
Currently the `compact!`-ion pass fails to fold constant `PiNode` like `PiNode(0.0, Float64)`. This commit fixes it up.
1 parent c62f4ea commit 5b49d06

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

base/compiler/ssair/ir.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,8 +1362,9 @@ function process_node!(compact::IncrementalCompact, result_idx::Int, inst::Instr
13621362
return result_idx
13631363
end
13641364
elseif !isa(pi_val, AnySSAValue) && !isa(pi_val, GlobalRef)
1365-
valtyp = isa(pi_val, QuoteNode) ? typeof(pi_val.value) : typeof(pi_val)
1366-
if valtyp === stmt.typ
1365+
pi_val′ = isa(pi_val, QuoteNode) ? pi_val.value : pi_val
1366+
stmttyp = stmt.typ
1367+
if isa(stmttyp, Const) ? pi_val′ === stmttyp.val : typeof(pi_val′) === stmttyp
13671368
ssa_rename[idx] = pi_val
13681369
return result_idx
13691370
end

test/compiler/inline.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ function f44200()
11301130
x44200
11311131
end
11321132
let src = code_typed1(f44200)
1133-
@test_broken count(x -> isa(x, Core.PiNode), src.code) == 0
1133+
@test count(x -> isa(x, Core.PiNode), src.code) == 0
11341134
end
11351135

11361136
# Test that peeling off one case from (::Any) doesn't introduce

test/compiler/irutils.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ isinvoke(y) = @nospecialize(x) -> isinvoke(y, x)
3737
isinvoke(sym::Symbol, @nospecialize(x)) = isinvoke(mi->mi.def.name===sym, x)
3838
isinvoke(pred::Function, @nospecialize(x)) = isexpr(x, :invoke) && pred(x.args[1]::MethodInstance)
3939

40-
function fully_eliminated(@nospecialize args...; retval=(@__FILE__), kwargs...)
41-
code = code_typed1(args...; kwargs...).code
40+
fully_eliminated(@nospecialize args...; retval=(@__FILE__), kwargs...) =
41+
fully_eliminated(code_typed1(args...; kwargs...); retval)
42+
fully_eliminated(src::CodeInfo; retval=(@__FILE__)) = fully_eliminated(src.code; retval)
43+
fully_eliminated(ir::IRCode; retval=(@__FILE__)) = fully_eliminated(ir.stmts.inst; retval)
44+
function fully_eliminated(code::Vector{Any}; retval=(@__FILE__), kwargs...)
4245
if retval !== (@__FILE__)
4346
length(code) == 1 || return false
4447
code1 = code[1]

test/compiler/ssair.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using Core.IR
55
const Compiler = Core.Compiler
66
using .Compiler: CFG, BasicBlock, NewSSAValue
77

8-
include(normpath(@__DIR__, "irutils.jl"))
8+
include("irutils.jl")
99

1010
make_bb(preds, succs) = BasicBlock(Compiler.StmtRange(0, 0), preds, succs)
1111

@@ -593,6 +593,16 @@ let ci = make_ci([
593593
@test Core.Compiler.verify_ir(ir) === nothing
594594
end
595595

596+
# compact constant PiNode
597+
let ci = make_ci(Any[
598+
PiNode(0.0, Const(0.0))
599+
ReturnNode(SSAValue(1))
600+
])
601+
ir = Core.Compiler.inflate_ir(ci)
602+
ir = Core.Compiler.compact!(ir)
603+
@test fully_eliminated(ir)
604+
end
605+
596606
# insert_node! with new instruction with flag computed
597607
let ir = Base.code_ircode((Int,Int); optimize_until="inlining") do a, b
598608
a^b

0 commit comments

Comments
 (0)