Inline (the fixnum (* x y))

This commit is contained in:
Stas Boukarev 2025-09-04 02:34:01 +03:00
parent 0e7d8d574d
commit ec111830aa
3 changed files with 35 additions and 3 deletions

View file

@ -3922,7 +3922,7 @@
(multiple-value-bind (cast) (cast-or-check-bound-type node (specifier-type 'fixnum))
(when cast
(cond ((csubtypep (lvar-type x) (specifier-type 'integer))
(delay-ir1-transform node :constraint)
(delay-ir1-transform node :ir1-phases)
(if (and
(not (types-equal-or-intersect (lvar-type y) (specifier-type '(eql 0))))
(or (not (types-equal-or-intersect (lvar-type x) (specifier-type '(eql #.(- most-negative-fixnum)))))
@ -3943,6 +3943,35 @@
(deftransform * ((y x) (fixnum t) * :node node :priority :last)
(unknown-*-transform x y node))
(deftransform * ((x y) (t t) * :node node :priority :last)
(or (unless (or (csubtypep (lvar-type x) (specifier-type 'word))
(csubtypep (lvar-type x) (specifier-type 'sb-vm:signed-word))
(csubtypep (lvar-type x) (specifier-type '(or complex float)))
(csubtypep (lvar-type y) (specifier-type 'word))
(csubtypep (lvar-type y) (specifier-type 'sb-vm:signed-word))
(csubtypep (lvar-type y) (specifier-type '(or complex float))))
(block nil
(multiple-value-bind (cast) (cast-or-check-bound-type node (specifier-type 'fixnum))
(when cast
(cond ((and (csubtypep (lvar-type x) (specifier-type '(and integer (not (member 0 -1)))))
(csubtypep (lvar-type y) (specifier-type '(and integer (not (member 0 -1))))))
(delay-ir1-transform node :constraint)
`(* (the fixnum x) (the fixnum y)))
((and (csubtypep (lvar-type x) (specifier-type 'integer))
(csubtypep (lvar-type y) (specifier-type 'integer)))
(delay-ir1-transform node :constraint)
`(* (the sb-vm:signed-word x) (the sb-vm:signed-word y)))
(t
(delay-ir1-transform node :ir1-phases)
(delete-lvar-cast-if (specifier-type 'number) y)
(delete-lvar-cast-if (specifier-type 'number) x)
`(if (and (typep x 'fixnum)
(typep y 'fixnum))
(* (truly-the fixnum x)
(truly-the fixnum y))
(two-arg-* x y))))))))
(give-up-ir1-transform)))
(defun overflow-transform-1 (name x node)
(unless (node-lvar node)
(give-up-ir1-transform))

View file

@ -862,4 +862,7 @@
(the fixnum (* y x))))))
(assert (equal (ctu:ir1-named-calls `(lambda (x)
(the fixnum (* x 2))))
'(sb-kernel:*-by-fixnum-to-fixnum))))
'(sb-kernel:*-by-fixnum-to-fixnum)))
(assert (not (ctu:ir1-named-calls `(lambda (x y)
(declare (integer x y))
(the fixnum (* x y)))))))