Commits

Alex Gaynor  committed b6009ce

int_lshift(0, x) -> 0
int_rshift(0, x) -> 0

  • Participants
  • Parent commits ef1fb51

Comments (0)

Files changed (2)

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

 
         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:
+            self.make_constant_int(op.result, 0)
         else:
             self.emit_operation(op)
 
 
         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:
+            self.make_constant_int(op.result, 0)
         else:
             self.emit_operation(op)
 

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

         """
         self.optimize_loop(ops, expected)
 
+    def test_shift_zero(self):
+        ops = """
+        [i0]
+        i1 = int_lshift(0, i0)
+        i2 = int_rshift(0, i0)
+        jump(i1, i2)
+        """
+        expected = """
+        [i0]
+        jump(0, 0)
+        """
+        self.optimize_loop(ops, expected)
+
     def test_bound_and(self):
         ops = """
         [i0]