Author: Carl Friedrich Bolz <[email protected]>
Branch:
Changeset: r82369:4ee6b2b67a6b
Date: 2016-02-21 17:27 +0100
http://bitbucket.org/pypy/pypy/changeset/4ee6b2b67a6b/
Log: reduce all guards from int_floordiv_ovf if one of the arguments is
constant
(completely random old diff I had lying around)
diff --git a/rpython/jit/codewriter/support.py
b/rpython/jit/codewriter/support.py
--- a/rpython/jit/codewriter/support.py
+++ b/rpython/jit/codewriter/support.py
@@ -246,12 +246,12 @@
def _ll_2_int_floordiv_ovf_zer(x, y):
if y == 0:
raise ZeroDivisionError
- if x == -sys.maxint - 1 and y == -1:
- raise OverflowError
- return llop.int_floordiv(lltype.Signed, x, y)
+ return _ll_2_int_floordiv_ovf(x, y)
def _ll_2_int_floordiv_ovf(x, y):
- if x == -sys.maxint - 1 and y == -1:
+ # intentionally not short-circuited to produce only one guard
+ # and to remove the check fully if one of the arguments is known
+ if (x == -sys.maxint - 1) & (y == -1):
raise OverflowError
return llop.int_floordiv(lltype.Signed, x, y)
@@ -263,12 +263,11 @@
def _ll_2_int_mod_ovf_zer(x, y):
if y == 0:
raise ZeroDivisionError
- if x == -sys.maxint - 1 and y == -1:
- raise OverflowError
- return llop.int_mod(lltype.Signed, x, y)
+ return _ll_2_int_mod_ovf(x, y)
def _ll_2_int_mod_ovf(x, y):
- if x == -sys.maxint - 1 and y == -1:
+ #see comment in _ll_2_int_floordiv_ovf
+ if (x == -sys.maxint - 1) & (y == -1):
raise OverflowError
return llop.int_mod(lltype.Signed, x, y)
diff --git a/rpython/jit/metainterp/test/test_ajit.py
b/rpython/jit/metainterp/test/test_ajit.py
--- a/rpython/jit/metainterp/test/test_ajit.py
+++ b/rpython/jit/metainterp/test/test_ajit.py
@@ -1199,6 +1199,31 @@
(-sys.maxint-1) // (-6) +
100 * 8)
+ def test_overflow_fold_if_divisor_constant(self):
+ import sys
+ from rpython.rtyper.lltypesystem.lloperation import llop
+ myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res'])
+ def f(x, y):
+ res = 0
+ while y > 0:
+ myjitdriver.can_enter_jit(x=x, y=y, res=res)
+ myjitdriver.jit_merge_point(x=x, y=y, res=res)
+ try:
+ res += llop.int_floordiv_ovf(lltype.Signed,
+ x, 2)
+ res += llop.int_mod_ovf(lltype.Signed,
+ x, 2)
+ x += 5
+ except OverflowError:
+ res += 100
+ y -= 1
+ return res
+ res = self.meta_interp(f, [-41, 8])
+ # the guard_true are for the loop condition
+ # the guard_false needed to check whether an overflow can occur have
+ # been folded away
+ self.check_resops(guard_true=2, guard_false=0)
+
def test_isinstance(self):
class A:
pass
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit