Make value allocator aware of normal values used in branching

This way we avoid allocating and using a temporary variable when
branching based on the contents of a variable.
This commit is contained in:
John Lorentzson 2025-07-06 22:22:18 +02:00
parent b1b7d863b5
commit 9685f00e10

View file

@ -6,7 +6,7 @@
;;; allocator instead. ;;; allocator instead.
(defparameter +accumulator-users+ (defparameter +accumulator-users+
'(or ir-operation ir-assign)) '(or ir-operation ir-assign ir-if))
(defun calls-exist-between-p (start end) (defun calls-exist-between-p (start end)
(labels (labels
@ -50,14 +50,14 @@
:not-saved) :not-saved)
((typep data 'ir-variable) ((typep data 'ir-variable)
:named-variable) :named-variable)
((and (eql (next (definition data)) (last-use data))
(typep (last-use data) +accumulator-users+)
(eql data (first (inputs (last-use data)))))
:accumulator)
((and (eql (next (definition data)) (last-use data)) ((and (eql (next (definition data)) (last-use data))
(typep (last-use data) 'ir-if) (typep (last-use data) 'ir-if)
(typep (definition data) 'ir-comparison)) (typep (definition data) 'ir-comparison))
:branch) :branch)
((and (eql (next (definition data)) (last-use data))
(typep (last-use data) +accumulator-users+)
(eql data (first (inputs (last-use data)))))
:accumulator)
((and (= (length (users data)) 1) ((and (= (length (users data)) 1)
(typep (last-use data) 'ir-call) (typep (last-use data) 'ir-call)
(not (calls-exist-between-p (definition data) (last-use data)))) (not (calls-exist-between-p (definition data) (last-use data))))