From 0e147eb8be67898afb424a900df96229ad558997 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Tue, 27 Jun 2023 12:13:40 -0400 Subject: [PATCH] irinterp: Add handling for :throw_undef_if_not (#50303) This addresses an existing TODO to terminate irinterp on discovering a :throw_undef_if_not that is dead. The underlying infrastructure to do this was added in #49692, so this just needed to be wired up properly. --- base/compiler/ssair/irinterp.jl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/base/compiler/ssair/irinterp.jl b/base/compiler/ssair/irinterp.jl index 0a738371aca6e..bafa70ab22b03 100644 --- a/base/compiler/ssair/irinterp.jl +++ b/base/compiler/ssair/irinterp.jl @@ -130,8 +130,16 @@ function reprocess_instruction!(interp::AbstractInterpreter, idx::Int, bb::Union if nothrow ir.stmts[idx][:flag] |= IR_FLAG_NOTHROW end - elseif head === :throw_undef_if_not || # TODO: Terminate interpretation early if known false? - head === :gc_preserve_begin || + elseif head === :throw_undef_if_not + condval = maybe_extract_const_bool(argextype(inst.args[2], ir)) + condval isa Bool || return false + if condval + ir.stmts[idx][:inst] = nothing + # We simplified the IR, but we did not update the type + return false + end + rt = Union{} + elseif head === :gc_preserve_begin || head === :gc_preserve_end return false else