[pypy-commit] pypy default: Test and fix: the test (s == "") was optimized by incorrectly assuming
arigo
noreply at buildbot.pypy.org
Tue May 26 17:04:03 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r77585:f883c1d60693
Date: 2015-05-26 17:04 +0200
http://bitbucket.org/pypy/pypy/changeset/f883c1d60693/
Log: Test and fix: the test (s == "") was optimized by incorrectly
assuming that s is not None
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -4614,6 +4614,58 @@
"""
self.optimize_strunicode_loop_extradescrs(ops, expected)
+ def test_str_equal_none3(self):
+ ops = """
+ []
+ p5 = newstr(0)
+ i0 = call(0, NULL, p5, descr=strequaldescr)
+ escape(i0)
+ jump()
+ """
+ expected = """
+ []
+ escape(0)
+ jump()
+ """
+ self.optimize_strunicode_loop_extradescrs(ops, expected)
+
+ def test_str_equal_none4(self):
+ ops = """
+ [p1]
+ p5 = newstr(0)
+ i0 = call(0, p5, p1, descr=strequaldescr)
+ escape(i0)
+ jump(p1)
+ """
+ expected = """
+ [p1]
+ # can't optimize more: p1 may be NULL!
+ i0 = call(0, s"", p1, descr=strequaldescr)
+ escape(i0)
+ jump(p1)
+ """
+ self.optimize_strunicode_loop_extradescrs(ops, expected)
+
+ def test_str_equal_none5(self):
+ ops = """
+ [p1]
+ guard_nonnull(p1) []
+ p5 = newstr(0)
+ i0 = call(0, p5, p1, descr=strequaldescr)
+ escape(i0)
+ jump(p1)
+ """
+ expected = """
+ [p1]
+ guard_nonnull(p1) []
+ # p1 is not NULL, so the string comparison (p1=="") becomes:
+ i6 = strlen(p1)
+ i0 = int_eq(i6, 0)
+ escape(i0)
+ jump(p1)
+ """
+ self.optimize_strunicode_loop_extradescrs(ops, expected)
+
def test_str_equal_nonnull1(self):
ops = """
[p1]
diff --git a/rpython/jit/metainterp/optimizeopt/vstring.py b/rpython/jit/metainterp/optimizeopt/vstring.py
--- a/rpython/jit/metainterp/optimizeopt/vstring.py
+++ b/rpython/jit/metainterp/optimizeopt/vstring.py
@@ -667,10 +667,15 @@
l2box = v2.getstrlen(None, mode, None)
if isinstance(l2box, ConstInt):
if l2box.value == 0:
- lengthbox = v1.getstrlen(self, mode, None)
- seo = self.optimizer.send_extra_operation
- seo(ResOperation(rop.INT_EQ, [lengthbox, CONST_0], resultbox))
- return True
+ if v1.is_nonnull():
+ lengthbox = v1.getstrlen(self, mode, None)
+ else:
+ lengthbox = v1.getstrlen(None, mode, None)
+ if lengthbox is not None:
+ seo = self.optimizer.send_extra_operation
+ seo(ResOperation(rop.INT_EQ, [lengthbox, CONST_0],
+ resultbox))
+ return True
if l2box.value == 1:
l1box = v1.getstrlen(None, mode, None)
if isinstance(l1box, ConstInt) and l1box.value == 1:
More information about the pypy-commit
mailing list