intel/mi_builder: Short-circuit shifts in more cases
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 18 Feb 2021 15:34:34 +0000 (09:34 -0600)
committerMarge Bot <eric+marge@anholt.net>
Thu, 18 Feb 2021 21:28:40 +0000 (21:28 +0000)
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9116>

src/intel/common/gen_mi_builder.h

index 79a1679..98e547c 100644 (file)
@@ -855,6 +855,12 @@ static inline struct gen_mi_value
 gen_mi_ishl_imm(struct gen_mi_builder *b,
                 struct gen_mi_value src, uint32_t shift)
 {
+   if (shift == 0)
+      return src;
+
+   if (shift >= 64)
+      return gen_mi_imm(0);
+
    struct gen_mi_value res = gen_mi_value_to_gpr(b, src);
 
    for (unsigned i = 0; i < shift; i++)
@@ -867,10 +873,13 @@ static inline struct gen_mi_value
 gen_mi_ushr32_imm(struct gen_mi_builder *b,
                   struct gen_mi_value src, uint32_t shift)
 {
+   if (shift == 0)
+      return src;
+
    /* We right-shift by left-shifting by 32 - shift and taking the top 32 bits
     * of the result.
     */
-   if (shift > 64)
+   if (shift >= 64)
       return gen_mi_imm(0);
 
    if (shift > 32) {