diff --git a/changelog b/changelog index 33d7c06f0f..5069a2ec37 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ + 38) PR #3311 for #3310. Small optimisation to the dependence-analysis + functionality for array indices consisting of simple References. + 37) PR #3295 for #3292. Add command-line flag to permit config-file settings to be overridden and extend possible settings for the runtime warnings option. diff --git a/src/psyclone/psyir/tools/dependency_tools.py b/src/psyclone/psyir/tools/dependency_tools.py index c9571c5b2f..7cf69bcbfb 100644 --- a/src/psyclone/psyir/tools/dependency_tools.py +++ b/src/psyclone/psyir/tools/dependency_tools.py @@ -48,7 +48,7 @@ from psyclone.errors import InternalError, LazyString from psyclone.psyir.backend.sympy_writer import SymPyWriter from psyclone.psyir.backend.visitor import VisitorError -from psyclone.psyir.nodes import Loop, Node, Range +from psyclone.psyir.nodes import Loop, Node, Range, Reference # pylint: disable=too-many-lines @@ -657,7 +657,21 @@ def _is_loop_carried_dependency(self, loop_variables, write_access, return True elif len(set_of_vars) == 1: # One loop variable used in both accesses. - # E.g. `a(2*i+3) = a(i*i)` + # E.g. `a(2*i+3) = a(i*i)`. Add a shortcut for + # a very common case - the index is a simple reference + if (isinstance(index_write, Reference) and + isinstance(index_other, Reference) and + index_write == index_other): + if index_write.name == loop_var: + # a(j, ...) and a(j, ...) - these accesses + # will never overlap for different j, independent + # of the expressions in the other dimensions + return True + # The expression does not depend on the loop variable + # at all (dependency distance would return None), + # again no need for an explicit test, we can continue + # the outer loop + continue distance = self._get_dependency_distance(loop_var, index_write, index_other)