diff --git a/base/compiler/ssair/ir.jl b/base/compiler/ssair/ir.jl index d133b88721238..be8d5c3e9e932 100644 --- a/base/compiler/ssair/ir.jl +++ b/base/compiler/ssair/ir.jl @@ -1359,8 +1359,9 @@ function process_node!(compact::IncrementalCompact, result_idx::Int, inst::Instr return result_idx end elseif !isa(pi_val, AnySSAValue) && !isa(pi_val, GlobalRef) - valtyp = isa(pi_val, QuoteNode) ? typeof(pi_val.value) : typeof(pi_val) - if valtyp === stmt.typ + pi_val′ = isa(pi_val, QuoteNode) ? pi_val.value : pi_val + stmttyp = stmt.typ + if isa(stmttyp, Const) ? pi_val′ === stmttyp.val : typeof(pi_val′) === stmttyp ssa_rename[idx] = pi_val return result_idx end diff --git a/test/compiler/inline.jl b/test/compiler/inline.jl index 3bc7ab5ccbc82..638f7e0185568 100644 --- a/test/compiler/inline.jl +++ b/test/compiler/inline.jl @@ -1130,7 +1130,7 @@ function f44200() x44200 end let src = code_typed1(f44200) - @test_broken count(x -> isa(x, Core.PiNode), src.code) == 0 + @test count(x -> isa(x, Core.PiNode), src.code) == 0 end # Test that peeling off one case from (::Any) doesn't introduce diff --git a/test/compiler/irutils.jl b/test/compiler/irutils.jl index 00de9b2472de4..c2f6fd3314c1b 100644 --- a/test/compiler/irutils.jl +++ b/test/compiler/irutils.jl @@ -37,8 +37,11 @@ isinvoke(y) = @nospecialize(x) -> isinvoke(y, x) isinvoke(sym::Symbol, @nospecialize(x)) = isinvoke(mi->mi.def.name===sym, x) isinvoke(pred::Function, @nospecialize(x)) = isexpr(x, :invoke) && pred(x.args[1]::MethodInstance) -function fully_eliminated(@nospecialize args...; retval=(@__FILE__), kwargs...) - code = code_typed1(args...; kwargs...).code +fully_eliminated(@nospecialize args...; retval=(@__FILE__), kwargs...) = + fully_eliminated(code_typed1(args...; kwargs...); retval) +fully_eliminated(src::CodeInfo; retval=(@__FILE__)) = fully_eliminated(src.code; retval) +fully_eliminated(ir::IRCode; retval=(@__FILE__)) = fully_eliminated(ir.stmts.inst; retval) +function fully_eliminated(code::Vector{Any}; retval=(@__FILE__), kwargs...) if retval !== (@__FILE__) length(code) == 1 || return false code1 = code[1] diff --git a/test/compiler/ssair.jl b/test/compiler/ssair.jl index 98cab349b46ee..ea833fa4ce5ff 100644 --- a/test/compiler/ssair.jl +++ b/test/compiler/ssair.jl @@ -5,7 +5,7 @@ using Core.IR const Compiler = Core.Compiler using .Compiler: CFG, BasicBlock, NewSSAValue -include(normpath(@__DIR__, "irutils.jl")) +include("irutils.jl") make_bb(preds, succs) = BasicBlock(Compiler.StmtRange(0, 0), preds, succs) @@ -593,6 +593,16 @@ let ci = make_ci([ @test Core.Compiler.verify_ir(ir) === nothing end +# compact constant PiNode +let ci = make_ci(Any[ + PiNode(0.0, Const(0.0)) + ReturnNode(SSAValue(1)) + ]) + ir = Core.Compiler.inflate_ir(ci) + ir = Core.Compiler.compact!(ir) + @test fully_eliminated(ir) +end + # insert_node! with new instruction with flag computed let ir = Base.code_ircode((Int,Int); optimize_until="inlining") do a, b a^b