Module: Mesa
Branch: main
Commit: 49177b9e2fc2358176e465f4cf929f41a09a3c2f
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=49177b9e2fc2358176e465f4cf929f41a09a3c2f

Author: Ian Romanick <[email protected]>
Date:   Fri Feb 26 07:12:42 2021 -0800

nir/algebraic: Tautology replacements require sources be numbers

It seems worth the small amount of damage to give an extra cushion of
not having to debug problems later.

Reviewed-by: Rhys Perry <[email protected]>

All Intel platforms had similar results. (Tiger Lake shown)
total instructions in shared programs: 21043197 -> 21043359 (<.01%)
instructions in affected programs: 4409 -> 4571 (3.67%)
helped: 0
HURT: 25
HURT stats (abs)   min: 1 max: 16 x̄: 6.48 x̃: 5
HURT stats (rel)   min: 0.39% max: 15.38% x̄: 4.59% x̃: 4.40%
95% mean confidence interval for instructions value: 4.37 8.59
95% mean confidence interval for instructions %-change: 2.93% 6.26%
Instructions are HURT.

total cycles in shared programs: 856175986 -> 856176921 (<.01%)
cycles in affected programs: 58908 -> 59843 (1.59%)
helped: 0
HURT: 25
HURT stats (abs)   min: 7 max: 70 x̄: 37.40 x̃: 38
HURT stats (rel)   min: 0.27% max: 5.63% x̄: 1.87% x̃: 1.39%
95% mean confidence interval for cycles value: 31.11 43.69
95% mean confidence interval for cycles %-change: 1.35% 2.39%
Cycles are HURT.

No fossil-db changes on any Intel platform.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10012>

---

 src/compiler/nir/nir_opt_algebraic.py | 12 +++++------
 src/compiler/nir/nir_search_helpers.h | 40 +++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/src/compiler/nir/nir_opt_algebraic.py 
b/src/compiler/nir/nir_opt_algebraic.py
index 7e6136fbe88..75987e3cc58 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -1177,13 +1177,13 @@ optimizations.extend([
    # 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',  'a(is_not_positive)', 'b(is_gt_zero)'),      False),
-   (('fge',  'a(is_lt_zero)',      'b(is_not_negative)'), False),
+   (('fge', 'a(is_a_number_not_negative)', 'b(is_a_number_not_positive)'), 
True),
+   (('fge', 'a(is_not_positive)',          'b(is_gt_zero)'),               
False),
+   (('fge', 'a(is_lt_zero)',               'b(is_not_negative)'),          
False),
 
-   (('flt',  'a(is_not_negative)', 'b(is_not_positive)'), False),
-   (('~flt', 'a(is_not_positive)', 'b(is_gt_zero)'),      True),
-   (('~flt', 'a(is_lt_zero)',      'b(is_not_negative)'), True),
+   (('flt', 'a(is_not_negative)',          'b(is_not_positive)'),          
False),
+   (('flt', 'a(is_a_number_not_positive)', 'b(is_a_number_gt_zero)'),      
True),
+   (('flt', 'a(is_a_number_lt_zero)',      'b(is_a_number_not_negative)'), 
True),
 
    (('ine', 'a(is_not_zero)', 0), True),
    (('ieq', 'a(is_not_zero)', 0), False),
diff --git a/src/compiler/nir/nir_search_helpers.h 
b/src/compiler/nir/nir_search_helpers.h
index cae9ef4f0bd..a49b1edaa41 100644
--- a/src/compiler/nir/nir_search_helpers.h
+++ b/src/compiler/nir/nir_search_helpers.h
@@ -442,6 +442,15 @@ is_ ## r (struct hash_table *ht, const nir_alu_instr 
*instr,            \
 {                                                                       \
    const struct ssa_result_range v = nir_analyze_range(ht, instr, src);  \
    return v.range == r;                                                 \
+}                                                                       \
+                                                                        \
+static inline bool                                                      \
+is_a_number_ ## r (struct hash_table *ht, const nir_alu_instr *instr,   \
+                   unsigned src, UNUSED unsigned num_components,        \
+                   UNUSED const uint8_t *swizzle)                       \
+{                                                                       \
+   const struct ssa_result_range v = nir_analyze_range(ht, instr, src); \
+   return v.is_a_number && v.range == r;                                \
 }
 
 RELATION(lt_zero)
@@ -458,6 +467,17 @@ is_not_negative(struct hash_table *ht, const nir_alu_instr 
*instr, unsigned src,
    return v.range == ge_zero || v.range == gt_zero || v.range == eq_zero;
 }
 
+static inline bool
+is_a_number_not_negative(struct hash_table *ht, const nir_alu_instr *instr,
+                         unsigned src, UNUSED unsigned num_components,
+                         UNUSED const uint8_t *swizzle)
+{
+   const struct ssa_result_range v = nir_analyze_range(ht, instr, src);
+   return v.is_a_number &&
+          (v.range == ge_zero || v.range == gt_zero || v.range == eq_zero);
+}
+
+
 static inline bool
 is_not_positive(struct hash_table *ht, const nir_alu_instr *instr, unsigned 
src,
                 UNUSED unsigned num_components, UNUSED const uint8_t *swizzle)
@@ -466,6 +486,16 @@ is_not_positive(struct hash_table *ht, const nir_alu_instr 
*instr, unsigned src,
    return v.range == le_zero || v.range == lt_zero || v.range == eq_zero;
 }
 
+static inline bool
+is_a_number_not_positive(struct hash_table *ht, const nir_alu_instr *instr,
+                         unsigned src, UNUSED unsigned num_components,
+                         UNUSED const uint8_t *swizzle)
+{
+   const struct ssa_result_range v = nir_analyze_range(ht, instr, src);
+   return v.is_a_number &&
+          (v.range == le_zero || v.range == lt_zero || v.range == eq_zero);
+}
+
 static inline bool
 is_not_zero(struct hash_table *ht, const nir_alu_instr *instr, unsigned src,
             UNUSED unsigned num_components, UNUSED const uint8_t *swizzle)
@@ -474,6 +504,16 @@ is_not_zero(struct hash_table *ht, const nir_alu_instr 
*instr, unsigned src,
    return v.range == lt_zero || v.range == gt_zero || v.range == ne_zero;
 }
 
+static inline bool
+is_a_number_not_zero(struct hash_table *ht, const nir_alu_instr *instr,
+                     unsigned src, UNUSED unsigned num_components,
+                     UNUSED const uint8_t *swizzle)
+{
+   const struct ssa_result_range v = nir_analyze_range(ht, instr, src);
+   return v.is_a_number &&
+          (v.range == lt_zero || v.range == gt_zero || v.range == ne_zero);
+}
+
 static inline bool
 is_a_number(struct hash_table *ht, const nir_alu_instr *instr, unsigned src,
             UNUSED unsigned num_components, UNUSED const uint8_t *swizzle)

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to