nir/lower_source_mods: Don't propagate register sources
authorJason Ekstrand <jason.ekstrand@intel.com>
Mon, 13 Apr 2015 21:13:16 +0000 (14:13 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 23 Apr 2015 01:10:41 +0000 (18:10 -0700)
The nir_lower_source_mods pass does a weak form of copy propagation to
clean up all of the mov-with-negate's that get generated.  However, we
weren't properly checking that the sources were SSA and so we could end up
moving a register read which is not, in general, valid.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
src/glsl/nir/nir_lower_to_source_mods.c

index d6bf77f17c1172cc152b9d8f825cde92682bc460..7b4a0f657380c982eed99dfee32f336188e191fd 100644 (file)
@@ -67,6 +67,13 @@ nir_lower_to_source_mods_block(nir_block *block, void *state)
             continue;
          }
 
+         /* We can only do a rewrite if the source we are copying is SSA.
+          * Otherwise, moving the read might invalidly reorder reads/writes
+          * on a register.
+          */
+         if (!parent->src[0].src.is_ssa)
+            continue;
+
          nir_instr_rewrite_src(instr, &alu->src[i].src, parent->src[0].src);
          if (alu->src[i].abs) {
             /* abs trumps both neg and abs, do nothing */