LOGBITP and LOGTEST optimizations from x86.
[sbcl.git] / src / compiler / x86-64 / insts.lisp
index 15efc7d..0a982cd 100644 (file)
              (t
               (error "bogus operands for TEST: ~S and ~S" this that)))))))
 
+;;; Emit the most compact form of the test immediate instruction,
+;;; using an 8 bit test when the immediate is only 8 bits and the
+;;; value is one of the four low registers (rax, rbx, rcx, rdx) or the
+;;; control stack.
+(defun emit-optimized-test-inst (x y)
+  (typecase y
+    ((unsigned-byte 7)
+     (let ((offset (tn-offset x)))
+       (cond ((and (sc-is x any-reg descriptor-reg)
+                   (or (= offset rax-offset) (= offset rbx-offset)
+                       (= offset rcx-offset) (= offset rdx-offset)))
+              (inst test (reg-in-size x :byte) y))
+             ((sc-is x control-stack)
+              (inst test (make-ea :byte :base rbp-tn
+                                  :disp (frame-byte-offset offset))
+                    y))
+             (t
+              (inst test x y)))))
+    (t
+     (inst test x y))))
+
 (define-instruction or (segment dst src)
   (:printer-list
    (arith-inst-printer-list #b001))