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

PHI nodes not grouped at top of basic block! when testing some packages #50448

Closed
KristofferC opened this issue Jul 7, 2023 · 3 comments · Fixed by #50639
Closed

PHI nodes not grouped at top of basic block! when testing some packages #50448

KristofferC opened this issue Jul 7, 2023 · 3 comments · Fixed by #50639
Assignees
Labels
regression Regression in behavior compared to a previous version upstream The issue is with an upstream dependency, e.g. LLVM
Milestone

Comments

@KristofferC
Copy link
Member

When running the tests for

"DistributionsAD"
"AdvancedHMC"
"Pathfinder"

with assertions enabled they error with

PHI nodes not grouped at top of basic block!
  %64 = phi <2 x double> [ %36, %idxend15.us ], [ %106, %idxend44.us.postloop ], [ %54, %idxend44.us ]
label %L97.us
julia: /source/src/llvm-lower-handlers.cpp:243: llvm::PreservedAnalyses LowerExcHandlersPass::run(llvm::Function&, llvm::FunctionAnalysisManager&): Assertion `!verifyFunction(F, &errs())' failed.

Example PkgEval log: https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_hash/c9a32f4_vs_e4ee485/DistributionsAD.primary.log

@KristofferC KristofferC added regression Regression in behavior compared to a previous version compiler:codegen Generation of LLVM IR and native code labels Jul 7, 2023
@KristofferC KristofferC added this to the 1.10 milestone Jul 7, 2023
@maleadt
Copy link
Member

maleadt commented Jul 14, 2023

Bisected to #49798 (cc @pchintalapudi). I'm looking into reducing to an MWE, but there's quite some code involved with these packages.

@maleadt
Copy link
Member

maleadt commented Jul 14, 2023

Reduced to:

using LinearAlgebra
Base.:*(x, partials)  = scale_tuple(partials, x)
tupexpr(f, N) = Expr(:tuple, [f(i) for i=1:N]...)
@generated function scale_tuple(tup::NTuple{N}, x) where N
    tupexpr(i -> :(tup[$i] * x), N)
end
struct Dual{V,N}
    value::V
    partials::NTuple{N,V}
end
Dual(value, partials::NTuple{N,V}) where {N,V} = Dual{V,N}(value, partials)
Base.:*(x, y::Dual) = Dual(x * y.value, x * y.partials)
Base.:\(x, y::Dual) = Dual(x \ y.value, one(y.value) / x * y.partials)
Base.:-(:, y) = y
struct PDMat{T} <: AbstractMatrix{T} end
Base.size(PDMat) = (adim, adim)
function logdensity_and_gradient(ℓ, x)
    duals = Dual{Float64,10}[]
    cholesky(ℓ).factors' \ duals
end
phasepoint(h, θ::T) where T<:AbstractVector = h(θ)
find_good_stepsize(h, θ) = phasepoint(h, θ)

sig = Tuple{typeof(find_good_stepsize), Base.Fix1{typeof(logdensity_and_gradient), PDMat{Float64}}, Array{Float64}}
CC = Core.Compiler
world = Base.get_world_counter()
match, = CC._findsup(sig, nothing, world)
mi = CC.specialize_method(match)
ccall(:jl_compile_method_internal, Any, (Any, UInt), mi, world)

Run with LLVM assertions enabled, and --check-bounds=yes:

PHI nodes not grouped at top of basic block!
  %28 = phi <4 x double> [ %114, %guard_pass90 ], [ %72, %main.exit.selector ], [ %107, %guard_pass85.loopexit ]
label %L86
julia: /source/src/llvm-lower-handlers.cpp:243: llvm::PreservedAnalyses LowerExcHandlersPass::run(llvm::Function&, llvm::FunctionAnalysisManager&): Assertion `!verifyFunction(F, &errs())' failed.

@pchintalapudi
Copy link
Member

This is not actually our fault, this is llvm/llvm-project#60649, fixed by llvm/llvm-project@af39acd, which we should backport. cc @vchuravy

@pchintalapudi pchintalapudi added upstream The issue is with an upstream dependency, e.g. LLVM and removed compiler:codegen Generation of LLVM IR and native code labels Jul 14, 2023
@maleadt maleadt self-assigned this Jul 20, 2023
@maleadt maleadt linked a pull request Jul 22, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression Regression in behavior compared to a previous version upstream The issue is with an upstream dependency, e.g. LLVM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants