From: Stas Boukarev Date: Sun, 28 Jul 2013 18:26:18 +0000 (+0400) Subject: Microoptimize comparisons with 0 on x86oids. X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=d62278d1ad8359740e590810b12d84b50b2dc6be;p=sbcl.git Microoptimize comparisons with 0 on x86oids. Implement the common idiom of using TEST REG, REG in place of CMP REG, 0, saving 1 byte, for fast-if->/< VOPs. --- diff --git a/src/compiler/x86-64/arith.lisp b/src/compiler/x86-64/arith.lisp index c50e0dd..f455bff 100644 --- a/src/compiler/x86-64/arith.lisp +++ b/src/compiler/x86-64/arith.lisp @@ -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) diff --git a/src/compiler/x86/arith.lisp b/src/compiler/x86/arith.lisp index 9a04be9..f9c09e1 100644 --- a/src/compiler/x86/arith.lisp +++ b/src/compiler/x86/arith.lisp @@ -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)))))