Author: Richard Plangger <r...@pasra.at>
Branch: vecopt-merge
Changeset: r79259:d95ae9b7cad9
Date: 2015-08-27 16:34 +0200
http://bitbucket.org/pypy/pypy/changeset/d95ae9b7cad9/

Log:    loop versioning needed to changes the failargs for stitched bridges
        -> thus tests needed adaption further testing memory ref
        adjacent_to, adjacent_after and alias work correctly

diff --git a/rpython/jit/metainterp/optimizeopt/dependency.py 
b/rpython/jit/metainterp/optimizeopt/dependency.py
--- a/rpython/jit/metainterp/optimizeopt/dependency.py
+++ b/rpython/jit/metainterp/optimizeopt/dependency.py
@@ -449,7 +449,7 @@
                     while i >= 0:
                         def_node = def_chain[i][0]
                         oref = def_node.memory_ref
-                        if oref is not None and mref.indices_can_alias(oref):
+                        if oref is not None and mref.alias(oref):
                             return def_node
                         elif oref is None:
                             return def_node
@@ -968,17 +968,10 @@
                self.coefficient_div == 1 and \
                self.constant == 0
 
-    def __eq__(self, other):
+    def less(self, other):
+        # TODO
         if self.same_variable(other):
-            return self.diff(other) == 0
-        return False
-
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def less(self, other):
-        if self.same_variable(other):
-            return self.diff(other) < 0
+            return self.constant_diff(other) < 0
         return False
 
     def clone(self):
@@ -990,14 +983,26 @@
 
     def same_variable(self, other):
         assert isinstance(other, IndexVar)
-        return other.var is self.var
+        return other.var == self.var
 
-    def diff(self, other):
+    def same_mulfactor(self, other):
+        coeff = self.coefficient_mul == other.coefficient_mul
+        coeff = coeff and (self.coefficient_div == other.coefficient_div)
+        if not coeff:
+            # if not equal, try to check if they divide without rest
+            selfmod = self.coefficient_mul % self.coefficient_div
+            othermod = other.coefficient_mul % other.coefficient_div
+            if selfmod == 0 and othermod == 0:
+                # yet another chance for them to be equal
+                selfdiv = self.coefficient_mul // self.coefficient_div
+                otherdiv = other.coefficient_mul // other.coefficient_div
+                coeff = selfdiv == otherdiv
+        return coeff
+
+    def constant_diff(self, other):
         """ calculates the difference as a second parameter """
         assert isinstance(other, IndexVar)
-        mycoeff = self.coefficient_mul // self.coefficient_div
-        othercoeff = other.coefficient_mul // other.coefficient_div
-        return mycoeff + self.constant - (othercoeff + other.constant)
+        return self.constant - other.constant
 
     def emit_operations(self, opt, result_box=None):
         box = self.var
@@ -1029,7 +1034,7 @@
         return box
 
     def compare(self, other):
