From 476009959074d6e187fc056cd051e91bd1a6ea8d Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Sun, 20 Sep 2015 14:10:55 -0500 Subject: [PATCH] Don't count (-1) * as a flop --- loopy/statistics.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/loopy/statistics.py b/loopy/statistics.py index 1d882ce88..7b7289931 100755 --- a/loopy/statistics.py +++ b/loopy/statistics.py @@ -126,7 +126,23 @@ class ExpressionOpCounter(CombineMapper): else: return ToCountMap() - map_product = map_sum + def map_product(self, expr): + from pymbolic.primitives import is_zero + if expr.children: + return ToCountMap( + {self.type_inf(expr): len(expr.children)-1} + ) + sum( + self.rec(child) + for child in expr.children + + # Do not count '(-1)* ' (as produced by + # subtraction in pymbolic): Assume this + # gets implemented as a sign flip or + # as subtraction. (Confirmed to be true on + # at least Nvidia 352.30.) + if not is_zero(child - 1)) + else: + return ToCountMap() def map_quotient(self, expr, *args): return ToCountMap({self.type_inf(expr): 1}) \ -- GitLab