i965/vs: Fix access beyond array bounds for non-GRF operands.
authorEric Anholt <eric@anholt.net>
Fri, 23 Sep 2011 20:52:47 +0000 (13:52 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 26 Sep 2011 22:33:42 +0000 (15:33 -0700)
Caught by valgrind.  I never saw a segfault from it (probably because
it's hard to have much more of any other file than GRF).

src/mesa/drivers/dri/i965/brw_vec4_copy_propagation.cpp

index e0b2d2abf2bb26a119de28887027ce17392e614f..a5f6f93879a810cc64174183a4b61f27a2c00f3b 100644 (file)
@@ -241,9 +241,6 @@ vec4_visitor::opt_copy_propagation()
        * optimizing out access to the copy result
        */
       for (int i = 2; i >= 0; i--) {
-        int reg = (virtual_grf_reg_map[inst->src[i].reg] +
-                   inst->src[i].reg_offset);
-
         /* Copied values end up in GRFs, and we don't track reladdr
          * accesses.
          */
@@ -251,6 +248,9 @@ vec4_visitor::opt_copy_propagation()
             inst->src[i].reladdr)
            continue;
 
+        int reg = (virtual_grf_reg_map[inst->src[i].reg] +
+                   inst->src[i].reg_offset);
+
         /* Find the regs that each swizzle component came from.
          */
         src_reg *values[4];