r600g/sb: fix issues cause by GLSL switching to loops for switch
[mesa.git] / src / gallium / drivers / r600 / sb / sb_dce_cleanup.cpp
index acd6613166f645a13d9c8c32395fbd14f14574e0..79aef9106a4f543bbcc553e19dc59e3eb68056cb 100644 (file)
@@ -56,7 +56,8 @@ bool dce_cleanup::visit(cf_node& n, bool enter) {
                else
                        cleanup_dst(n);
        } else {
-               if (n.bc.op_ptr->flags & (CF_CLAUSE | CF_BRANCH | CF_LOOP))
+               if ((sh.dce_flags & DF_EXPAND) &&
+                               (n.bc.op_ptr->flags & (CF_CLAUSE | CF_BRANCH | CF_LOOP)))
                        n.expand();
        }
        return true;
@@ -107,27 +108,35 @@ bool dce_cleanup::visit(region_node& n, bool enter) {
 }
 
 void dce_cleanup::cleanup_dst(node& n) {
-       cleanup_dst_vec(n.dst);
+       if (!cleanup_dst_vec(n.dst) && remove_unused &&
+                       !n.dst.empty() && !(n.flags & NF_DONT_KILL) && n.parent)
+               n.remove();
 }
 
 bool dce_cleanup::visit(container_node& n, bool enter) {
-       if (enter) {
+       if (enter)
                cleanup_dst(n);
-       } else {
-
-       }
        return true;
 }
 
-void dce_cleanup::cleanup_dst_vec(vvec& vv) {
+bool dce_cleanup::cleanup_dst_vec(vvec& vv) {
+       bool alive = false;
+
        for (vvec::iterator I = vv.begin(), E = vv.end(); I != E; ++I) {
                value* &v = *I;
                if (!v)
                        continue;
 
-               if (v->is_dead())
+               if (v->gvn_source && v->gvn_source->is_dead())
+                       v->gvn_source = NULL;
+
+               if (v->is_dead() || (remove_unused && !v->is_rel() && !v->uses))
                        v = NULL;
+               else
+                       alive = true;
        }
+
+       return alive;
 }
 
 } // namespace r600_sb