From 5e8fa7f8d40eed6218ae39886181eff0140059b3 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 27 Feb 2021 12:17:46 -0800 Subject: compiler: optimize useless if to jmp. * share/txr/stdlib/optimize.tl (basic-blocks thread-jumps-block): This is a complementary optimization to the one which matches (if (d @reg) @jlabel). An if instruction conditional on the nil register (t 0) is always taken, and can be rewritten to a jmp. This can promote elimination of dead code. --- share/txr/stdlib/optimize.tl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/share/txr/stdlib/optimize.tl b/share/txr/stdlib/optimize.tl index 259a64ae..81536c32 100644 --- a/share/txr/stdlib/optimize.tl +++ b/share/txr/stdlib/optimize.tl @@ -258,6 +258,8 @@ (set insn ninsn ninsn (match-case insn ((if (d @reg) @jlabel) nil) + ((if (t 0) @jlabel) + ^(jmp ,jlabel)) ((jmp @jlabel) (let ((jinsns [bb.hash jlabel].insns)) (match-case jinsns -- cgit v1.2.3