[pypy-svn] pypy default: dissable the shift optimizations if the shift count is not known to be less than LONG_BIT
hakanardo
commits-noreply at bitbucket.org
Tue Apr 26 22:31:31 CEST 2011
Author: Hakan Ardo <hakan at debian.org>
Branch:
Changeset: r43645:4b667c14b991
Date: 2011-04-26 22:31 +0200
http://bitbucket.org/pypy/pypy/changeset/4b667c14b991/
Log: dissable the shift optimizations if the shift count is not known to
be less than LONG_BIT
diff --git a/pypy/jit/metainterp/optimizeopt/intutils.py b/pypy/jit/metainterp/optimizeopt/intutils.py
--- a/pypy/jit/metainterp/optimizeopt/intutils.py
+++ b/pypy/jit/metainterp/optimizeopt/intutils.py
@@ -1,4 +1,4 @@
-from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift
+from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift, LONG_BIT
class IntBound(object):
_attrs_ = ('has_upper', 'has_lower', 'upper', 'lower')
@@ -20,7 +20,7 @@
def make_lt(self, other):
return self.make_le(other.add(-1))
-
+
def make_ge(self, other):
if other.has_lower:
if not self.has_lower or other.lower > self.lower:
@@ -161,7 +161,8 @@
def lshift_bound(self, other):
if self.has_upper and self.has_lower and \
other.has_upper and other.has_lower and \
- other.known_ge(IntBound(0, 0)):
+ other.known_ge(IntBound(0, 0)) and \
+ other.known_lt(IntBound(LONG_BIT, LONG_BIT)):
try:
vals = (ovfcheck_lshift(self.upper, other.upper),
ovfcheck_lshift(self.upper, other.lower),
@@ -176,7 +177,8 @@
def rshift_bound(self, other):
if self.has_upper and self.has_lower and \
other.has_upper and other.has_lower and \
- other.known_ge(IntBound(0, 0)):
+ other.known_ge(IntBound(0, 0)) and \
+ other.known_lt(IntBound(LONG_BIT, LONG_BIT)):
vals = (self.upper >> other.upper,
self.upper >> other.lower,
self.lower >> other.upper,
diff --git a/pypy/jit/metainterp/test/test_intbound.py b/pypy/jit/metainterp/test/test_intbound.py
--- a/pypy/jit/metainterp/test/test_intbound.py
+++ b/pypy/jit/metainterp/test/test_intbound.py
@@ -2,6 +2,7 @@
IntLowerBound, IntUnbounded
from copy import copy
import sys
+from pypy.rlib.rarithmetic import LONG_BIT
def bound(a,b):
if a is None and b is None:
@@ -229,6 +230,12 @@
assert not b10.lshift_bound(b100).has_upper
assert not bmax.lshift_bound(b10).has_upper
assert b10.lshift_bound(b10).has_upper
+
+ for b in (b10, b100, bmax, IntBound(0, 0)):
+ for shift_count_bound in (IntBound(7, LONG_BIT), IntBound(-7, 7)):
+ #assert not b.lshift_bound(shift_count_bound).has_upper
+ assert not b.rshift_bound(shift_count_bound).has_upper
+
def test_div_bound():
for _, _, b1 in some_bounds():
More information about the Pypy-commit
mailing list