r600/sfn: Always check arrays writes before allowing copy propagation
authorGert Wollny <gert.wollny@collabora.com>
Sat, 22 Jul 2023 16:22:07 +0000 (18:22 +0200)
committerMarge Bot <emma+marge@anholt.net>
Wed, 26 Jul 2023 19:33:42 +0000 (19:33 +0000)
Also propaate extra dependencies when an indirect load is propagated

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24297>

src/gallium/drivers/r600/sfn/sfn_optimizer.cpp

index 986019a..c2f6183 100644 (file)
@@ -407,25 +407,29 @@ CopyPropFwdVisitor::visit(AluInstr *instr)
             }
          }
       }
-
+      bool move_addr_use = false;
       bool src_can_propagate = false;
       if (auto rsrc = src->as_register()) {
          if (rsrc->has_flag(Register::ssa)) {
             src_can_propagate = true;
          } else if (mov_block_id == target_block_id) {
-            if (rsrc->addr()) {
-               if (i->block_id() == mov_block_id &&
-                   i->index() == instr->index() + 1)
+            if (auto a = rsrc->addr()) {
+               if (a->as_register() &&
+                   !a->as_register()->has_flag(Register::addr_or_idx) &&
+                   i->block_id() == mov_block_id &&
+                   i->index() == instr->index() + 1) {
                   src_can_propagate = true;
+                  move_addr_use = true;
+               }
             } else {
                src_can_propagate = true;
-               for (auto p : rsrc->parents()) {
-                  if (p->block_id() == mov_block_id &&
-                      p->index() > instr->index() &&
-                      p->index() < i->index()) {
-                     src_can_propagate = false;
-                     break;
-                  }
+            }
+            for (auto p : rsrc->parents()) {
+               if (p->block_id() == mov_block_id &&
+                   p->index() > instr->index() &&
+                   p->index() < i->index()) {
+                  src_can_propagate = false;
+                  break;
                }
             }
          }
@@ -439,8 +443,16 @@ CopyPropFwdVisitor::visit(AluInstr *instr)
 
          if (i->as_alu() && i->as_alu()->parent_group()) {
             progress |= i->as_alu()->parent_group()->replace_source(dest, src);
-         } else
-            progress |= i->replace_source(dest, src);
+         } else {
+            bool success = i->replace_source(dest, src);
+            if (success && move_addr_use) {
+               for (auto r : instr->required_instr()){
+                  std::cerr << "add " << *r << " to " << *i << "\n";
+                  i->add_required_instr(r);
+               }
+            }
+            progress |= success;
+         }
       }
    }
    if (instr->dest()) {