Commits

Alex Gaynor  committed 27cc4ad

When a newstr is allocated in the JIT, we can propogate the strlen, even if it isn't a constant.

  • Participants
  • Parent commits 95649f1

Comments (0)

Files changed (2)

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

         setfield_gc(p0, p1, descr=valuedescr)
         jump(p0)
         """
+        # It used to be the case that this would have a series of
+        # strsetitem(p1, idx, 0), which was silly because memory is 0 filled
+        # when allocated.
         expected = """
         [p0]
         p1 = newstr(4)
         """
         self.optimize_loop(ops, expected)
 
+    def test_newstr_strlen(self):
+        ops = """
+        [i0]
+        p0 = newstr(i0)
+        escape(p0)
+        i1 = strlen(p0)
+        i2 = int_add(i1, 1)
+        jump(i2)
+        """
+        expected = """
+        [i0]
+        p0 = newstr(i0)
+        escape(p0)
+        i1 = int_add(i0, 1)
+        jump(i1)
+        """
+        self.optimize_loop(ops, expected)
+
 
 class TestLLtype(BaseTestOptimizeBasic, LLtypeMixin):
     pass

File pypy/jit/metainterp/optimizeopt/vstring.py

         else:
             self.getvalue(op.result).ensure_nonnull()
             self.emit_operation(op)
+            self.pure(mode.STRLEN, [op.result], op.getarg(0))
 
     def optimize_STRSETITEM(self, op):
         value = self.getvalue(op.getarg(0))