From 5468a3e1131c89d7150b8db296808910219813dc Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Fri, 5 Jul 2024 16:20:47 +0200 Subject: [PATCH] Fix a regression in the test for #13432 (#55004) The test for #13432 is supposed to test a particular codegen path involving Bottom. It turns out that this code path is regressed on master, but hidden by the fact that in modern julia, the optimizer can fold this code path early. Fix the bug and add a variant of the test that shows the issue on julia master. Note that this is both an assertion failure and incorrect codegen. This PR addresses both. --- src/cgutils.cpp | 9 +++++++-- test/core.jl | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 2813c6bcce5d9..1d285cfaef937 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -1598,7 +1598,7 @@ static bool can_optimize_isa_union(jl_uniontype_t *type) // a simple case of emit_isa that is obvious not to include a safe-point static Value *emit_exactly_isa(jl_codectx_t &ctx, const jl_cgval_t &arg, jl_datatype_t *dt, bool could_be_null=false) { - assert(jl_is_concrete_type((jl_value_t*)dt)); + assert(jl_is_concrete_type((jl_value_t*)dt) || is_uniquerep_Type((jl_value_t*)dt)); if (arg.TIndex) { unsigned tindex = get_box_tindex(dt, arg.typ); if (tindex > 0) { @@ -1621,7 +1621,12 @@ static Value *emit_exactly_isa(jl_codectx_t &ctx, const jl_cgval_t &arg, jl_data BasicBlock *postBB = BasicBlock::Create(ctx.builder.getContext(), "post_isa", ctx.f); ctx.builder.CreateCondBr(isboxed, isaBB, postBB); ctx.builder.SetInsertPoint(isaBB); - Value *istype_boxed = ctx.builder.CreateICmpEQ(emit_typeof(ctx, arg.Vboxed, false, true), emit_tagfrom(ctx, dt)); + Value *istype_boxed = NULL; + if (is_uniquerep_Type((jl_value_t*)dt)) { + istype_boxed = ctx.builder.CreateICmpEQ(decay_derived(ctx, arg.Vboxed), decay_derived(ctx, literal_pointer_val(ctx, jl_tparam0(dt)))); + } else { + istype_boxed = ctx.builder.CreateICmpEQ(emit_typeof(ctx, arg.Vboxed, false, true), emit_tagfrom(ctx, dt)); + } ctx.builder.CreateBr(postBB); isaBB = ctx.builder.GetInsertBlock(); // could have changed ctx.builder.SetInsertPoint(postBB); diff --git a/test/core.jl b/test/core.jl index 964fce94d41d2..8b0328659ae39 100644 --- a/test/core.jl +++ b/test/core.jl @@ -3999,6 +3999,14 @@ end end @test f13432b(true) == true @test f13432b(false) == false +@noinline function f13432c(x) + offset = x ? Base.Bottom : 1 + # Barrier for inference, so the optimizer cannot optimize this, + # but codegen can still see this is a constant + return ===(offset, Base.inferencebarrier(Base.Bottom)) +end +@test f13432c(true) == true +@test f13432c(false) == false #13433, read!(::IO, a::Vector{UInt8}) should return a mutable struct IO13433 <: IO end