[pypy-commit] pypy default: fix for a bug where you do newstr(<const>) copystrcontent strgetitem and the JIT was incorrectly folding teh strgetitem
alex_gaynor
noreply at buildbot.pypy.org
Sat Sep 24 04:11:35 CEST 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r47574:1d957571e185
Date: 2011-09-23 22:11 -0400
http://bitbucket.org/pypy/pypy/changeset/1d957571e185/
Log: fix for a bug where you do newstr(<const>) copystrcontent strgetitem
and the JIT was incorrectly folding teh strgetitem
diff --git a/pypy/jit/metainterp/optimizeopt/vstring.py b/pypy/jit/metainterp/optimizeopt/vstring.py
--- a/pypy/jit/metainterp/optimizeopt/vstring.py
+++ b/pypy/jit/metainterp/optimizeopt/vstring.py
@@ -368,7 +368,7 @@
def new(self):
return OptString()
-
+
def make_vstring_plain(self, box, source_op, mode):
vvalue = VStringPlainValue(self.optimizer, box, source_op, mode)
self.make_equal_to(box, vvalue)
@@ -438,7 +438,11 @@
#
if isinstance(value, VStringPlainValue): # even if no longer virtual
if vindex.is_constant():
- return value.getitem(vindex.box.getint())
+ res = value.getitem(vindex.box.getint())
+ # If it is uninitialized we can't return it, it was set by a
+ # COPYSTRCONTENT, not a STRSETITEM
+ if res is not optimizer.CVAL_UNINITIALIZED_ZERO:
+ return res
#
resbox = _strgetitem(self.optimizer, value.force_box(), vindex.force_box(), mode)
return self.getvalue(resbox)
diff --git a/pypy/jit/metainterp/test/test_string.py b/pypy/jit/metainterp/test/test_string.py
--- a/pypy/jit/metainterp/test/test_string.py
+++ b/pypy/jit/metainterp/test/test_string.py
@@ -1,9 +1,11 @@
import py
+
+from pypy.jit.codewriter.policy import StopAtXPolicy
+from pypy.jit.metainterp.test.support import LLJitMixin, OOJitMixin
+from pypy.rlib.debug import debug_print
from pypy.rlib.jit import JitDriver, dont_look_inside, we_are_jitted
-from pypy.rlib.debug import debug_print
-from pypy.jit.codewriter.policy import StopAtXPolicy
+from pypy.rlib.rstring import StringBuilder
from pypy.rpython.ootypesystem import ootype
-from pypy.jit.metainterp.test.support import LLJitMixin, OOJitMixin
class StringTests:
@@ -560,3 +562,17 @@
self.check_loops({
"guard_true": 5, "int_is_true": 3, "int_lt": 2, "int_add": 2, "jump": 2,
}, everywhere=True)
+
+ def test_virtual_copystringcontent(self):
+ jitdriver = JitDriver(reds=['n', 'result'], greens=[])
+ def main(n):
+ result = 0
+ while n >= 0:
+ jitdriver.jit_merge_point(n=n, result=result)
+ b = StringBuilder(6)
+ b.append("Hello!")
+ result += ord(b.build()[0])
+ n -= 1
+ return result
+ res = self.meta_interp(main, [9])
+ assert res == main(9)
\ No newline at end of file
More information about the pypy-commit
mailing list