diff options
author | 2017-10-11 10:41:10 +0200 | |
---|---|---|
committer | 2017-10-11 10:41:10 +0200 | |
commit | 370c8eac32b6e3365bc84f02492c2c9b4bbd51a9 (patch) | |
tree | bcf74d8488c8032852f59a1929148a6333df7893 /rpython | |
parent | fix annotation for 1b7397a88e79 - same signature for {set, list}.switch_to_ob... (diff) | |
download | pypy-370c8eac32b6e3365bc84f02492c2c9b4bbd51a9.tar.gz pypy-370c8eac32b6e3365bc84f02492c2c9b4bbd51a9.tar.bz2 pypy-370c8eac32b6e3365bc84f02492c2c9b4bbd51a9.zip |
some passing cases, and comments how they work
Diffstat (limited to 'rpython')
-rw-r--r-- | rpython/jit/metainterp/optimizeopt/intbounds.py | 6 | ||||
-rw-r--r-- | rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py | 49 |
2 files changed, 55 insertions, 0 deletions
diff --git a/rpython/jit/metainterp/optimizeopt/intbounds.py b/rpython/jit/metainterp/optimizeopt/intbounds.py index ac09864741..81320b9630 100644 --- a/rpython/jit/metainterp/optimizeopt/intbounds.py +++ b/rpython/jit/metainterp/optimizeopt/intbounds.py @@ -305,6 +305,10 @@ class OptIntBounds(Optimization): # Transform into INT_ADD. The following guard will be killed # by optimize_GUARD_NO_OVERFLOW; if we see instead an # optimize_GUARD_OVERFLOW, then InvalidLoop. + + # NB: this case also takes care of int_add_ovf with 0 as on of the + # arguments: the result will be bounded, and then the optimization + # for int_add with 0 as argument will remove the op. op = self.replace_op_with(op, rop.INT_ADD) return self.emit(op) @@ -325,6 +329,7 @@ class OptIntBounds(Optimization): return None resbound = b0.sub_bound(b1) if resbound.bounded(): + # this case takes care of int_sub_ovf(x, 0) as well op = self.replace_op_with(op, rop.INT_SUB) return self.emit(op) @@ -342,6 +347,7 @@ class OptIntBounds(Optimization): b2 = self.getintbound(op.getarg(1)) resbound = b1.mul_bound(b2) if resbound.bounded(): + # this case also takes care of multiplication with 0 and 1 op = self.replace_op_with(op, rop.INT_MUL) return self.emit(op) diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py index e60c38d652..9b6891eaf5 100644 --- a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py +++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py @@ -1962,6 +1962,55 @@ class BaseTestOptimizeBasic(BaseTestBasic): """ self.optimize_loop(ops, expected) + ops = """ + [i0] + i1 = int_mul_ovf(0, i0) + guard_no_overflow() [] + jump(i1) + """ + expected = """ + [i0] + jump(0) + """ + self.optimize_loop(ops, expected) + + ops = """ + [i0] + i1 = int_mul_ovf(i0, 0) + guard_no_overflow() [] + jump(i1) + """ + expected = """ + [i0] + jump(0) + """ + self.optimize_loop(ops, expected) + + ops = """ + [i0] + i1 = int_mul_ovf(1, i0) + guard_no_overflow() [] + jump(i1) + """ + expected = """ + [i0] + jump(i0) + """ + self.optimize_loop(ops, expected) + + ops = """ + [i0] + i1 = int_mul_ovf(i0, 1) + guard_no_overflow() [] + jump(i1) + """ + expected = """ + [i0] + jump(i0) + """ + self.optimize_loop(ops, expected) + + def test_fold_constant_partial_ops_float(self): ops = """ [f0] |