From: Andrea Corallo Date: Sun, 27 Dec 2020 20:33:07 +0000 (+0100) Subject: Add 1+ 1- integer range propagation support X-Git-Tag: emacs-28.0.90~2727^2~207 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=42fb6de0b366622cd59006f69fbc13c5cf3a0714;p=emacs.git Add 1+ 1- integer range propagation support * lisp/emacs-lisp/comp-cstr.el (comp-cstr-one): New special var. * lisp/emacs-lisp/comp.el (comp-fwprop-call): Propagate integer ranges on +1 -1. * test/src/comp-tests.el (comp-tests-type-spec-tests): Add two tests. --- diff --git a/lisp/emacs-lisp/comp-cstr.el b/lisp/emacs-lisp/comp-cstr.el index 28cffcf0661..57d93912d2f 100644 --- a/lisp/emacs-lisp/comp-cstr.el +++ b/lisp/emacs-lisp/comp-cstr.el @@ -154,6 +154,10 @@ Return them as multiple value." collect cstr into positives finally return (cl-values positives negatives))) +(defvar comp-cstr-one (make-comp-cstr :typeset () + :range '((1 . 1))) + "Represent the integer immediate one (1).") + ;;; Value handling. diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 336ed39145d..6b06ac5840d 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -2651,7 +2651,9 @@ Fold the call in case." (comp-mvar-neg lval) (comp-cstr-neg cstr)))) (cl-case f (+ (comp-cstr-add lval args)) - (- (comp-cstr-sub lval args))))) + (- (comp-cstr-sub lval args)) + (1+ (comp-cstr-add lval `(,(car args) ,comp-cstr-one))) + (1- (comp-cstr-sub lval `(,(car args) ,comp-cstr-one)))))) (defun comp-fwprop-insn (insn) "Propagate within INSN." diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index 154229ec872..d0e482bb501 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el @@ -1125,7 +1125,19 @@ Return a list of results." (< 1 j 5) (< 1 k 5)) (+ x y z i j k))) - (or null float (integer 12 24))))) + (or null float (integer 12 24))) + + ;; 45 + ((defun comp-tests-ret-type-spec-f (x) + (when (<= 1 x 5) + (1+ x))) + (or null float (integer 2 6))) + + ;;46 + ((defun comp-tests-ret-type-spec-f (x) + (when (<= 1 x 5) + (1- x))) + (or null float (integer 0 4))))) (defun comp-tests-define-type-spec-test (number x) `(comp-deftest ,(intern (format "ret-type-spec-%d" number)) ()