Author: Richard Plangger <r...@pasra.at>
Branch: vecopt2
Changeset: r77125:d0777f689686
Date: 2015-04-28 13:11 +0200
http://bitbucket.org/pypy/pypy/changeset/d0777f689686/

Log:    started to implement guard folding. (j=i+1,guard(j),k=j+1,guard(k)
        => j=i+2, guard(j))

diff --git a/rpython/jit/metainterp/optimizeopt/__init__.py 
b/rpython/jit/metainterp/optimizeopt/__init__.py
--- a/rpython/jit/metainterp/optimizeopt/__init__.py
+++ b/rpython/jit/metainterp/optimizeopt/__init__.py
@@ -67,7 +67,8 @@
         loop.logops = metainterp_sd.logger_noopt.log_loop(loop.inputargs,
                                                           loop.operations)
         optimizations, unroll = build_opt_chain(metainterp_sd, enable_opts)
-        if warmstate.vectorize and jitdriver_sd.vectorize:
+
+        if jitdriver_sd.vectorize:
             optimize_vector(metainterp_sd, jitdriver_sd, loop, optimizations)
         elif unroll:
             return optimize_unroll(metainterp_sd, jitdriver_sd, loop,
diff --git a/rpython/jit/metainterp/optimizeopt/vectorize.py 
b/rpython/jit/metainterp/optimizeopt/vectorize.py
--- a/rpython/jit/metainterp/optimizeopt/vectorize.py
+++ b/rpython/jit/metainterp/optimizeopt/vectorize.py
@@ -97,8 +97,6 @@
         self.schedule()
 
     def emit_operation(self, op):
-        if op.getopnum() == rop.GUARD_EARLY_EXIT:
-            return
         self._last_emitted_op = op
         self._newoperations.append(op)
 
@@ -356,10 +354,10 @@
                 self.emit_operation(candidate.getoperation())
                 scheduler.schedule(0)
 
-        self.loop.operations = self._newoperations[:]
         if not we_are_translated():
             for node in self.dependency_graph.nodes:
                 assert node.emitted
+        self.loop.operations = self.collapse_index_guards()
 
     def relax_index_guards(self):
         label_idx = 0
@@ -402,6 +400,27 @@
 
             guard_node.relax_guard_to(self.future_condition)
 
+    def collapse_index_guards(self):
+        final_ops = []
+        last_guard = None
+        is_after_relax = False
+        for op in self._newoperations:
+            if op.getopnum() == rop.GUARD_EARLY_EXIT:
+                assert last_guard is not None
+                final_ops.append(last_guard)
+                is_after_relax = True
+                continue
+            if not is_after_relax:
+                if op.is_guard():
+                    last_guard = op
+                else:
+                    final_ops.append(op)
+            else:
+                final_ops.append(op)
+        assert is_after_relax
+        return final_ops
+
+
 def must_unpack_result_to_exec(op, target_op):
     # TODO either move to resop or util
     if op.getoperation().vector != -1:
diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -464,7 +464,7 @@
     'enable_opts': 'INTERNAL USE ONLY (MAY NOT WORK OR LEAD TO CRASHES): '
                    'optimizations to enable, or all = %s' % ENABLE_ALL_OPTS,
     'max_unroll_recursion': 'how many levels deep to unroll a recursive 
function',
-    'vectorize': 'try to vectorize loops instead of unrolling them. This only 
works if the cpu model has the sse2 instruction set and the jit driver defines 
that there is possibility for unrolling',
+    'vectorize': 'try to vectorize loops instead of unrolling them. This only 
works if the cpu model has the sse2 instruction set. default on',
     }
 
 PARAMETERS = {'threshold': 1039, # just above 1024, prime
@@ -479,7 +479,7 @@
               'max_unroll_loops': 0,
               'enable_opts': 'all',
               'max_unroll_recursion': 7,
-              'vectorize': 0,
+              'vectorize': 1,
               }
 unroll_parameters = unrolling_iterable(PARAMETERS.items())
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to