1. Pypy
  2. Untitled project
  3. pypy

Commits

Alex Gaynor  committed ef1fb51

int_sub(0, x) -> int_neg(x)

  • Participants
  • Parent commits 410b98e
  • Branches default

Comments (0)

Files changed (2)

File rpython/jit/metainterp/optimizeopt/rewrite.py

View file
  • Ignore whitespace
         v2 = self.getvalue(op.getarg(1))
         if v2.is_constant() and v2.box.getint() == 0:
             self.make_equal_to(op.result, v1)
+        elif v1.is_constant() and v1.box.getint() == 0:
+            op = op.copy_and_change(rop.INT_NEG, args=[v2.box])
+            self.emit_operation(op)
         elif v1 is v2:
             self.make_constant_int(op.result, 0)
         else:

File rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py

View file
  • Ignore whitespace
         ops = """
         [i0]
         i1 = int_sub(i0, i0)
-        jump(i1)
+        i2 = int_sub(i1, i0)
+        jump(i1, i2)
         """
         expected = """
         [i0]
-        jump(0)
+        i2 = int_neg(i0)
+        jump(0, i2)
         """
         self.optimize_loop(ops, expected)