Second though, that will recompile on every call, but if we cache the
promote functions:
def main(n, promoters={}):
i, a = 0, 0
if n not in promoters:
exec """def promote(n):
assert n==%d""" % n
promoters[n] = promote
else:
promote = promoters[n]
while i < n:
promote(n)
a += i+5
i += 1
return a
we will actualy get rid of the extra ptr_eq and guard_false too...
On Thu, Apr 14, 2011 at 4:01 PM, Hakan Ardo <[email protected]> wrote:
> On Thu, Apr 14, 2011 at 3:01 PM, Antonio Cuni <[email protected]> wrote:
>>
>> Of course the ovf check needs to be there because we don't specialize the
>> loop
>> on the value of n. Although it might be cool to be able to do promotion at
>> applevel, for those who really want :-)
>
> Well, you can actually (sort of):
>
> def main(n):
> i, a = 0, 0
> exec """def promote(n):
> assert n==%d""" % n
> while i < n:
> promote(n)
> a += i+5
> i += 1
> return a
>
> With this I get two extra operations in the loop:
>
> i11 = ptr_eq(ConstPtr(ptr10), p7)
> guard_false(i11, descr=<Guard4>) [p1, p0, p2, p3, p4, i5, i6]
>
> but p7 is loop-invariant so they should be easy to get rid of. I don't
> know why they are not already...
>
> --
> Håkan Ardö
>
--
Håkan Ardö
_______________________________________________
[email protected]
http://codespeak.net/mailman/listinfo/pypy-dev