-        """ returns if the two are compareable as a first result
+        """ Returns if the two are compareable as a first result
             and a number (-1,0,1) of the ordering
         """
         coeff = self.coefficient_mul == other.coefficient_mul
@@ -1056,6 +1061,16 @@
             return True, c
         return False, 0
 
+    def __eq__(self, other):
+        if not self.same_variable(other):
+            return False
+        if not self.same_mulfactor(other):
+            return False
+        return self.constant_diff(other) == 0
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
     def __repr__(self):
         if self.is_identity():
             return 'IndexVar(%s+%s)' % (self.var, repr(self.next_nonconst))
@@ -1083,16 +1098,58 @@
 
     def is_adjacent_to(self, other):
         """ this is a symmetric relation """
+        if not self.same_array(other):
+            return False
+        if not self.index_var.same_variable(other.index_var):
+            return False
+        if not self.index_var.same_mulfactor(other.index_var):
+            return False
         stride = self.stride()
-        if self.match(other):
-            return abs(self.index_var.diff(other.index_var)) - stride == 0
-        return False
+        return abs(self.index_var.constant_diff(other.index_var)) - stride == 0
 
-    def match(self, other):
-        assert isinstance(other, MemoryRef)
-        if self.array == other.array and self.descr == other.descr:
-            return self.index_var.same_variable(other.index_var)
-        return False
+    def is_adjacent_after(self, other):
+        """ the asymetric relation to is_adjacent_to """
+        if not self.same_array(other):
+            return False
+        if not self.index_var.same_variable(other.index_var):
+            return False
+        if not self.index_var.same_mulfactor(other.index_var):
+            return False
+        stride = self.stride()
+        return other.index_var.constant_diff(self.index_var) == stride
+
+    def alias(self, other):
+        """ is this reference an alias to other?
+            they can alias iff self.origin != other.origin, or their
+            linear combination point to the same element.
+        """
+        assert other is not None
+        if not self.same_array(other):
+            return False
+        svar = self.index_var
+        ovar = other.index_var
+        if not svar.same_variable(ovar):
+            return True
+        if not svar.same_mulfactor(ovar):
+            return True
+        return abs(svar.constant_diff(ovar)) < self.stride()
+
+    def same_array(self, other):
+        return self.array is other.array and self.descr == other.descr
+
+    def __eq__(self, other):
+        """ NOT_RPYTHON """
+        if not self.same_array(other):
+            return False
+        if not self.index_var.same_variable(other.index_var):
+            return False
+        if not self.index_var.same_mulfactor(other.index_var):
+            return False
+        stride = self.stride()
+        return other.index_var.constant_diff(self.index_var) == 0
+
+    #def __ne__(self, other):
+    #    return not self.__eq__(other)
 
     def stride(self):
         """ the stride in bytes """
@@ -1100,34 +1157,5 @@
             return 1
         return self.descr.get_item_size_in_bytes()
 
-    def is_adjacent_after(self, other):
-        """ the asymetric relation to is_adjacent_to """
-        stride = self.stride()
-        if self.match(other):
-            return other.index_var.diff(self.index_var) == stride
-        return False
-
-    def indices_can_alias(self, other):
-        """ can to array indices alias? they can alias iff 
-        self.origin != other.origin, or their
-        linear combination point to the same element.
-        """
-        assert other is not None
-        if not self.index_var.same_variable(other.index_var):
-            return True
-        stride = self.stride()
-        if self.match(other):
-            diff = self.index_var.diff(other.index_var)
-            return abs(diff) < stride
-        return False
-
-    def __eq__(self, other):
-        if self.match(other):
-            return self.index_var.diff(other.index_var) == 0
-        return False
-
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
     def __repr__(self):
         return 'MemRef(%s,%s)' % (self.array, self.index_var)
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_dependency.py 
b/rpython/jit/metainterp/optimizeopt/test/test_dependency.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_dependency.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_dependency.py
@@ -137,7 +137,7 @@
         assert i.is_identity()
         assert not i.less(j)
         assert i.same_variable(j)
-        assert i.diff(j) == 0
+        assert i.constant_diff(j) == 0
 
     def test_index_var_diff(self):
         b = FakeBox()
@@ -145,31 +145,41 @@
         j = IndexVar(b,1,1,1)
         assert not i.is_identity()
         assert not j.is_identity()
-        assert i.diff(j) == 1
+        assert not i.same_mulfactor(j)
+        assert i.constant_diff(j) == -1
 
     def test_memoryref_basic(self):
         i = FakeBox()
         a = FakeBox()
         m1 = memoryref(a, i, (1,1,0))
         m2 = memoryref(a, i, (1,1,0))
-        assert m1.match(m2)
+        assert m1.alias(m2)
 
-    @py.test.mark.parametrize('coeff1,coeff2,adja,alias',
-            [((1,1,0), (1,1,0), False, True),
-             ((4,2,0), (8,4,0), False, True),
-             ((4,2,0), (8,2,0), False, True),
-             ((4,2,1), (8,4,0), True, False),
+    @py.test.mark.parametrize('coeff1,coeff2,state',
+            #                    +------------------ adjacent
+            #                    |+----------------- adjacent_after
+            #                    ||+---------------- adjacent_befure
+            #                    |||+--------------- alias
+            #                    ||||
+            [((1,1,0), (1,1,0), 'ffft'),
+             ((4,2,0), (8,4,0), 'ffft'),
+             ((4,2,0), (8,2,0), 'ffft'),
+             ((4,2,1), (8,4,0), 'tftf'),
             ])
-    def test_memoryref_adjacent_alias(self, coeff1,
-                                      coeff2, adja,
-                                      alias):
+    def test_memoryref_adjacent_alias(self, coeff1, coeff2, state):
         i = FakeBox()
         a = FakeBox()
         m1 = memoryref(a, i, coeff1)
         m2 = memoryref(a, i, coeff2)
-        assert m1.is_adjacent_after(m2) == adja
-        assert m2.is_adjacent_after(m1) == adja
-        assert m1.indices_can_alias(m2) == alias
+        adja = state[0] == 't'
+        adja_after = state[1] == 't'
+        adja_before = state[2] == 't'
+        alias = state[3] == 't'
+        assert m1.is_adjacent_to(m2) == adja
+        assert m2.is_adjacent_to(m1) == adja
+        assert m1.is_adjacent_after(m2) == adja_after
+        assert m2.is_adjacent_after(m1) == adja_before
+        assert m1.alias(m2) == alias
 
     def test_dependency_empty(self):
         ops = """
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_guard.py 
b/rpython/jit/metainterp/optimizeopt/test/test_guard.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_guard.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_guard.py
@@ -80,6 +80,7 @@
 
 class GuardBaseTest(SchedulerBaseTest):
     def optguards(self, loop, user_code=False):
