slavapestov/factor — Issue #246: Specialization confuses type propagation?
Author: mrjbq7
Created: 2011-10-11 17:42:34+00:00
State: open

I was looking into why #235 gets slower, and it seems like specializing words confuses the compiler in a couple ways:

Looking at the `optimized.` output for `benchmark.yuv-to-rgb`, before #235:

```factor
"COMPLEX SHUFFLE" >R >R "COMPLEX SHUFFLE"
"COMPLEX SHUFFLE"
```

And after specializing `nth` and `set-nth` it, it adds useless code (`dup tag ...`):

```factor
"COMPLEX SHUFFLE" >R >R "COMPLEX SHUFFLE" dup tag 0
eq? [ ] [ ] if
"COMPLEX SHUFFLE"
```

In the case of `benchmark.tuple-arrays`, its a little different, before it uses fixnum primitives:

```factor
"COMPLEX SHUFFLE" >R >R swap >R fixnum*fast
R> 2dup "COMPLEX SHUFFLE" >R R> >R R> swap
2 fixnum+fast slot
"COMPLEX SHUFFLE" "COMPLEX SHUFFLE" 1
"COMPLEX SHUFFLE"
( 6342045 6347969 6347971 -- 6342045 6347969 6347971 6347969 6347971 )
"COMPLEX SHUFFLE" >R fixnum+fast
R> >R R> swap 2 fixnum+fast slot
```

And after, it checks for fixnum tag and has two code paths involving bignums:

```factor
"COMPLEX SHUFFLE" >R >R swap >R fixnum*
R> 2dup "COMPLEX SHUFFLE" >R R> over tag 0
eq?
[ >R R> swap 2 fixnum+fast slot ] [
>R bignum>fixnum R> swap 2 fixnum+fast
slot
] if
"COMPLEX SHUFFLE" "COMPLEX SHUFFLE" 1
"COMPLEX SHUFFLE"
( 6641667 6647932 6647934 -- 6641667 6647932 6647934 6647932 6647934 )
"COMPLEX SHUFFLE" >R dup tag 0 eq?
[ fixnum+ ] [ >R fixnum>bignum R> bignum+ ]
if R> over tag 0 eq?
[ >R R> swap 2 fixnum+fast slot ] [
>R bignum>fixnum R> swap 2 fixnum+fast
slot
] if
```