@@ -317,7 +317,7 @@ def lex_le(self, other):
317317 def lex_lt (self , other ):
318318 return self .timestamp < other .timestamp
319319
320- # NOTE: This is called a lot with the same arguments - memoize yields mild speedup
320+ # Note: memoization yields mild compiler speedup
321321 @memoized_meth
322322 def distance (self , other ):
323323 """
@@ -365,14 +365,21 @@ def distance(self, other):
365365 # Case 1: `sit` is an IterationInterval with statically known
366366 # trip count. E.g. it ranges from 0 to 3; `other` performs a
367367 # constant access at 4
368- for v in (self [n ], other [n ]):
369- try :
370- # NOTE: Split the boolean to make the conditional short circuit
371- # more frequently for mild speedup
372- if bool (v < sit .symbolic_min ) or bool (v > sit .symbolic_max ):
373- return Vector (S .ImaginaryUnit )
374- except TypeError :
375- pass
368+
369+ # To avoid evaluating expensive symbolic Lt or Gt operations,
370+ # we pre-empt such operations by checking if the values to be compared
371+ # to are symbolic, and skip this case if not.
372+ if not any (isinstance (i , sympy .core .Basic )
373+ for i in (sit .symbolic_min , sit .symbolic_max )):
374+
375+ for v in (self [n ], other [n ]):
376+ try :
377+ # Note: Boolean is split to make the conditional short
378+ # circuit more frequently for mild speedup
379+ if bool (v < sit .symbolic_min ) or bool (v > sit .symbolic_max ):
380+ return Vector (S .ImaginaryUnit )
381+ except TypeError :
382+ pass
376383
377384 # Case 2: `sit` is an IterationInterval over a local SubDimension
378385 # and `other` performs a constant access
@@ -1174,7 +1181,6 @@ def d_from_access_gen(self, accesses):
11741181 Generate all flow, anti, and output dependences involving any of
11751182 the given TimedAccess objects.
11761183 """
1177- # FIXME: This seems to be a hotspot
11781184 accesses = as_tuple (accesses )
11791185 for d in self .d_all_gen ():
11801186 for i in accesses :
0 commit comments