[pypy-commit] pypy bounds-int-add-or: rewrite to use power of two minus 2, no more overflow

squeaky noreply at buildbot.pypy.org
Mon Feb 17 23:59:09 CET 2014


Author: Squeaky <squeaky_pl at gmx.com>
Branch: bounds-int-add-or
Changeset: r69199:e19230cb6257
Date: 2014-02-17 21:14 +0100
http://bitbucket.org/pypy/pypy/changeset/e19230cb6257/

Log:	rewrite to use power of two minus 2, no more overflow

diff --git a/rpython/jit/metainterp/optimizeopt/intbounds.py b/rpython/jit/metainterp/optimizeopt/intbounds.py
--- a/rpython/jit/metainterp/optimizeopt/intbounds.py
+++ b/rpython/jit/metainterp/optimizeopt/intbounds.py
@@ -81,12 +81,8 @@
         if v1.intbound.known_ge(IntBound(0, 0)) and \
            v2.intbound.known_ge(IntBound(0, 0)):
             r = self.getvalue(op.result)
-            r.intbound.make_ge(IntLowerBound(0))
-
             mostsignificant = v1.intbound.upper | v2.intbound.upper
-            # check if next_power2 won't overflow
-            if mostsignificant < (1 << ((symbolic.WORD - 1) << 3)):
-                r.intbound.make_lt(IntUpperBound(next_power2(mostsignificant)))
+            r.intbound.intersect(IntBound(0, next_pow2_m1(mostsignificant)))
 
     optimize_INT_OR = optimize_INT_OR_or_XOR
     optimize_INT_XOR = optimize_INT_OR_or_XOR
@@ -108,9 +104,7 @@
         elif v1.intbound.known_ge(IntBound(0, 0)) and \
           v2.intbound.known_ge(IntBound(0, 0)):
             lesser = min(v1.intbound.upper, v2.intbound.upper)
-            # check if next_power2 won't overflow
-            if lesser < (1 << ((symbolic.WORD - 1) << 3)):
-                r.intbound.intersect(IntBound(0, next_power2(lesser) - 1))
+            r.intbound.intersect(IntBound(0, next_pow2_m1(lesser)))
 
     def optimize_INT_SUB(self, op):
         v1 = self.getvalue(op.getarg(0))
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -5422,7 +5422,7 @@
         """
         self.optimize_loop(ops, ops)
 
-    def test_or_same_arg(self):
+    def test_int_or_same_arg(self):
         ops = """
         [i0]
         i1 = int_or(i0, i0)


More information about the pypy-commit mailing list