bifrost: Lower x->bool conversions to != 0
[mesa.git] / src / panfrost / bifrost / bir.c
index 3c5ad9bf71b90af751ff3ed07e13ace758caa792..3ca57f66f0efde5a939f8049eea96e633f000520 100644 (file)
@@ -38,14 +38,15 @@ bi_has_outmod(bi_instruction *ins)
         return classy && floaty;
 }
 
-/* Technically we should check the source type, not the dest
- * type, but the type converting opcodes (i2f, f2i) don't
- * actually support mods so it doesn't matter. */
+/* Have to check source for e.g. compares */
 
 bool
 bi_has_source_mods(bi_instruction *ins)
 {
-        return bi_has_outmod(ins);
+        bool classy = bi_class_props[ins->type] & BI_MODS;
+        bool floaty = nir_alu_type_get_base_type(ins->src_types[0]) == nir_type_float;
+
+        return classy && floaty;
 }
 
 /* A source is swizzled if the op is swizzlable, in 8-bit or
@@ -95,11 +96,29 @@ bi_from_bytemask(uint16_t bytemask, unsigned bytes)
 unsigned
 bi_get_component_count(bi_instruction *ins, signed src)
 {
+        /* Discards and branches are oddball since they're not BI_VECTOR but no
+         * destination. So special case.. */
+        if (ins->type == BI_DISCARD || ins->type == BI_BRANCH)
+                return 1;
+
         if (bi_class_props[ins->type] & BI_VECTOR) {
                 assert(ins->vector_channels);
                 return (src <= 0) ? ins->vector_channels : 1;
         } else {
-                unsigned bytes = nir_alu_type_get_type_size(src < 0 ? ins->dest_type : ins->src_types[src]);
+                unsigned dest_bytes = nir_alu_type_get_type_size(ins->dest_type);
+                unsigned src_bytes = nir_alu_type_get_type_size(ins->src_types[src]);
+
+                /* If there's either f32 on either end, it's only a single
+                 * component, etc. */
+
+                unsigned bytes = src < 0 ? dest_bytes : src_bytes;
+
+                if (ins->type == BI_CONVERT)
+                        bytes = MAX2(dest_bytes, src_bytes);
+                
+                if (ins->type == BI_ATEST || ins->type == BI_SELECT)
+                        return 1;
+
                 return MAX2(32 / bytes, 1);
         }
 }