Microoptimize comparisons with 0 on x86oids.
authorStas Boukarev <stassats@gmail.com>
Sun, 28 Jul 2013 18:26:18 +0000 (22:26 +0400)
committerStas Boukarev <stassats@gmail.com>
Sun, 28 Jul 2013 18:26:18 +0000 (22:26 +0400)
Implement the common idiom of using TEST REG, REG in place of CMP REG,
0, saving 1 byte, for fast-if->/< VOPs.

src/compiler/x86-64/arith.lisp
src/compiler/x86/arith.lisp

index c50e0dd..f455bff 100644 (file)
@@ -1328,13 +1328,17 @@ constant shift greater than word length")))
                         (:translate ,tran)
                         (:conditional ,(if signed cond unsigned))
                         (:generator ,cost
-                                    (inst cmp x
-                                          ,(case suffix
-                                             (-c/fixnum
-                                                `(constantize (fixnumize y)))
-                                             ((-c/signed -c/unsigned)
-                                                `(constantize y))
-                                             (t 'y))))))
+                          (cond ((and (sc-is x any-reg signed-reg unsigned-reg)
+                                      (eql y 0))
+                                 (inst test x x))
+                                (t
+                                 (inst cmp x
+                                       ,(case suffix
+                                          (-c/fixnum
+                                           `(constantize (fixnumize y)))
+                                          ((-c/signed -c/unsigned)
+                                           `(constantize y))
+                                          (t 'y))))))))
                    '(/fixnum -c/fixnum /signed -c/signed /unsigned -c/unsigned)
 ;                  '(/fixnum  /signed  /unsigned)
                    '(4 3 6 5 6 5)
index 9a04be9..f9c09e1 100644 (file)
@@ -1185,10 +1185,14 @@ constant shift greater than word length")))
                                            cond
                                            unsigned))
                         (:generator ,cost
-                                    (inst cmp x
-                                          ,(if (eq suffix '-c/fixnum)
-                                               '(fixnumize y)
-                                               'y)))))
+                          (cond ((and (sc-is x any-reg signed-reg unsigned-reg)
+                                      (eql y 0))
+                                 (inst test x x))
+                                (t
+                                 (inst cmp x
+                                       ,(if (eq suffix '-c/fixnum)
+                                            '(fixnumize y)
+                                            'y)))))))
                    '(/fixnum -c/fixnum /signed -c/signed /unsigned -c/unsigned)
                    '(4 3 6 5 6 5)
                    '(t t t t nil nil)))))