From 8e4f23224a90d35683dbd45007682c861c4eb354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 30 Aug 2018 06:55:37 +0200 Subject: beam_peep: Add is_boolean optimization of select_val A select_val instruction that test whether a register is a boolean like this: {select_val,Reg,{f,Fail},{list,[{atom,true},Lbl,{atom,false},Lbl]}}. can be replaced with an is_boolean test: {test,is_boolean,{f,Fail},[Reg]}. {jump,{f,Lbl}}. This optimization is currently done in beam_dead. However, if done in the beam_peep, it can catch more opportunities to do the optimization, because after having run beam_jump, labels that were different have been coalesced. --- lib/compiler/src/beam_peep.erl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/compiler/src') diff --git a/lib/compiler/src/beam_peep.erl b/lib/compiler/src/beam_peep.erl index 74da6aa704..2323a439e9 100644 --- a/lib/compiler/src/beam_peep.erl +++ b/lib/compiler/src/beam_peep.erl @@ -112,6 +112,10 @@ peep([{select,Op,R,F,Vls0}|Is], SeenTests0, Acc0) -> %% Single value left. Convert to regular test Is1 = [{test,test_arity,F,[R,Arity]},{jump,Lbl}|Is], peep(Is1, SeenTests0, Acc0); + [{atom,B1},Lbl,{atom,B2},Lbl] when B1 =:= not B2 -> + %% Replace with is_boolean test. + Is1 = [{test,is_boolean,F,[R]},{jump,Lbl}|Is], + peep(Is1, SeenTests0, Acc0); [_|_]=Vls -> I = {select,Op,R,F,Vls}, peep(Is, gb_sets:empty(), [I|Acc0]) -- cgit v1.2.3