From 16e6b383cff55a7c417fa8bff33c9cca1d04d3df Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 29 Sep 2021 22:46:01 -0700 Subject: compiler: remove impossible cases in jump threading. * stdlib/optimize.tl (basic-blocks thread-jumps-block): There can't be any instructions in a basic block after an if or ifq, so in these cases, jrest is always nil. Let's ignore that nil efficiently with @nil, and get rid of the cut-block branches of the code. There is a similar case in peephole-block, but the target of the jump is an (end ...) which doesn't necessarily end a basic block. I temporarily put in an (assert (null jrest)), and, surprisingly, it never went off during a rebuild of the library or running of the test case. Still, only a jend ends a basic block; it would not be correct to simplify it like these two cases in thread-jumps-block. --- stdlib/optimize.tl | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/stdlib/optimize.tl b/stdlib/optimize.tl index db069efa..5f81bc10 100644 --- a/stdlib/optimize.tl +++ b/stdlib/optimize.tl @@ -309,10 +309,8 @@ (jmp @(and @jjlabel @(not @jlabel))) . @nil) ^(if ,reg ,jjlabel)) ((@jlabel - (ifq @reg (t 0) @jjlabel) . @jrest) - (let ((xbl (if jrest - bb.(cut-block [bb.hash jlabel] jrest jinsns) - bb.(next-block [bb.hash jlabel])))) + (ifq @reg (t 0) @jjlabel) . @nil) + (let ((xbl bb.(next-block [bb.hash jlabel]))) (if xbl ^(if ,reg ,xbl.label) insn))) @@ -326,10 +324,8 @@ ^(ifq ,reg ,creg ,jjlabel)) ((@(require @jlabel (equal creg '(t 0))) (if @reg - @(and @jjlabel @(not @jlabel))) . @jrest) - (let ((xbl (if jrest - bb.(cut-block [bb.hash jlabel] jrest jinsns) - bb.(next-block [bb.hash jlabel])))) + @(and @jjlabel @(not @jlabel))) . @nil) + (let ((xbl bb.(next-block [bb.hash jlabel]))) (if xbl ^(ifq ,reg ,creg ,xbl.label) insn))) -- cgit v1.2.3