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;
39527f37199929932300acc1688d8160e1f3b1d753Jason Ekstrand   struct gen_device_info *devinfo;
408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   struct gl_context *ctx;
418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   struct gl_shader_program *shader_prog;
42c300559fbfa6127320b78c130061fdb6a454658dMatt Turner   struct brw_vue_prog_data *prog_data;
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,
50c300559fbfa6127320b78c130061fdb6a454658dMatt Turner                                 nir_shader *shader,
51c300559fbfa6127320b78c130061fdb6a454658dMatt Turner                                 struct brw_vue_prog_data *prog_data)
52c300559fbfa6127320b78c130061fdb6a454658dMatt Turner      : vec4_visitor(compiler, NULL, NULL, prog_data, shader, NULL,
53c300559fbfa6127320b78c130061fdb6a454658dMatt Turner                     false, -1)
54c300559fbfa6127320b78c130061fdb6a454658dMatt Turner      {
55c300559fbfa6127320b78c130061fdb6a454658dMatt Turner         prog_data->dispatch_mode = DISPATCH_MODE_4X2_DUAL_OBJECT;
56c300559fbfa6127320b78c130061fdb6a454658dMatt Turner      }
578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiroprotected:
598fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* Dummy implementation for pure virtual methods */
60f687b8e1785df0825443f07778e5d0ddf6f9be09Ian Romanick   virtual dst_reg *make_reg_for_system_value(int location)
618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   {
628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      unreachable("Not reached");
638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   virtual void setup_payload()
668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   {
678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      unreachable("Not reached");
688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   virtual void emit_prolog()
718fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   {
728fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      unreachable("Not reached");
738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   virtual void emit_program_code()
768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   {
778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      unreachable("Not reached");
788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   virtual void emit_thread_end()
818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   {
828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      unreachable("Not reached");
838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   virtual void emit_urb_write_header(int mrf)
868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   {
878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      unreachable("Not reached");
888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   virtual vec4_instruction *emit_urb_write_opcode(bool complete)
918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   {
928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      unreachable("Not reached");
938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro};
958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeirovoid cmod_propagation_test::SetUp()
988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ctx = (struct gl_context *)calloc(1, sizeof(*ctx));
1008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   compiler = (struct brw_compiler *)calloc(1, sizeof(*compiler));
101527f37199929932300acc1688d8160e1f3b1d753Jason Ekstrand   devinfo = (struct gen_device_info *)calloc(1, sizeof(*devinfo));
102c300559fbfa6127320b78c130061fdb6a454658dMatt Turner   prog_data = (struct brw_vue_prog_data *)calloc(1, sizeof(*prog_data));
1038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   compiler->devinfo = devinfo;
1048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
105e1af20f18a86f52a9640faf2d4ff8a71b0a4fa9bTimothy Arceri   nir_shader *shader =
106e1af20f18a86f52a9640faf2d4ff8a71b0a4fa9bTimothy Arceri      nir_shader_create(NULL, MESA_SHADER_VERTEX, NULL, NULL);
1078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
108c300559fbfa6127320b78c130061fdb6a454658dMatt Turner   v = new cmod_propagation_vec4_visitor(compiler, shader, prog_data);
1098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   devinfo->gen = 4;
1118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
1128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeirostatic vec4_instruction *
1148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiroinstruction(bblock_t *block, int num)
1158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
1168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   vec4_instruction *inst = (vec4_instruction *)block->start();
1178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   for (int i = 0; i < num; i++) {
1188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      inst = (vec4_instruction *)inst->next;
1198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
1208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   return inst;
1218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
1228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeirostatic bool
1248fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeirocmod_propagation(vec4_visitor *v)
1258fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
12692ae101ed0dff689f207abf61f68167009de4e29Alejandro Piñeiro   const bool print = getenv("TEST_DEBUG");
1278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   if (print) {
1298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      fprintf(stderr, "= Before =\n");
1308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      v->dump_instructions();
1318fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
1328fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bool ret = v->opt_cmod_propagation();
1348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   if (print) {
1368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      fprintf(stderr, "\n= After =\n");
1378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro      v->dump_instructions();
1388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   }
1398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   return ret;
1418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
1428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, basic)
1448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
1458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
1468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::float_type);
1478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
1488fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
149f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
1508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
1518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest_null.writemask = WRITEMASK_X;
1528fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1538fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.ADD(dest, src0, src1);
1548fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest_null, src_reg(dest), zero, BRW_CONDITIONAL_GE);
1558fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1568fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
1578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
1588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add        dest.x  src0.xxxx  src1.xxxx
1598fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.ge.f0  null.x  dest.xxxx  0.0f
1608fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
1618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
1628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add.ge.f0  dest.x  src0.xxxx  src1.xxxx
1638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
1648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
1668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
1678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
1698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
1708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1718fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_TRUE(cmod_propagation(v));
1728fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
1748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->end_ip);
1758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
1768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 0)->conditional_mod);
1778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
1788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, basic_different_dst_writemask)
1808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
1818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
1828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::float_type);
1838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
1848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
185f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
1868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
1878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.ADD(dest, src0, src1);
1898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest_null, src_reg(dest), zero, BRW_CONDITIONAL_GE);
1908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
1918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
1928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
1938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add        dest.x     src0  src1
1948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.ge.f0  null.xyzw  dest  0.0f
1958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
1968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
1978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
1988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
1998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
2018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
2028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
2048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
2058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
2078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
2098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
2108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
2118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NONE, instruction(block0, 0)->conditional_mod);
2128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
2138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 1)->conditional_mod);
2148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
2158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, andz_one)
2178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
2188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
2198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::int_type);
2208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
221f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
222f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg one(brw_imm_d(1));
2238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2248fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(retype(dest, BRW_REGISTER_TYPE_F), src0, zero, BRW_CONDITIONAL_L);
2258fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   set_condmod(BRW_CONDITIONAL_Z,
2268fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro               bld.AND(bld.null_reg_d(), src_reg(dest), one));
2278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
2298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: cmp.l.f0     dest:F  src0:F  0F
2308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: and.z.f0     null:D  dest:D  1D
2318fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
2328fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
2338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
2348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
2358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
2378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
2388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
2408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
2418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
2438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
2458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
2468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 0)->opcode);
2478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_L, instruction(block0, 0)->conditional_mod);
2488fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_AND, instruction(block0, 1)->opcode);
2498fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_EQ, instruction(block0, 1)->conditional_mod);
2508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
2518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2528fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, non_cmod_instruction)
2538fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
2548fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
2558fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::uint_type);
2568fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::uint_type);
257f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_ud(0u));
2588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.FBL(dest, src0);
2598fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_ud(), src_reg(dest), zero, BRW_CONDITIONAL_GE);
2608fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
2628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
2638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: fbl        dest  src0
2648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.ge.f0  null  dest  0u
2658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
2668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
2678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
2688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
2698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
2718fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
2728fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
2748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
2758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
2778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
2798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
2808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_FBL, instruction(block0, 0)->opcode);
2818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
2828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 1)->conditional_mod);
2838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
2848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, intervening_flag_write)
2868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
2878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
2888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::float_type);
2898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
2908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
2918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src2 = src_reg(v, glsl_type::float_type);
292f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
2938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.ADD(dest, src0, src1);
2948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_f(), src2, zero, BRW_CONDITIONAL_GE);
2958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_f(), src_reg(dest), zero, BRW_CONDITIONAL_GE);
2968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
2978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
2988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
2998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add        dest  src0  src1
3008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.ge.f0  null  src2  0.0f
3018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 2: cmp.ge.f0  null  dest  0.0f
3028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
3038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
3048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
3058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
3068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
3088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
3098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
3118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(2, block0->end_ip);
3128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
3148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
3168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(2, block0->end_ip);
3178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
3188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
3198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 1)->conditional_mod);
3208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 2)->opcode);
3218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 2)->conditional_mod);
3228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
3238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3248fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, intervening_flag_read)
3258fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
3268fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
3278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest0 = dst_reg(v, glsl_type::float_type);
3288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest1 = dst_reg(v, glsl_type::float_type);
3298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
3308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
3318fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src2 = src_reg(v, glsl_type::float_type);
332f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
3338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.ADD(dest0, src0, src1);
3348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   set_predicate(BRW_PREDICATE_NORMAL, bld.SEL(dest1, src2, zero));
3358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_f(), src_reg(dest0), zero, BRW_CONDITIONAL_GE);
3368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
3388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
3398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add        dest0 src0  src1
3408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: (+f0) sel  dest1 src2  0.0f
3418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 2: cmp.ge.f0  null  dest0 0.0f
3428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
3438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
3448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
3458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
3468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
3488fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
3498fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
3518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(2, block0->end_ip);
3528fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3538fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
3548fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3558fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
3568fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(2, block0->end_ip);
3578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
3588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_SEL, instruction(block0, 1)->opcode);
3598fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_PREDICATE_NORMAL, instruction(block0, 1)->predicate);
3608fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 2)->opcode);
3618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 2)->conditional_mod);
3628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
3638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, intervening_dest_write)
3658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
3668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
3678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::vec4_type);
3688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
3698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
3708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src2 = src_reg(v, glsl_type::vec2_type);
371f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
372cab3d4673922e2beb1f86f59c6aef17f55da3ac2Jason Ekstrand   bld.ADD(offset(dest, 8, 2), src0, src1);
3738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.emit(SHADER_OPCODE_TEX, dest, src2)
37469fdf13c215c2970feaca76f178a5c2c11ba8fecFrancisco Jerez      ->size_written = 4 * REG_SIZE;
375cab3d4673922e2beb1f86f59c6aef17f55da3ac2Jason Ekstrand   bld.CMP(bld.null_reg_f(), offset(src_reg(dest), 8, 2), zero, BRW_CONDITIONAL_GE);
3768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
3788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
3798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add        dest+2  src0    src1
3808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: tex rlen 4 dest+0  src2
3818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 2: cmp.ge.f0  null    dest+2  0.0f
3828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
3838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
3848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
3858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
3868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
3888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
3898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
3918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(2, block0->end_ip);
3928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
3948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
3958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
3968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(2, block0->end_ip);
3978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
3988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NONE, instruction(block0, 0)->conditional_mod);
3998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(SHADER_OPCODE_TEX, instruction(block0, 1)->opcode);
4008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NONE, instruction(block0, 0)->conditional_mod);
4018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 2)->opcode);
4028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 2)->conditional_mod);
4038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
4048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, intervening_flag_read_same_value)
4068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
4078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
4088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest0 = dst_reg(v, glsl_type::float_type);
4098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest1 = dst_reg(v, glsl_type::float_type);
4108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
4118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
4128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src2 = src_reg(v, glsl_type::float_type);
413f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
4148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
4158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest_null.writemask = WRITEMASK_X;
4168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   set_condmod(BRW_CONDITIONAL_GE, bld.ADD(dest0, src0, src1));
4188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   set_predicate(BRW_PREDICATE_NORMAL, bld.SEL(dest1, src2, zero));
4198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest_null, src_reg(dest0), zero, BRW_CONDITIONAL_GE);
4208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
4228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
4238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add.ge.f0  dest0   src0  src1
4248fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: (+f0) sel  dest1   src2  0.0f
4258fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 2: cmp.ge.f0  null.x  dest0 0.0f
4268fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
4278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
4288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add.ge.f0  dest0 src0  src1
4298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: (+f0) sel  dest1 src2  0.0f
4308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
4318fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4328fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
4338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
4348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
4368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(2, block0->end_ip);
4378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_TRUE(cmod_propagation(v));
4398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
4408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
4418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
4428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 0)->conditional_mod);
4438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_SEL, instruction(block0, 1)->opcode);
4448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_PREDICATE_NORMAL, instruction(block0, 1)->predicate);
4458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
4468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, negate)
4488fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
4498fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
4508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::float_type);
4518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
4528fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
453f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
4548fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.ADD(dest, src0, src1);
4558fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg tmp_src = src_reg(dest);
4568fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   tmp_src.negate = true;
4578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
4588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest_null.writemask = WRITEMASK_X;
4598fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest_null, tmp_src, zero, BRW_CONDITIONAL_GE);
4608fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
4628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
4638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add        dest     src0  src1
4648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.ge.f0  null.x  -dest 0.0f
4658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
4668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
4678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add.le.f0  dest     src0  src1
4688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
4698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
4718fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
4728fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
4748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
4758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_TRUE(cmod_propagation(v));
4778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
4788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->end_ip);
4798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
4808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_LE, instruction(block0, 0)->conditional_mod);
4818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
4828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, movnz)
4848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
4858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
4868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::float_type);
4878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
4888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::float_type);
4898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
4908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest_null.writemask = WRITEMASK_X;
4918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest, src0, src1, BRW_CONDITIONAL_L);
4938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   set_condmod(BRW_CONDITIONAL_NZ,
4948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro               bld.MOV(dest_null, src_reg(dest)));
4958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
4968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
4978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
4988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: cmp.l.f0  dest:F  src0:F  src1:F
4998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: mov.nz.f0 null.x  dest:F
5008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
5018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
5028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: cmp.l.f0  dest  src0:F  src1:F
5038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
5048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
5068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
5078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
5098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
5108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_TRUE(cmod_propagation(v));
5128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
5148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->end_ip);
5158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 0)->opcode);
5168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_L, instruction(block0, 0)->conditional_mod);
5178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
5188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, different_types_cmod_with_zero)
5208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
5218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
5228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::int_type);
5238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::int_type);
5248fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::int_type);
525f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
5268fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.ADD(dest, src0, src1);
5278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_f(), retype(src_reg(dest), BRW_REGISTER_TYPE_F), zero,
5288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro           BRW_CONDITIONAL_GE);
5298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
5318fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
5328fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: add        dest:D  src0:D  src1:D
5338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.ge.f0  null:F  dest:F  0.0f
5348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
5358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
5368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
5378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
5388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
5408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
5418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
5438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
5448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
5468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
5488fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
5498fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
5508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
5518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 1)->conditional_mod);
5528fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
5538fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5548fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, andnz_non_one)
5558fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
5568fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
5578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::int_type);
5588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::float_type);
559f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
560f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg nonone(brw_imm_d(38));
5618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(retype(dest, BRW_REGISTER_TYPE_F), src0, zero, BRW_CONDITIONAL_L);
5638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   set_condmod(BRW_CONDITIONAL_NZ,
5648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro               bld.AND(bld.null_reg_d(), src_reg(dest), nonone));
5658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
5678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: cmp.l.f0     dest:F  src0:F  0F
5688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: and.nz.f0    null:D  dest:D  38D
5698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
5708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
5718fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
5728fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
5738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
5758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
5768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
5788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
5798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
5818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
5838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
5848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 0)->opcode);
5858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_L, instruction(block0, 0)->conditional_mod);
5868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_AND, instruction(block0, 1)->opcode);
5878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NZ, instruction(block0, 1)->conditional_mod);
5888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
5898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
5908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro/* Note that basic is using glsl_type:float types, while this one is using
5918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro * glsl_type::vec4 */
5928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, basic_vec4)
5938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
5948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
5958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::vec4_type);
5968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::vec4_type);
5978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::vec4_type);
598f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
5998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.MUL(dest, src0, src1);
6018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_f(), src_reg(dest), zero, BRW_CONDITIONAL_NZ);
6028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
6048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: mul         dest.xyzw  src0.xyzw  src1.xyzw
6058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.nz.f0.0 null.xyzw  dest.xyzw  0.0f
6068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
6078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
6088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: mul.nz.f0.0 dest.xyzw  src0.xyzw  src1.xyzw
6098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
6108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
6128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
6138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
6158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
6168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_TRUE(cmod_propagation(v));
6188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
6208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->end_ip);
6218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_MUL, instruction(block0, 0)->opcode);
6228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NZ, instruction(block0, 0)->conditional_mod);
6238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
6248fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6258fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, basic_vec4_different_dst_writemask)
6268fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
6278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
6288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::vec4_type);
6298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest.writemask = WRITEMASK_X;
6308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::vec4_type);
6318fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::vec4_type);
632f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
6338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
6348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.MUL(dest, src0, src1);
6368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest_null, src_reg(dest), zero, BRW_CONDITIONAL_NZ);
6378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
6398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: mul         dest.x  src0  src1
6408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.nz.f0.0 null    dest  0.0f
6418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
6428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
6438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (no changes)
6448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
6458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
6478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
6488fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6498fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
6508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
6518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6528fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
6538fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6548fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
6558fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
6568fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_MUL, instruction(block0, 0)->opcode);
6578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NONE, instruction(block0, 0)->conditional_mod);
6588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
6598fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NZ, instruction(block0, 1)->conditional_mod);
6608fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
6618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, mad_one_component_vec4)
6638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
6648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
6658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::vec4_type);
6668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest.writemask = WRITEMASK_X;
6678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::vec4_type);
6688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::vec4_type);
6698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src2 = src_reg(v, glsl_type::vec4_type);
6708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src0.swizzle = src1.swizzle = src2.swizzle = BRW_SWIZZLE_XXXX;
6718fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src2.negate = true;
672f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
6738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg tmp(dest);
6748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   tmp.swizzle = BRW_SWIZZLE_XXXX;
6758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
6768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest_null.writemask = WRITEMASK_X;
6778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.MAD(dest, src0, src1, src2);
6798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest_null, tmp, zero, BRW_CONDITIONAL_L);
6808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
6828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
6838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: mad         dest.x:F  src0.xxxx:F  src10.xxxx:F  -src2.xxxx:F
6848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.l.f0.0  null.x:F  dest.xxxx:F  0.0f
6858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
6868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
6878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: mad.l.f0    dest.x:F  src0.xxxx:F  src10.xxxx:F  -src2.xxxx:F
6888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
6898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
6918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
6928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
6948fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
6958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_TRUE(cmod_propagation(v));
6978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
6988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
6998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->end_ip);
7008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_MAD, instruction(block0, 0)->opcode);
7018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_L, instruction(block0, 0)->conditional_mod);
7028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
7038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, mad_more_one_component_vec4)
7058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
7068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
7078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::vec4_type);
7088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest.writemask = WRITEMASK_XW;
7098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::vec4_type);
7108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::vec4_type);
7118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src2 = src_reg(v, glsl_type::vec4_type);
7128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src0.swizzle = src1.swizzle = src2.swizzle = BRW_SWIZZLE_XXXX;
7138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src2.negate = true;
714f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
7158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg tmp(dest);
7168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   tmp.swizzle = BRW_SWIZZLE_XXXX;
7178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_f();
7188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.MAD(dest, src0, src1, src2);
7208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest_null, tmp, zero, BRW_CONDITIONAL_L);
7218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
7238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
7248fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: mad         dest.xw:F  src0.xxxx:F  src10.xxxx:F  -src2.xxxx:F
7258fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.l.f0.0  null:F  dest.xxxx:F  zeroF
7268fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
7278fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
7288fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (No changes)
7298fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
7308fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7318fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
7328fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
7338fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7348fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
7358fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
7368fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7378fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
7388fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7398fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
7408fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
7418fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_MAD, instruction(block0, 0)->opcode);
7428fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NONE, instruction(block0, 0)->conditional_mod);
7438fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
7448fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_L, instruction(block0, 1)->conditional_mod);
7458fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
7468fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7478fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, cmp_mov_vec4)
7488fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
7498fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
7508fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::ivec4_type);
7518fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest.writemask = WRITEMASK_X;
7528fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::ivec4_type);
7538fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src0.swizzle = BRW_SWIZZLE_XXXX;
7548fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src0.file = UNIFORM;
755f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg nonone = retype(brw_imm_d(16), BRW_REGISTER_TYPE_D);
7568fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg mov_src = src_reg(dest);
7578fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   mov_src.swizzle = BRW_SWIZZLE_XXXX;
7588fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest_null = bld.null_reg_d();
7598fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dest_null.writemask = WRITEMASK_X;
7608fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7618fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(dest, src0, nonone, BRW_CONDITIONAL_GE);
7628fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   set_condmod(BRW_CONDITIONAL_NZ,
7638fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro               bld.MOV(dest_null, mov_src));
7648fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7658fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
7668fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
7678fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: cmp.ge.f0  dest.x:D  u.xxxx:D  16D
7688fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: mov.nz.f0  null.x:D  dest.xxxx:D
7698fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
7708fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
7718fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: cmp.ge.f0  dest.x:D  u.xxxx:D  16D
7728fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
7738fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7748fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
7758fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
7768fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7778fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
7788fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
7798fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7808fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_TRUE(cmod_propagation(v));
7818fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7828fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
7838fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->end_ip);
7848fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 0)->opcode);
7858fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 0)->conditional_mod);
7868fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
7878fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7888fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro PiñeiroTEST_F(cmod_propagation_test, mul_cmp_different_channels_vec4)
7898fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro{
7908fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   const vec4_builder bld = vec4_builder(v).at_end();
7918fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   dst_reg dest = dst_reg(v, glsl_type::vec4_type);
7928fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src0 = src_reg(v, glsl_type::vec4_type);
7938fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg src1 = src_reg(v, glsl_type::vec4_type);
794f9a9ba5eac2f1934bd7fecc92cd309f22411164bMatt Turner   src_reg zero(brw_imm_f(0.0f));
7958fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   src_reg cmp_src = src_reg(dest);
7968fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   cmp_src.swizzle = BRW_SWIZZLE4(0,1,3,2);
7978fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
7988fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.MUL(dest, src0, src1);
7998fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bld.CMP(bld.null_reg_f(), cmp_src, zero, BRW_CONDITIONAL_NZ);
8008fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
8018fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   /* = Before =
8028fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 0: mul         dest  src0       src1
8038fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * 1: cmp.nz.f0.0 null  dest.xywz  0.0f
8048fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    *
8058fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * = After =
8068fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    * (No changes)
8078fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro    */
8088fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
8098fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   v->calculate_cfg();
8108fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   bblock_t *block0 = v->cfg->blocks[0];
8118fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
8128fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(0, block0->start_ip);
8138fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(1, block0->end_ip);
8148fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
8158fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_FALSE(cmod_propagation(v));
8168fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro
8178fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(0, block0->start_ip);
8188fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   ASSERT_EQ(1, block0->end_ip);
8198fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_MUL, instruction(block0, 0)->opcode);
8208fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NONE, instruction(block0, 0)->conditional_mod);
8218fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
8228fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro   EXPECT_EQ(BRW_CONDITIONAL_NZ, instruction(block0, 1)->conditional_mod);
8238fc8fcc04f584b32cd5bf633da8e3508249e339dAlejandro Piñeiro}
824