Ticket #21 (closed defect: fixed)
Modular arith bug 3
|Reported by:||rtoy||Owned by:||somebody|
The following code doesn't use modular arithmetic for ash:
(defun bug (v) (declare (type (unsigned-byte 32) v) (optimize (speed 3) (safety 0))) (logand #xffffffff (logxor v (ash v (- -16)))))
You get compiler warnings about ASH. But the equivalent code is ok:
(defun bug-a (v) (declare (type (unsigned-byte 32) v) (optimize (speed 3) (safety 0))) (ldb (byte 32 0) (logxor v (ash v (- -16)))))
Also, if in bug, you change (- -16) to the obvious 16, the compiler notes are gone, and the generated code is as expected.
What appears to be happening is that when logand-defopt-helper is run, the compiler doesn't know the type of the shift for ASH. Hence, it can't do modular arithmetic stuff. However, when the code is finally generated, you can see that the shift is now a known constant value of 16. I don't know why.