summaryrefslogtreecommitdiffstats
path: root/stdlib
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-04-17 15:40:11 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-04-17 15:40:11 -0700
commit1cd7fb50f4a68b39c6715203bc7e92808188d7c0 (patch)
tree1258777aada4a72233fdc7a45f2867b07513ab47 /stdlib
parent559e2cace50b534d7591d7bb6f0ba68afe09dc68 (diff)
downloadtxr-1cd7fb50f4a68b39c6715203bc7e92808188d7c0.tar.gz
txr-1cd7fb50f4a68b39c6715203bc7e92808188d7c0.tar.bz2
txr-1cd7fb50f4a68b39c6715203bc7e92808188d7c0.zip
compiler: move peephole pattern and remove condition.
* stdlib/optimize.tl (basic-blocks do-peephole-block): Remove the local function only-locally-used-treg. This is unnecessary because the optimization is valid even if the treg is used in downstream basic blocks. It was necessary previously in the old version of this optimization in which we deleted the first instruction which sets the treg's value. We are now depending on it being identified as a dead register. Also, moving the rule to the end. The reason is that there are cases when the pattern matches, but it returns insns. That causes the rewrite macro to march down to the next instruction, skipping other patterns. This could be bad, unless the pattern is the last one tried before the @else fallback.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/optimize.tl26
1 files changed, 11 insertions, 15 deletions
diff --git a/stdlib/optimize.tl b/stdlib/optimize.tl
index bb1b84c3..e78c9300 100644
--- a/stdlib/optimize.tl
+++ b/stdlib/optimize.tl
@@ -384,10 +384,7 @@
(defmeth basic-blocks do-peephole-block (bb bl code)
(labels ((dead-treg (insn n)
(let ((li [bb.li-hash insn]))
- (and li (not (bit li.used n)))))
- (only-locally-used-treg (insn n)
- (let ((li [bb.li-hash insn]))
- (and li (bit li.used n) (not (bit bl.live n))))))
+ (and li (not (bit li.used n))))))
(rewrite-case insns code
;; dead t-reg
(@(require ((@(or mov getlx getv getf getfb) (t @n) . @nil) . @nil)
@@ -407,17 +404,6 @@
(pushnew bl bb.rescan)
(set bb.recalc t)
(cdr insns))
- ;; unnecessary copying t-reg
- (@(require ((mov @(as dst (t @n)) @src) . @rest)
- (only-locally-used-treg (car insns) n)
- (nequal dst src))
- (let ((ren bb.(rename rest dst src)))
- (cond
- ((nequal rest ren)
- (pushnew bl bb.rescan)
- (set bb.recalc t)
- (cons (car insns) ren))
- (t insns))))
;; wasteful moves
(((mov @reg0 @nil) (mov @reg0 @nil) . @nil)
(cdr insns))
@@ -500,6 +486,16 @@
bl.next nil
bl.links nil))
oinsns))
+ ;; unnecessary copying t-reg
+ (@(require ((mov @(as dst (t @nil)) @src) . @rest)
+ (nequal dst src))
+ (let ((ren bb.(rename rest dst src)))
+ (cond
+ ((nequal rest ren)
+ (pushnew bl bb.rescan)
+ (set bb.recalc t)
+ (cons (car insns) ren))
+ (t insns))))
(@nil insns))))
(defmeth basic-blocks peephole (bb)