Opened 16 years ago
Closed 16 years ago
#21 closed defect (fixed)
Modular arith bug 3
Reported by: | Raymond Toy | Owned by: | somebody |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | Core | Version: | 2008-08 |
Keywords: | Cc: |
Description
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.
Change History (3)
comment:1 Changed 16 years ago by
Priority: | major → minor |
---|
comment:2 Changed 16 years ago by
comment:3 Changed 16 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note: See
TracTickets for help on using
tickets.
This should be fixed in the 2008-12 snapshot.
We now delay
logand-defopt-helper
until afterIR2
optimizations are done so that we give the compiler a chance to derive all of the variable types. Then we run this optimizer. This will cause some increase in compilation time for code that deals with modular arithmetic, but we should get better behaved modular arithmetic.