i965/vec4: Fix cmod propagation not to propagate non-identity cmod into CMP(N).
authorFrancisco Jerez <currojerez@riseup.net>
Wed, 1 Jun 2016 23:27:52 +0000 (16:27 -0700)
committerFrancisco Jerez <currojerez@riseup.net>
Sat, 4 Jun 2016 01:38:51 +0000 (18:38 -0700)
The conditional mod of these instructions determines the semantics of
the comparison itself (rather than being evaluated based on the result
of the instruction as is usually the case for most other instructions
that allow conditional mods), so it's in general not legal to
propagate a conditional mod into a CMP instruction.  This prevents
cmod propagation from (mis)optimizing:

 cmp.z.f0 tmp, ...
 mov.z.f0 null, tmp

into:

 cmp.z.f0 tmp, ...

which gives the negation of the flag result of the original sequence.
I originally noticed this while working on SIMD32 in the scalar
back-end, but the same scenario is likely to be possible in vec4
programs so this commit ports the bugfix with the same name from the
scalar back-end to the vec4 cmod propagation pass.

Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/mesa/drivers/dri/i965/brw_vec4_cmod_propagation.cpp

index 0c8224f5f8336138103f6bb5e99066e5caf24a04..c376bebbe8eed71b373f32ba9b86e9724123be9f 100644 (file)
@@ -115,6 +115,18 @@ opt_cmod_propagation_local(bblock_t *block)
                break;
             }
 
+            /* The conditional mod of the CMP/CMPN instructions behaves
+             * specially because the flag output is not calculated from the
+             * result of the instruction, but the other way around, which
+             * means that even if the condmod to propagate and the condmod
+             * from the CMP instruction are the same they will in general give
+             * different results because they are evaluated based on different
+             * inputs.
+             */
+            if (scan_inst->opcode == BRW_OPCODE_CMP ||
+                scan_inst->opcode == BRW_OPCODE_CMPN)
+               break;
+
             /* Otherwise, try propagating the conditional. */
             enum brw_conditional_mod cond =
                inst->src[0].negate ? brw_swap_cmod(inst->conditional_mod)