julia icon indicating copy to clipboard operation
julia copied to clipboard

`CC.populate_def_use_map!` doesn't work as expected.

Open jumerckx opened this issue 4 months ago • 1 comments

MWE:

using Test

const CC = Core.Compiler

ir, ret = only(Base.code_ircode((Int, ); optimize_until="compact 1") do x
    y = 2*x
    return y
end)

tpdum = CC.TwoPhaseDefUseMap(length(ir.stmts));

CC.populate_def_use_map!(tpdum, ir)

@test !isempty(tpdum.data) # fails, tpdum is empty

The problem is the following, as described by @willtebbutt on Slack:

I'm a bit confused by the use of userefs in populate_def_use_map! , see here: https://github.com/JuliaLang/julia/blob/b19a7c1721f623ae085354889b183622537543b0/base/compiler/ssair/irinterp.jl#L290 In particular:

  1. the argument to userefs is an Instruction, meaning that the relevant flag of the returned UseRefIterator will always be set to false.
  2. The relevant flag being false means that no iterations of the linked for loop will ever be performed.
  3. Therefore, calling populate_def_use_map does not appear to ever modify tpdum.

jumerckx avatar Oct 16 '24 13:10 jumerckx