The problem here is that the AREF gets converted to:
(SB-KERNEL:DATA-VECTOR-REF-WITH-OFFSET <array> V <offset>)
and the compiler doesn't know that V's type (which has been asserted
to be an array index) can actually vary based on the value of OFFSET
(31 in this case).
I think the right thing to do here is a DEFOPTIMIZER for
DATA-VECTOR-REF-WITH-OFFSET that looks something like:
(in-package :sb-c)
(defoptimizer (data-vector-ref-with-offset optimizer) ((array index
offset) node)
(let ((did-something nil))
(do-uses (n index)
(when (and (cast-p n)
(eq (cast-type-check n) t)
(constant-lvar-p offset)
(numeric-type-p (cast-asserted-type n))
(numeric-type-p (cast-type-to-check n)))
(let* ((value (lvar-value offset))
(upper-array-limit (1- sb!xc:array-dimension-limit))
(actual-index-type (modified-numeric-type (cast-type-to-check n)
:low (- value)
:high (min upper-array-limit
(- upper-array-limit value)))))
(setf (cast-asserted-type n) actual-index-type
(cast-type-to-check n) actual-index-type
(cast-reoptimize n) t
did-something t))))
did-something))
But this is getting into parts of IR1 that I don't know very well,
hence the overzealous checking. I haven't tried bootstrapping with
this, but it does have the expected effect on the assembly:
; 0621799C: 40F6C601 TEST SIL, 1 ;
no-arg-parsing entry point
; A0: 752A JNE L0
; A2: 488BCE MOV RCX, RSI
; A5: 4883F9C2 CMP RCX, -62
; A9: 7C21 JL L0
; AB: 488BCE MOV RCX, RSI
; AE: 4883F93E CMP RCX, 62
; B2: 7F18 JNLE L0
; B4: 488BCE MOV RCX, RSI
; B7: 488B0572FFFFFF MOV RAX, [RIP-142] ; #(0 0 0 0
; ...)
; BE: 488B9488F9000000 MOV RDX, [RAX+RCX*4+249]
Those more experienced in IR1...does the above look plausible? Are
there better ways to express what we want to do here?
-Nathan
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and
> their applications. This 200-page book is written by three acclaimed
> leaders in the field. The early access version is available now.
> Download your free book today!
http://p.sf.net/sfu/neotech_d2d_may
> _______________________________________________
> Sbcl-devel mailing list
>
Sbcl-...@lists.sourceforge.net
>
https://lists.sourceforge.net/lists/listinfo/sbcl-devel
>
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and
their applications. This 200-page book is written by three acclaimed
leaders in the field. The early access version is available now.
Download your free book today!
http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
Sbcl-devel mailing list
Sbcl-...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sbcl-devel