diff --git a/base/compiler/ssair/inlining.jl b/base/compiler/ssair/inlining.jl index a77a67ab262def..d012c73a7dc9b7 100644 --- a/base/compiler/ssair/inlining.jl +++ b/base/compiler/ssair/inlining.jl @@ -1717,6 +1717,24 @@ function early_inline_special_case(ir::IRCode, stmt::Expr, flag::UInt32, elseif ⊑(optimizer_lattice(state.interp), cond, Bool) && stmt.args[3] === stmt.args[4] return SomeCase(stmt.args[3]) end + elseif f === and_int && length(argtypes) == 3 + argtype2 = argtypes[2] + if argtype2 isa Const && argtype2.val === true + return SomeCase(stmt.args[3]) + end + argtype3 = argtypes[3] + if argtype3 isa Const && argtype3.val === true + return SomeCase(stmt.args[2]) + end + elseif f === or_int && length(argtypes) == 3 + argtype2 = argtypes[2] + if argtype2 isa Const && argtype2.val === false + return SomeCase(stmt.args[3]) + end + argtype3 = argtypes[3] + if argtype3 isa Const && argtype3.val === false + return SomeCase(stmt.args[2]) + end end return nothing end diff --git a/test/compiler/inline.jl b/test/compiler/inline.jl index a8b5fd66dcd0d0..f44e6665b05fcc 100644 --- a/test/compiler/inline.jl +++ b/test/compiler/inline.jl @@ -2214,3 +2214,9 @@ let ir = Base.code_ircode((Issue52644,); optimize_until="Inlining") do t @test irfunc(Issue52644(Tuple{})) === :DataType @test_throws MethodError irfunc(Issue52644(Tuple{<:Integer})) end + +# inlining optimization for `and_int` and `or_int` +@test fully_eliminated(x->x&true, (Bool,); retval=Argument(2)) +@test fully_eliminated(x->true&x, (Bool,); retval=Argument(2)) +@test fully_eliminated(x->x|false, (Bool,); retval=Argument(2)) +@test fully_eliminated(x->false|x, (Bool,); retval=Argument(2))