Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r45149:440bff536936
Date: 2011-06-27 14:03 -0700
http://bitbucket.org/pypy/pypy/changeset/440bff536936/
Log: Make the optimizer recognize the effect that int_is_true();
guard_true() has on the bounds. Specifically this removes an op + a
guard in the case of something like `if x and x[0] == "f"` where x
is a string at app level.
diff --git a/pypy/jit/metainterp/optimizeopt/intbounds.py
b/pypy/jit/metainterp/optimizeopt/intbounds.py
--- a/pypy/jit/metainterp/optimizeopt/intbounds.py
+++ b/pypy/jit/metainterp/optimizeopt/intbounds.py
@@ -1,7 +1,7 @@
from pypy.jit.metainterp.optimizeopt.optimizer import Optimization, CONST_1,
CONST_0
from pypy.jit.metainterp.optimizeopt.util import _findall
-from pypy.jit.metainterp.optimizeopt.intutils import IntBound, IntUnbounded, \
- IntLowerBound, IntUpperBound
+from pypy.jit.metainterp.optimizeopt.intutils import (IntBound, IntUnbounded,
+ IntLowerBound, IntUpperBound)
from pypy.jit.metainterp.history import Const, ConstInt
from pypy.jit.metainterp.resoperation import rop, ResOperation
@@ -373,6 +373,15 @@
if v2.intbound.intersect(v1.intbound):
self.propagate_bounds_backward(op.getarg(1))
+ def propagate_bounds_INT_IS_TRUE(self, op):
+ r = self.getvalue(op.result)
+ if r.is_constant():
+ if r.box.same_constant(CONST_1):
+ v1 = self.getvalue(op.getarg(0))
+ if v1.intbound.known_ge(IntBound(0, 0)):
+ v1.intbound.make_gt(IntBound(0, 0))
+ self.propagate_bounds_backward(op.getarg(0))
+
def propagate_bounds_INT_ADD(self, op):
v1 = self.getvalue(op.getarg(0))
v2 = self.getvalue(op.getarg(1))
@@ -418,5 +427,6 @@
propagate_bounds_INT_SUB_OVF = propagate_bounds_INT_SUB
propagate_bounds_INT_MUL_OVF = propagate_bounds_INT_MUL
+
optimize_ops = _findall(OptIntBounds, 'optimize_')
propagate_bounds_ops = _findall(OptIntBounds, 'propagate_bounds_')
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -4497,6 +4497,25 @@
"""
self.optimize_loop(ops, expected)
+ def test_int_is_true_bounds(self):
+ ops = """
+ [p0]
+ i0 = strlen(p0)
+ i1 = int_is_true(i0)
+ guard_true(i1) []
+ i2 = int_ge(0, i0)
+ guard_false(i2) []
+ jump(p0)
+ """
+ expected = """
+ [p0]
+ i0 = strlen(p0)
+ i1 = int_is_true(i0)
+ guard_true(i1) []
+ jump(p0)
+ """
+ self.optimize_loop(ops, expected)
+
class TestLLtype(BaseTestOptimizeBasic, LLtypeMixin):
pass
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit