emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/native-comp 42fb6de 4/4: Add 1+ 1- integer range propagation sup


From: Andrea Corallo
Subject: feature/native-comp 42fb6de 4/4: Add 1+ 1- integer range propagation support
Date: Sun, 27 Dec 2020 15:53:39 -0500 (EST)

branch: feature/native-comp
commit 42fb6de0b366622cd59006f69fbc13c5cf3a0714
Author: Andrea Corallo <akrl@sdf.org>
Commit: Andrea Corallo <akrl@sdf.org>

    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.
---
 lisp/emacs-lisp/comp-cstr.el |  4 ++++
 lisp/emacs-lisp/comp.el      |  4 +++-
 test/src/comp-tests.el       | 14 +++++++++++++-
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/comp-cstr.el b/lisp/emacs-lisp/comp-cstr.el
index 28cffcf..57d9391 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 336ed39..6b06ac5 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 154229e..d0e482b 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)) ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]