test_vec4_cmod_propagation.cpp revision f9a9ba5eac2f1934bd7fecc92cd309f22411164b
18fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro/*
28fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * Copyright © 2015 Intel Corporation
38fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro *
48fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * Permission is hereby granted, free of charge, to any person obtaining a
58fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * copy of this software and associated documentation files (the "Software"),
68fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * to deal in the Software without restriction, including without limitation
78fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * and/or sell copies of the Software, and to permit persons to whom the
98fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * Software is furnished to do so, subject to the following conditions:
108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro *
118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * The above copyright notice and this permission notice (including the next
128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * paragraph) shall be included in all copies or substantial portions of the
138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * Software.
148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro *
158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * IN THE SOFTWARE.
228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro *
238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * Based on test_fs_cmod_propagation.cpp
248fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro */
258fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
268fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro#include <gtest/gtest.h>
278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro#include "brw_vec4.h"
288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro#include "brw_vec4_builder.h"
298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro#include "brw_cfg.h"
308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro#include "program/program.h"
318fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
328fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeirousing namespace brw;
338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiroclass cmod_propagation_test : public ::testing::Test {
358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   virtual void SetUp();
368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiropublic:
388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   struct brw_compiler *compiler;
398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   struct brw_device_info *devinfo;
408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   struct gl_context *ctx;
418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   struct gl_shader_program *shader_prog;
428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   struct brw_vertex_program *vp;
438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   vec4_visitor *v;
448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro};
458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiroclass cmod_propagation_vec4_visitor : public vec4_visitor
478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
488fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiropublic:
498fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   cmod_propagation_vec4_visitor(struct brw_compiler *compiler,
508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro                                 nir_shader *shader)
518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      : vec4_visitor(compiler, NULL, NULL, NULL, shader, NULL,
528fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro                     false, -1) {}
538fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
548fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiroprotected:
558fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* Dummy implementation for pure virtual methods */
568fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   virtual dst_reg *make_reg_for_system_value(int location,
578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro                                              const glsl_type *type)
588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   {
598fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      unreachable("Not reached");
608fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   virtual void setup_payload()
638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   {
648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      unreachable("Not reached");
658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   virtual void emit_prolog()
688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   {
698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      unreachable("Not reached");
708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
718fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
728fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   virtual void emit_program_code()
738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   {
748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      unreachable("Not reached");
758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   virtual void emit_thread_end()
788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   {
798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      unreachable("Not reached");
808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   virtual void emit_urb_write_header(int mrf)
838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   {
848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      unreachable("Not reached");
858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   virtual vec4_instruction *emit_urb_write_opcode(bool complete)
888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   {
898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      unreachable("Not reached");
908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro};
928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeirovoid cmod_propagation_test::SetUp()
958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ctx = (struct gl_context *)calloc(1, sizeof(*ctx));
978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   compiler = (struct brw_compiler *)calloc(1, sizeof(*compiler));
988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   devinfo = (struct brw_device_info *)calloc(1, sizeof(*devinfo));
998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   compiler->devinfo = devinfo;
1008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   vp = ralloc(NULL, struct brw_vertex_program);
1028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   nir_shader *shader = nir_shader_create(NULL, MESA_SHADER_VERTEX, NULL);
1048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v = new cmod_propagation_vec4_visitor(compiler, shader);
1068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   _mesa_init_gl_program(&vp->program.Base, GL_VERTEX_SHADER, 0);
1088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   devinfo->gen = 4;
1108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
1118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeirostatic vec4_instruction *
1138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiroinstruction(bblock_t *block, int num)
1148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
1158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   vec4_instruction *inst = (vec4_instruction *)block->start();
1168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   for (int i = 0; i < num; i++) {
1178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      inst = (vec4_instruction *)inst->next;
1188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
1198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   return inst;
1208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
1218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeirostatic bool
1238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeirocmod_propagation(vec4_visitor *v)
1248fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
12592ae101ed0dff689f207abf61f68167009de4e29Alejandro Piñeiro   const bool print = getenv("TEST_DEBUG");
1268fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   if (print) {
1288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      fprintf(stderr, "= Before =\n");
1298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      v->dump_instructions();
1308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
1318fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1328fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bool ret = v->opt_cmod_propagation();
1338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   if (print) {
1358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      fprintf(stderr, "\n= After =\n");
1368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      v->dump_instructions();
1378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
1388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   return ret;
1408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
1418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, basic)
1438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
1448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
1458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::float_type);
1468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
1478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
148f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
1498fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
1508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest_null.writemask = WRITEMASK_X;
1518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1528fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.ADD(dest, src0, src1);
1538fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest_null, src_reg(dest), zero, BRW_CONDITIONAL_GE);
1548fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1558fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
1568fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
1578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add        dest.x  src0.xxxx  src1.xxxx
1588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.ge.f0  null.x  dest.xxxx  0.0f
1598fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
1608fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
1618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add.ge.f0  dest.x  src0.xxxx  src1.xxxx
1628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
1638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
1658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
1668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
1688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
1698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_TRUE(cmod_propagation(v));
1718fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1728fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
1738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->end_ip);
1748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
1758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 0)->conditional_mod);
1768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
1778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, basic_different_dst_writemask)
1798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
1808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
1818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::float_type);
1828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
1838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
184f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
1858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
1868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.ADD(dest, src0, src1);
1888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest_null, src_reg(dest), zero, BRW_CONDITIONAL_GE);
1898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
1918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
1928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add        dest.x     src0  src1
1938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.ge.f0  null.xyzw  dest  0.0f
1948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
1958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
1968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
1978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
1988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
2008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
2018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
2038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
2048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
2068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
2088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
2098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
2108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NONE, instruction(block0, 0)->conditional_mod);
2118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
2128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 1)->conditional_mod);
2138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
2148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, andz_one)
2168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
2178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
2188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::int_type);
2198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
220f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
221f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg one(brw_imm_d(1));
2228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(retype(dest, BRW_REGISTER_TYPE_F), src0, zero, BRW_CONDITIONAL_L);
2248fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   set_condmod(BRW_CONDITIONAL_Z,
2258fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro               bld.AND(bld.null_reg_d(), src_reg(dest), one));
2268fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
2288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: cmp.l.f0     dest:F  src0:F  0F
2298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: and.z.f0     null:D  dest:D  1D
2308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
2318fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
2328fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
2338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
2348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
2368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
2378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
2398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
2408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
2428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
2448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
2458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 0)->opcode);
2468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_L, instruction(block0, 0)->conditional_mod);
2478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_AND, instruction(block0, 1)->opcode);
2488fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_EQ, instruction(block0, 1)->conditional_mod);
2498fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
2508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, non_cmod_instruction)
2528fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
2538fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
2548fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::uint_type);
2558fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::uint_type);
256f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_ud(0u));
2578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.FBL(dest, src0);
2588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_ud(), src_reg(dest), zero, BRW_CONDITIONAL_GE);
2598fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2608fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
2618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
2628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: fbl        dest  src0
2638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.ge.f0  null  dest  0u
2648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
2658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
2668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
2678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
2688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
2708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
2718fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2728fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
2738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
2748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
2768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
2788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
2798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_FBL, instruction(block0, 0)->opcode);
2808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
2818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 1)->conditional_mod);
2828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
2838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, intervening_flag_write)
2858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
2868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
2878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::float_type);
2888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
2898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
2908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src2 = src_reg(v, glsl_type::float_type);
291f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
2928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.ADD(dest, src0, src1);
2938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_f(), src2, zero, BRW_CONDITIONAL_GE);
2948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_f(), src_reg(dest), zero, BRW_CONDITIONAL_GE);
2958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
2978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
2988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add        dest  src0  src1
2998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.ge.f0  null  src2  0.0f
3008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 2: cmp.ge.f0  null  dest  0.0f
3018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
3028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
3038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
3048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
3058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
3078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
3088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
3108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(2, block0->end_ip);
3118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
3138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
3158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(2, block0->end_ip);
3168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
3178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
3188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 1)->conditional_mod);
3198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 2)->opcode);
3208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 2)->conditional_mod);
3218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
3228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, intervening_flag_read)
3248fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
3258fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
3268fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest0 = dst_reg(v, glsl_type::float_type);
3278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest1 = dst_reg(v, glsl_type::float_type);
3288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
3298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
3308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src2 = src_reg(v, glsl_type::float_type);
331f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
3328fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.ADD(dest0, src0, src1);
3338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   set_predicate(BRW_PREDICATE_NORMAL, bld.SEL(dest1, src2, zero));
3348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_f(), src_reg(dest0), zero, BRW_CONDITIONAL_GE);
3358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
3378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
3388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add        dest0 src0  src1
3398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: (+f0) sel  dest1 src2  0.0f
3408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 2: cmp.ge.f0  null  dest0 0.0f
3418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
3428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
3438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
3448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
3458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
3478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
3488fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3498fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
3508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(2, block0->end_ip);
3518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3528fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
3538fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3548fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
3558fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(2, block0->end_ip);
3568fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
3578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_SEL, instruction(block0, 1)->opcode);
3588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_PREDICATE_NORMAL, instruction(block0, 1)->predicate);
3598fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 2)->opcode);
3608fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 2)->conditional_mod);
3618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
3628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, intervening_dest_write)
3648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
3658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
3668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::vec4_type);
3678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
3688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
3698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src2 = src_reg(v, glsl_type::vec2_type);
370f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
3718fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.ADD(offset(dest, 2), src0, src1);
3728fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.emit(SHADER_OPCODE_TEX, dest, src2)
3738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      ->regs_written = 4;
3748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_f(), offset(src_reg(dest), 2), zero, BRW_CONDITIONAL_GE);
3758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
3778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
3788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add        dest+2  src0    src1
3798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: tex rlen 4 dest+0  src2
3808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 2: cmp.ge.f0  null    dest+2  0.0f
3818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
3828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
3838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
3848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
3858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
3878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
3888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
3908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(2, block0->end_ip);
3918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
3938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
3958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(2, block0->end_ip);
3968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
3978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NONE, instruction(block0, 0)->conditional_mod);
3988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(SHADER_OPCODE_TEX, instruction(block0, 1)->opcode);
3998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NONE, instruction(block0, 0)->conditional_mod);
4008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 2)->opcode);
4018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 2)->conditional_mod);
4028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
4038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, intervening_flag_read_same_value)
4058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
4068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
4078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest0 = dst_reg(v, glsl_type::float_type);
4088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest1 = dst_reg(v, glsl_type::float_type);
4098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
4108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
4118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src2 = src_reg(v, glsl_type::float_type);
412f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
4138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
4148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest_null.writemask = WRITEMASK_X;
4158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   set_condmod(BRW_CONDITIONAL_GE, bld.ADD(dest0, src0, src1));
4178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   set_predicate(BRW_PREDICATE_NORMAL, bld.SEL(dest1, src2, zero));
4188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest_null, src_reg(dest0), zero, BRW_CONDITIONAL_GE);
4198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
4218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
4228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add.ge.f0  dest0   src0  src1
4238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: (+f0) sel  dest1   src2  0.0f
4248fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 2: cmp.ge.f0  null.x  dest0 0.0f
4258fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
4268fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
4278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add.ge.f0  dest0 src0  src1
4288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: (+f0) sel  dest1 src2  0.0f
4298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
4308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4318fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
4328fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
4338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
4358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(2, block0->end_ip);
4368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_TRUE(cmod_propagation(v));
4388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
4398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
4408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
4418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 0)->conditional_mod);
4428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_SEL, instruction(block0, 1)->opcode);
4438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_PREDICATE_NORMAL, instruction(block0, 1)->predicate);
4448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
4458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, negate)
4478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
4488fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
4498fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::float_type);
4508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
4518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
452f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
4538fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.ADD(dest, src0, src1);
4548fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg tmp_src = src_reg(dest);
4558fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   tmp_src.negate = true;
4568fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
4578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest_null.writemask = WRITEMASK_X;
4588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest_null, tmp_src, zero, BRW_CONDITIONAL_GE);
4598fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4608fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
4618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
4628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add        dest     src0  src1
4638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.ge.f0  null.x  -dest 0.0f
4648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
4658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
4668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add.le.f0  dest     src0  src1
4678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
4688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
4708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
4718fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4728fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
4738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
4748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_TRUE(cmod_propagation(v));
4768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
4778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->end_ip);
4788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
4798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_LE, instruction(block0, 0)->conditional_mod);
4808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
4818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, movnz)
4838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
4848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
4858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::float_type);
4868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
4878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
4888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
4898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest_null.writemask = WRITEMASK_X;
4908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest, src0, src1, BRW_CONDITIONAL_L);
4928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   set_condmod(BRW_CONDITIONAL_NZ,
4938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro               bld.MOV(dest_null, src_reg(dest)));
4948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
4968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
4978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: cmp.l.f0  dest:F  src0:F  src1:F
4988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: mov.nz.f0 null.x  dest:F
4998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
5008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
5018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: cmp.l.f0  dest  src0:F  src1:F
5028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
5038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
5058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
5068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
5088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
5098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_TRUE(cmod_propagation(v));
5118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
5138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->end_ip);
5148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 0)->opcode);
5158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_L, instruction(block0, 0)->conditional_mod);
5168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
5178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, different_types_cmod_with_zero)
5198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
5208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
5218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::int_type);
5228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::int_type);
5238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::int_type);
524f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
5258fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.ADD(dest, src0, src1);
5268fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_f(), retype(src_reg(dest), BRW_REGISTER_TYPE_F), zero,
5278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro           BRW_CONDITIONAL_GE);
5288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
5308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
5318fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add        dest:D  src0:D  src1:D
5328fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.ge.f0  null:F  dest:F  0.0f
5338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
5348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
5358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
5368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
5378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
5398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
5408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
5428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
5438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
5458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
5478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
5488fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
5498fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
5508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 1)->conditional_mod);
5518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
5528fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5538fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, andnz_non_one)
5548fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
5558fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
5568fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::int_type);
5578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
558f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
559f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg nonone(brw_imm_d(38));
5608fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(retype(dest, BRW_REGISTER_TYPE_F), src0, zero, BRW_CONDITIONAL_L);
5628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   set_condmod(BRW_CONDITIONAL_NZ,
5638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro               bld.AND(bld.null_reg_d(), src_reg(dest), nonone));
5648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
5668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: cmp.l.f0     dest:F  src0:F  0F
5678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: and.nz.f0    null:D  dest:D  38D
5688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
5698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
5708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
5718fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
5728fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
5748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
5758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
5778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
5788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
5808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
5828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
5838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 0)->opcode);
5848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_L, instruction(block0, 0)->conditional_mod);
5858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_AND, instruction(block0, 1)->opcode);
5868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NZ, instruction(block0, 1)->conditional_mod);
5878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
5888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro/* Note that basic is using glsl_type:float types, while this one is using
5908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * glsl_type::vec4 */
5918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, basic_vec4)
5928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
5938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
5948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::vec4_type);
5958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::vec4_type);
5968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::vec4_type);
597f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
5988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.MUL(dest, src0, src1);
6008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_f(), src_reg(dest), zero, BRW_CONDITIONAL_NZ);
6018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
6038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: mul         dest.xyzw  src0.xyzw  src1.xyzw
6048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.nz.f0.0 null.xyzw  dest.xyzw  0.0f
6058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
6068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
6078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: mul.nz.f0.0 dest.xyzw  src0.xyzw  src1.xyzw
6088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
6098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
6118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
6128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
6148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
6158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_TRUE(cmod_propagation(v));
6178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
6198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->end_ip);
6208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_MUL, instruction(block0, 0)->opcode);
6218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NZ, instruction(block0, 0)->conditional_mod);
6228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
6238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6248fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, basic_vec4_different_dst_writemask)
6258fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
6268fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
6278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::vec4_type);
6288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest.writemask = WRITEMASK_X;
6298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::vec4_type);
6308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::vec4_type);
631f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
6328fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
6338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.MUL(dest, src0, src1);
6358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest_null, src_reg(dest), zero, BRW_CONDITIONAL_NZ);
6368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
6388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: mul         dest.x  src0  src1
6398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.nz.f0.0 null    dest  0.0f
6408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
6418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
6428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
6438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
6448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
6468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
6478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6488fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
6498fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
6508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
6528fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6538fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
6548fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
6558fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_MUL, instruction(block0, 0)->opcode);
6568fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NONE, instruction(block0, 0)->conditional_mod);
6578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
6588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NZ, instruction(block0, 1)->conditional_mod);
6598fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
6608fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, mad_one_component_vec4)
6628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
6638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
6648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::vec4_type);
6658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest.writemask = WRITEMASK_X;
6668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::vec4_type);
6678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::vec4_type);
6688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src2 = src_reg(v, glsl_type::vec4_type);
6698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src0.swizzle = src1.swizzle = src2.swizzle = BRW_SWIZZLE_XXXX;
6708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src2.negate = true;
671f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
6728fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg tmp(dest);
6738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   tmp.swizzle = BRW_SWIZZLE_XXXX;
6748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
6758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest_null.writemask = WRITEMASK_X;
6768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.MAD(dest, src0, src1, src2);
6788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest_null, tmp, zero, BRW_CONDITIONAL_L);
6798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
6818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
6828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: mad         dest.x:F  src0.xxxx:F  src10.xxxx:F  -src2.xxxx:F
6838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.l.f0.0  null.x:F  dest.xxxx:F  0.0f
6848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
6858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
6868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: mad.l.f0    dest.x:F  src0.xxxx:F  src10.xxxx:F  -src2.xxxx:F
6878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
6888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
6908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
6918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
6938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
6948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_TRUE(cmod_propagation(v));
6968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
6988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->end_ip);
6998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_MAD, instruction(block0, 0)->opcode);
7008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_L, instruction(block0, 0)->conditional_mod);
7018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
7028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, mad_more_one_component_vec4)
7048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
7058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
7068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::vec4_type);
7078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest.writemask = WRITEMASK_XW;
7088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::vec4_type);
7098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::vec4_type);
7108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src2 = src_reg(v, glsl_type::vec4_type);
7118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src0.swizzle = src1.swizzle = src2.swizzle = BRW_SWIZZLE_XXXX;
7128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src2.negate = true;
713f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
7148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg tmp(dest);
7158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   tmp.swizzle = BRW_SWIZZLE_XXXX;
7168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
7178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.MAD(dest, src0, src1, src2);
7198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest_null, tmp, zero, BRW_CONDITIONAL_L);
7208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
7228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
7238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: mad         dest.xw:F  src0.xxxx:F  src10.xxxx:F  -src2.xxxx:F
7248fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.l.f0.0  null:F  dest.xxxx:F  zeroF
7258fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
7268fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
7278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (No changes)
7288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
7298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
7318fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
7328fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
7348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
7358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
7378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
7398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
7408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_MAD, instruction(block0, 0)->opcode);
7418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NONE, instruction(block0, 0)->conditional_mod);
7428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
7438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_L, instruction(block0, 1)->conditional_mod);
7448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
7458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, cmp_mov_vec4)
7478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
7488fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
7498fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::ivec4_type);
7508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest.writemask = WRITEMASK_X;
7518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::ivec4_type);
7528fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src0.swizzle = BRW_SWIZZLE_XXXX;
7538fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src0.file = UNIFORM;
754f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg nonone = retype(brw_imm_d(16), BRW_REGISTER_TYPE_D);
7558fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg mov_src = src_reg(dest);
7568fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   mov_src.swizzle = BRW_SWIZZLE_XXXX;
7578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_d();
7588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest_null.writemask = WRITEMASK_X;
7598fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7608fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest, src0, nonone, BRW_CONDITIONAL_GE);
7618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   set_condmod(BRW_CONDITIONAL_NZ,
7628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro               bld.MOV(dest_null, mov_src));
7638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
7658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
7668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: cmp.ge.f0  dest.x:D  u.xxxx:D  16D
7678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: mov.nz.f0  null.x:D  dest.xxxx:D
7688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
7698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
7708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: cmp.ge.f0  dest.x:D  u.xxxx:D  16D
7718fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
7728fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
7748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
7758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
7778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
7788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_TRUE(cmod_propagation(v));
7808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
7828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->end_ip);
7838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 0)->opcode);
7848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 0)->conditional_mod);
7858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
7868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, mul_cmp_different_channels_vec4)
7888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
7898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
7908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::vec4_type);
7918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::vec4_type);
7928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::vec4_type);
793f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
7948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg cmp_src = src_reg(dest);
7958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   cmp_src.swizzle = BRW_SWIZZLE4(0,1,3,2);
7968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.MUL(dest, src0, src1);
7988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_f(), cmp_src, zero, BRW_CONDITIONAL_NZ);
7998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
8008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
8018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: mul         dest  src0       src1
8028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.nz.f0.0 null  dest.xywz  0.0f
8038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
8048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
8058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (No changes)
8068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
8078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
8088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
8098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
8108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
8118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
8128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
8138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
8148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
8158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
8168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
8178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
8188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_MUL, instruction(block0, 0)->opcode);
8198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NONE, instruction(block0, 0)->conditional_mod);
8208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
8218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NZ, instruction(block0, 1)->conditional_mod);
8228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
823