Path: blob/21.2-virgl/src/amd/compiler/tests/test_insert_nops.cpp
7099 views
/*1* Copyright © 2020 Valve Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*22*/23#include "helpers.h"2425using namespace aco;2627void create_mubuf(unsigned offset)28{29bld.mubuf(aco_opcode::buffer_load_dword, Definition(PhysReg(256), v1), Operand(PhysReg(0), s4),30Operand(PhysReg(256), v1), Operand::zero(), offset, true);31}3233void create_mimg(bool nsa, unsigned addrs, unsigned instr_dwords)34{35aco_ptr<MIMG_instruction> mimg{create_instruction<MIMG_instruction>(36aco_opcode::image_sample, Format::MIMG, 3 + addrs, 1)};37mimg->definitions[0] = Definition(PhysReg(256), v1);38mimg->operands[0] = Operand(PhysReg(0), s8);39mimg->operands[1] = Operand(PhysReg(0), s4);40mimg->operands[2] = Operand(v1);41for (unsigned i = 0; i < addrs; i++)42mimg->operands[3 + i] = Operand(PhysReg(256 + (nsa ? i * 2 : i)), v1);43mimg->dmask = 0x1;44mimg->dim = ac_image_2d;4546assert(get_mimg_nsa_dwords(mimg.get()) + 2 == instr_dwords);4748bld.insert(std::move(mimg));49}5051BEGIN_TEST(insert_nops.nsa_to_vmem_bug)52if (!setup_cs(NULL, GFX10))53return;5455/* no nop needed because offset&6==0 */56//>> p_unit_test 057//! v1: %0:v[0] = image_sample %0:s[0-7], %0:s[0-3], v1: undef, %0:v[0], %0:v[2], %0:v[4], %0:v[6], %0:v[8], %0:v[10] 2d storage: semantics: scope:invocation58//! v1: %0:v[0] = buffer_load_dword %0:s[0-3], %0:v[0], 0 offset:8 offen storage: semantics: scope:invocation59bld.pseudo(aco_opcode::p_unit_test, Operand::zero());60create_mimg(true, 6, 4);61create_mubuf(8);6263/* nop needed */64//! p_unit_test 165//! v1: %0:v[0] = image_sample %0:s[0-7], %0:s[0-3], v1: undef, %0:v[0], %0:v[2], %0:v[4], %0:v[6], %0:v[8], %0:v[10] 2d storage: semantics: scope:invocation66//! s_nop67//! v1: %0:v[0] = buffer_load_dword %0:s[0-3], %0:v[0], 0 offset:4 offen storage: semantics: scope:invocation68bld.pseudo(aco_opcode::p_unit_test, Operand::c32(1u));69create_mimg(true, 6, 4);70create_mubuf(4);7172/* no nop needed because the MIMG is not NSA */73//! p_unit_test 274//! v1: %0:v[0] = image_sample %0:s[0-7], %0:s[0-3], v1: undef, %0:v[0], %0:v[1], %0:v[2], %0:v[3], %0:v[4], %0:v[5] 2d storage: semantics: scope:invocation75//! v1: %0:v[0] = buffer_load_dword %0:s[0-3], %0:v[0], 0 offset:4 offen storage: semantics: scope:invocation76bld.pseudo(aco_opcode::p_unit_test, Operand::c32(2u));77create_mimg(false, 6, 2);78create_mubuf(4);7980/* no nop needed because there's already an instruction in-between */81//! p_unit_test 382//! v1: %0:v[0] = image_sample %0:s[0-7], %0:s[0-3], v1: undef, %0:v[0], %0:v[2], %0:v[4], %0:v[6], %0:v[8], %0:v[10] 2d storage: semantics: scope:invocation83//! v_nop84//! v1: %0:v[0] = buffer_load_dword %0:s[0-3], %0:v[0], 0 offset:4 offen storage: semantics: scope:invocation85bld.pseudo(aco_opcode::p_unit_test, Operand::c32(3u));86create_mimg(true, 6, 4);87bld.vop1(aco_opcode::v_nop);88create_mubuf(4);8990/* no nop needed because the NSA instruction is under 4 dwords */91//! p_unit_test 492//! v1: %0:v[0] = image_sample %0:s[0-7], %0:s[0-3], v1: undef, %0:v[0], %0:v[2] 2d storage: semantics: scope:invocation93//! v1: %0:v[0] = buffer_load_dword %0:s[0-3], %0:v[0], 0 offset:4 offen storage: semantics: scope:invocation94bld.pseudo(aco_opcode::p_unit_test, Operand::c32(4u));95create_mimg(true, 2, 3);96create_mubuf(4);9798/* NSA instruction and MUBUF/MTBUF in a different block */99//! p_unit_test 5100//! v1: %0:v[0] = image_sample %0:s[0-7], %0:s[0-3], v1: undef, %0:v[0], %0:v[2], %0:v[4], %0:v[6], %0:v[8], %0:v[10] 2d storage: semantics: scope:invocation101//! BB1102//! /* logical preds: / linear preds: BB0, / kind: uniform, */103//! s_nop104//! v1: %0:v[0] = buffer_load_dword %0:s[0-3], %0:v[0], 0 offset:4 offen storage: semantics: scope:invocation105bld.pseudo(aco_opcode::p_unit_test, Operand::c32(5u));106create_mimg(true, 6, 4);107bld.reset(program->create_and_insert_block());108create_mubuf(4);109program->blocks[0].linear_succs.push_back(1);110program->blocks[1].linear_preds.push_back(0);111112finish_insert_nops_test();113END_TEST114115BEGIN_TEST(insert_nops.writelane_to_nsa_bug)116if (!setup_cs(NULL, GFX10))117return;118119/* nop needed */120//>> p_unit_test 0121//! v1: %0:v[255] = v_writelane_b32_e64 0, 0, %0:v[255]122//! s_nop123//! v1: %0:v[0] = image_sample %0:s[0-7], %0:s[0-3], v1: undef, %0:v[0], %0:v[2] 2d storage: semantics: scope:invocation124bld.pseudo(aco_opcode::p_unit_test, Operand::zero());125bld.writelane(Definition(PhysReg(511), v1), Operand::zero(), Operand::zero(),126Operand(PhysReg(511), v1));127create_mimg(true, 2, 3);128129/* no nop needed because the MIMG is not NSA */130//! p_unit_test 1131//! v1: %0:v[255] = v_writelane_b32_e64 0, 0, %0:v[255]132//! v1: %0:v[0] = image_sample %0:s[0-7], %0:s[0-3], v1: undef, %0:v[0], %0:v[1] 2d storage: semantics: scope:invocation133bld.pseudo(aco_opcode::p_unit_test, Operand::c32(1u));134bld.writelane(Definition(PhysReg(511), v1), Operand::zero(), Operand::zero(),135Operand(PhysReg(511), v1));136create_mimg(false, 2, 2);137138/* no nop needed because there's already an instruction in-between */139//! p_unit_test 2140//! v1: %0:v[255] = v_writelane_b32_e64 0, 0, %0:v[255]141//! v_nop142//! v1: %0:v[0] = image_sample %0:s[0-7], %0:s[0-3], v1: undef, %0:v[0], %0:v[2] 2d storage: semantics: scope:invocation143bld.pseudo(aco_opcode::p_unit_test, Operand::c32(2u));144bld.writelane(Definition(PhysReg(511), v1), Operand::zero(), Operand::zero(),145Operand(PhysReg(511), v1));146bld.vop1(aco_opcode::v_nop);147create_mimg(true, 2, 3);148149/* writelane and NSA instruction in different blocks */150//! p_unit_test 3151//! v1: %0:v[255] = v_writelane_b32_e64 0, 0, %0:v[255]152//! BB1153//! /* logical preds: / linear preds: BB0, / kind: uniform, */154//! s_nop155//! v1: %0:v[0] = image_sample %0:s[0-7], %0:s[0-3], v1: undef, %0:v[0], %0:v[2] 2d storage: semantics: scope:invocation156bld.pseudo(aco_opcode::p_unit_test, Operand::c32(3u));157bld.writelane(Definition(PhysReg(511), v1), Operand::zero(), Operand::zero(),158Operand(PhysReg(511), v1));159bld.reset(program->create_and_insert_block());160create_mimg(true, 2, 3);161program->blocks[0].linear_succs.push_back(1);162program->blocks[1].linear_preds.push_back(0);163164finish_insert_nops_test();165END_TEST166167168