aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Friedrich Bolz-Tereick <cfbolz@gmx.de>2021-02-04 13:44:54 +0100
committerCarl Friedrich Bolz-Tereick <cfbolz@gmx.de>2021-02-04 13:44:54 +0100
commit2a1c7a8226d819e902d3db071ffb90c6a70ac13b (patch)
tree6bb33b6da861e7250b1f29affcd55dee12d4693a
parentuse low-level interface where applicable, add at least a minimal hypothesis t... (diff)
downloadpypy-2a1c7a8226d819e902d3db071ffb90c6a70ac13b.tar.gz
pypy-2a1c7a8226d819e902d3db071ffb90c6a70ac13b.tar.bz2
pypy-2a1c7a8226d819e902d3db071ffb90c6a70ac13b.zip
call more appropriate methods a bit everywhere
-rw-r--r--rpython/jit/metainterp/optimizeopt/intbounds.py76
-rw-r--r--rpython/jit/metainterp/optimizeopt/intutils.py15
-rw-r--r--rpython/jit/metainterp/optimizeopt/rewrite.py12
3 files changed, 45 insertions, 58 deletions
diff --git a/rpython/jit/metainterp/optimizeopt/intbounds.py b/rpython/jit/metainterp/optimizeopt/intbounds.py
index a9445a5f8e..f19989c52d 100644
--- a/rpython/jit/metainterp/optimizeopt/intbounds.py
+++ b/rpython/jit/metainterp/optimizeopt/intbounds.py
@@ -223,7 +223,7 @@ class OptIntBounds(Optimization):
b1 = self.getintbound(op.getarg(0))
b2 = self.getintbound(op.getarg(1))
b = b1.rshift_bound(b2)
- if b.has_lower and b.has_upper and b.lower == b.upper:
+ if b.is_constant():
# constant result (likely 0, for rshifts that kill all bits)
self.make_constant_int(op, b.lower)
return None
@@ -489,9 +489,8 @@ class OptIntBounds(Optimization):
numbits = op.getarg(1).getint() * 8
start = -(1 << (numbits - 1))
stop = 1 << (numbits - 1)
- bounds = IntBound(start, stop - 1)
bres = self.getintbound(op)
- bres.intersect(bounds)
+ bres.intersect_const(start, stop - 1)
def optimize_ARRAYLEN_GC(self, op):
return self.emit(op)
@@ -523,12 +522,11 @@ class OptIntBounds(Optimization):
v1 = self.getintbound(op)
v2 = getptrinfo(op.getarg(0))
intbound = self.getintbound(op.getarg(1))
- if (intbound.has_lower and v2 is not None and
- v2.getlenbound(vstring.mode_string) is not None):
- lb = IntLowerBound(intbound.lower + 1)
- v2.getlenbound(vstring.mode_string).make_ge(lb)
- v1.make_ge(IntLowerBound(0))
- v1.make_lt(IntUpperBound(256))
+ if intbound.has_lower and v2 is not None:
+ lenbound = v2.getlenbound(vstring.mode_string)
+ if lenbound is not None:
+ lenbound.make_gt_const(intbound.lower)
+ v1.intersect_const(0, 255)
def optimize_GETFIELD_RAW_I(self, op):
return self.emit(op)
@@ -537,8 +535,7 @@ class OptIntBounds(Optimization):
descr = op.getdescr()
if descr.is_integer_bounded():
b1 = self.getintbound(op)
- b1.make_ge(IntLowerBound(descr.get_integer_min()))
- b1.make_le(IntUpperBound(descr.get_integer_max()))
+ b1.intersect_const(descr.get_integer_min(), descr.get_integer_max())
optimize_GETFIELD_RAW_F = optimize_GETFIELD_RAW_I
optimize_GETFIELD_RAW_R = optimize_GETFIELD_RAW_I
@@ -567,8 +564,7 @@ class OptIntBounds(Optimization):
descr = op.getdescr()
if descr and descr.is_item_integer_bounded():
intbound = self.getintbound(op)
- intbound.make_ge(IntLowerBound(descr.get_item_integer_min()))
- intbound.make_le(IntUpperBound(descr.get_item_integer_max()))
+ intbound.intersect_const(descr.get_item_integer_min(), descr.get_item_integer_max())
optimize_GETARRAYITEM_RAW_F = optimize_GETARRAYITEM_RAW_I
optimize_GETARRAYITEM_GC_I = optimize_GETARRAYITEM_RAW_I
@@ -585,13 +581,13 @@ class OptIntBounds(Optimization):
def postprocess_UNICODEGETITEM(self, op):
b1 = self.getintbound(op)
- b1.make_ge(IntLowerBound(0))
+ b1.make_ge_const(0)
v2 = getptrinfo(op.getarg(0))
intbound = self.getintbound(op.getarg(1))
- if (intbound.has_lower and v2 is not None and
- v2.getlenbound(vstring.mode_unicode) is not None):
- lb = IntLowerBound(intbound.lower + 1)
- v2.getlenbound(vstring.mode_unicode).make_ge(lb)
+ if intbound.has_lower and v2 is not None:
+ lenbound = v2.getlenbound(vstring.mode_unicode)
+ if lenbound is not None:
+ lenbound.make_gt_const(intbound.lower)
def make_int_lt(self, box1, box2):
b1 = self.getintbound(box1)
@@ -655,7 +651,7 @@ class OptIntBounds(Optimization):
b2 = self.getintbound(box2)
if b2.known_nonnegative:
b1 = self.getintbound(box1)
- if b1.make_lt(b2) | b1.make_ge(IntBound(0, 0)):
+ if b1.make_lt(b2) | b1.make_ge_const(0):
self.propagate_bounds_backward(box1)
#if b2.make_gt(b1):
# ^^ probably correct but I fail to see a case where it is helpful
@@ -666,7 +662,7 @@ class OptIntBounds(Optimization):
b2 = self.getintbound(box2)
if b2.known_nonnegative:
b1 = self.getintbound(box1)
- if b1.make_le(b2) | b1.make_ge(IntBound(0, 0)):
+ if b1.make_le(b2) | b1.make_ge_const(0):
self.propagate_bounds_backward(box1)
#if b2.make_ge(b1):
# ^^ probably correct but I fail to see a case where it is helpful
@@ -718,25 +714,23 @@ class OptIntBounds(Optimization):
def propagate_bounds_INT_EQ(self, op):
r = self.getintbound(op)
- if r.is_constant():
- if r.equal(1):
- b1 = self.getintbound(op.getarg(0))
- b2 = self.getintbound(op.getarg(1))
- if b1.intersect(b2):
- self.propagate_bounds_backward(op.getarg(0))
- if b2.intersect(b1):
- self.propagate_bounds_backward(op.getarg(1))
+ if r.equal(1):
+ b1 = self.getintbound(op.getarg(0))
+ b2 = self.getintbound(op.getarg(1))
+ if b1.intersect(b2):
+ self.propagate_bounds_backward(op.getarg(0))
+ if b2.intersect(b1):
+ self.propagate_bounds_backward(op.getarg(1))
def propagate_bounds_INT_NE(self, op):
r = self.getintbound(op)
- if r.is_constant():
- if r.equal(0):
- b1 = self.getintbound(op.getarg(0))
- b2 = self.getintbound(op.getarg(1))
- if b1.intersect(b2):
- self.propagate_bounds_backward(op.getarg(0))
- if b2.intersect(b1):
- self.propagate_bounds_backward(op.getarg(1))
+ if r.equal(0):
+ b1 = self.getintbound(op.getarg(0))
+ b2 = self.getintbound(op.getarg(1))
+ if b1.intersect(b2):
+ self.propagate_bounds_backward(op.getarg(0))
+ if b2.intersect(b1):
+ self.propagate_bounds_backward(op.getarg(1))
def _propagate_int_is_true_or_zero(self, op, valnonzero, valzero):
if self.is_raw_ptr(op.getarg(0)):
@@ -746,16 +740,10 @@ class OptIntBounds(Optimization):
if r.getint() == valnonzero:
b1 = self.getintbound(op.getarg(0))
if b1.known_nonnegative():
- b1.make_gt(IntBound(0, 0))
+ b1.make_gt_const(0)
self.propagate_bounds_backward(op.getarg(0))
elif r.getint() == valzero:
- b1 = self.getintbound(op.getarg(0))
- # XXX remove this hack maybe?
- # Clever hack, we can't use self.make_constant_int yet because
- # the args aren't in the values dictionary yet so it runs into
- # an assert, this is a clever way of expressing the same thing.
- b1.make_ge(IntBound(0, 0))
- b1.make_lt(IntBound(1, 1))
+ self.make_constant_int(op.getarg(0), 0)
self.propagate_bounds_backward(op.getarg(0))
def propagate_bounds_INT_IS_TRUE(self, op):
diff --git a/rpython/jit/metainterp/optimizeopt/intutils.py b/rpython/jit/metainterp/optimizeopt/intutils.py
index 2590aad376..9ce1c14393 100644
--- a/rpython/jit/metainterp/optimizeopt/intutils.py
+++ b/rpython/jit/metainterp/optimizeopt/intutils.py
@@ -130,19 +130,18 @@ class IntBound(AbstractInfo):
def intersect(self, other):
r = False
-
if other.has_lower:
- if other.lower > self.lower or not self.has_lower:
- self.lower = other.lower
- self.has_lower = True
+ if self.make_ge_const(other.lower):
r = True
-
if other.has_upper:
- if other.upper < self.upper or not self.has_upper:
- self.upper = other.upper
- self.has_upper = True
+ if self.make_le_const(other.upper):
r = True
+ return r
+ def intersect_const(self, lower, upper):
+ r = self.make_ge_const(lower)
+ if self.make_le_const(upper):
+ r = True
return r
def add(self, offset):
diff --git a/rpython/jit/metainterp/optimizeopt/rewrite.py b/rpython/jit/metainterp/optimizeopt/rewrite.py
index 47b88dbfdf..bef3c84142 100644
--- a/rpython/jit/metainterp/optimizeopt/rewrite.py
+++ b/rpython/jit/metainterp/optimizeopt/rewrite.py
@@ -239,9 +239,9 @@ class OptRewrite(Optimization):
b1 = self.getintbound(op.getarg(0))
b2 = self.getintbound(op.getarg(1))
- if b2.is_constant() and b2.getint() == 0:
+ if b2.equal(0):
self.make_equal_to(op, op.getarg(0))
- elif b1.is_constant() and b1.getint() == 0:
+ elif b1.equal(0):
self.make_constant_int(op, 0)
else:
return self.emit(op)
@@ -250,9 +250,9 @@ class OptRewrite(Optimization):
b1 = self.getintbound(op.getarg(0))
b2 = self.getintbound(op.getarg(1))
- if b2.is_constant() and b2.getint() == 0:
+ if b2.equal(0):
self.make_equal_to(op, op.getarg(0))
- elif b1.is_constant() and b1.getint() == 0:
+ elif b1.equal(0):
self.make_constant_int(op, 0)
else:
return self.emit(op)
@@ -837,7 +837,7 @@ class OptRewrite(Optimization):
arg2 = op.getarg(2)
b2 = self.getintbound(arg2)
- if b1.is_constant() and b1.getint() == 0:
+ if b1.equal(0):
self.make_constant_int(op, 0)
self.last_emitted_operation = REMOVED
return True
@@ -873,7 +873,7 @@ class OptRewrite(Optimization):
arg2 = op.getarg(2)
b2 = self.getintbound(arg2)
- if b1.is_constant() and b1.getint() == 0:
+ if b1.equal(0):
self.make_constant_int(op, 0)
self.last_emitted_operation = REMOVED
return True