+        loop.snapshot()
         for op in loop.operations:
             if op.is_guard():
                 op.setdescr(compile.CompileLoopVersionDescr())
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_vectorize.py 
b/rpython/jit/metainterp/optimizeopt/test/test_vectorize.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_vectorize.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_vectorize.py
@@ -76,6 +76,7 @@
         return opt
 
     def vectoroptimizer_unrolled(self, loop, unroll_factor = -1):
+        loop.snapshot()
         opt = self.vectoroptimizer(loop)
         opt.linear_find_smallest_type(loop)
         if unroll_factor == -1 and opt.smallest_type_bytes == 0:
@@ -1024,7 +1025,7 @@
         i30 = int_lt(i20, 10)
         i2 = int_add(i0, 2)
         i3 = int_lt(i2, 10)
-        guard_true(i3) [p0,i0]
+        guard_true(i3) [p0,i0,f3]
         i4 = int_add(i0, 2)
         i5 = int_lt(i2, 10)
         v1 = vec_getarrayitem_raw(p0, i0, 2, descr=floatarraydescr)
@@ -1090,7 +1091,7 @@
         i52 = int_ge(i50, i18) 
         i637 = int_add(i28, 2)
         i638 = int_ge(i637, i18)
-        guard_false(i638) [p38, p12, p9, p14, p39, i37, i44, f35, i40, p42, 
i43, f34, i28, p36, i41]
+        guard_false(i638) [p36, i28, p9, i37, p14, f34, p12, p38, f35, p39, 
i40, i41, p42, i43, i44, i21, i4, i0, i18]
         i55 = int_add(i44, 16) 
         i629 = int_add(i28, 2)
         i57 = int_ge(i637, i18) 
@@ -1123,7 +1124,7 @@
         i4 = int_ge(i3, 36)
         i50 = int_add(i1, 4)
         i51 = int_ge(i50, 36)
-        guard_false(i51) []
+        guard_false(i51) [p0, p1, i1]
         i5 = int_add(i1, 2)
         i8 = int_ge(i5, 36)
         i6 = int_add(i1, 3)
@@ -1165,7 +1166,7 @@
         i186 = int_lt(i5, 100)
         i500 = int_add(i4, 16)
         i501 = int_lt(i500, 100)
-        guard_true(i501) []
+        guard_true(i501) [p0, p1, p2, i0, i4]
         i189 = int_add(i0, 8)
         i187 = int_add(i4, 8)
         i198 = int_add(i0, 12)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to