Opened 6 years ago

Closed 6 years ago

#21 closed defect (fixed)

Modular arith bug 3

Reported by: rtoy Owned by: somebody
Priority: minor Milestone:
Component: Core Version: 2008-08
Keywords: Cc:


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 6 years ago by rtoy

  • Priority changed from major to minor

comment:2 Changed 6 years ago by rtoy

This should be fixed in the 2008-12 snapshot.

We now delay logand-defopt-helperuntil after IR2 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.

comment:3 Changed 6 years ago by rtoy

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.