Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssair: compact! constant PiNode #50768

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1362,8 +1362,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
Expand Down
2 changes: 1 addition & 1 deletion test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions test/compiler/irutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 11 additions & 1 deletion test/compiler/ssair.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down