From: Ian Romanick Date: Thu, 8 Aug 2019 23:48:14 +0000 (-0700) Subject: nir/algebraic: Clean up value range analysis-based optimizations X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e07248d2a8605c202a292f59c4f44ee3debefc58;p=mesa.git nir/algebraic: Clean up value range analysis-based optimizations Fix the a / b ordering in some compares. Delete duplicate patterns. Add a table explaining things. While I was cleaning this up, I managed to confuse myself. The table helped sort that out. Reviewed-by: Alyssa Rosenzweig Reviewed-by: Caio Marcelo de Oliveira Filho --- diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 3fc35995bca..a94829d9bfb 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -838,31 +838,41 @@ optimizations.extend([ (('fne', 'a(is_not_zero)', 0.0), True), (('feq', 'a(is_not_zero)', 0.0), False), + # In this chart, + means value > 0 and - means value < 0. + # + # + >= + -> unknown 0 >= + -> false - >= + -> false + # + >= 0 -> true 0 >= 0 -> true - >= 0 -> false + # + >= - -> true 0 >= - -> true - >= - -> unknown + # + # Using grouping conceptually similar to a Karnaugh map... + # + # (+ >= 0, + >= -, 0 >= 0, 0 >= -) == (is_not_negative >= is_not_positive) -> true + # (0 >= +, - >= +) == (is_not_positive >= gt_zero) -> false + # (- >= +, - >= 0) == (lt_zero >= is_not_negative) -> false + # + # The flt / ilt cases just invert the expected result. + # # The results expecting true, must be marked imprecise. The results # expecting false are fine because NaN compared >= or < anything is false. (('~fge', 'a(is_not_negative)', 'b(is_not_positive)'), True), - (('fge', 'b(is_not_positive)', 'a(is_gt_zero)'), False), + (('fge', 'a(is_not_positive)', 'b(is_gt_zero)'), False), (('fge', 'a(is_lt_zero)', 'b(is_not_negative)'), False), - (('~fge', 'b(is_not_negative)', 'a(is_not_positive)'), True), (('flt', 'a(is_not_negative)', 'b(is_not_positive)'), False), - (('~flt', 'b(is_not_positive)', 'a(is_gt_zero)'), True), + (('~flt', 'a(is_not_positive)', 'b(is_gt_zero)'), True), (('~flt', 'a(is_lt_zero)', 'b(is_not_negative)'), True), - (('flt', 'b(is_not_negative)', 'a(is_not_positive)'), False), (('ine', 'a(is_not_zero)', 0), True), (('ieq', 'a(is_not_zero)', 0), False), (('ige', 'a(is_not_negative)', 'b(is_not_positive)'), True), - (('ige', 'b(is_not_positive)', 'a(is_gt_zero)'), False), + (('ige', 'a(is_not_positive)', 'b(is_gt_zero)'), False), (('ige', 'a(is_lt_zero)', 'b(is_not_negative)'), False), - (('ige', 'b(is_not_negative)', 'a(is_not_positive)'), True), (('ilt', 'a(is_not_negative)', 'b(is_not_positive)'), False), - (('ilt', 'b(is_not_positive)', 'a(is_gt_zero)'), True), + (('ilt', 'a(is_not_positive)', 'b(is_gt_zero)'), True), (('ilt', 'a(is_lt_zero)', 'b(is_not_negative)'), True), - (('ilt', 'b(is_not_negative)', 'a(is_not_positive)'), False), (('ult', 0, 'a(is_gt_zero)'), True),