transition_to_WQM(ctx, bld, block->index);
ctx.info[block->index].exec.back().second &= ~mask_type_global;
}
- unsigned num = ctx.info[block->index].exec.size();
+ int num = ctx.info[block->index].exec.size();
assert(num);
Operand cond = instr->operands[0];
- instr.reset(create_instruction<Pseudo_instruction>(aco_opcode::p_discard_if, Format::PSEUDO, num + 1, num + 1));
- for (unsigned i = 0; i < num; i++) {
- instr->operands[i] = Operand(ctx.info[block->index].exec[i].first);
- if (i == num - 1)
- instr->operands[i].setFixed(exec);
- Temp new_mask = bld.tmp(s2);
- instr->definitions[i] = Definition(new_mask);
- ctx.info[block->index].exec[i].first = new_mask;
+ for (int i = num - 1; i >= 0; i--) {
+ Instruction *andn2 = bld.sop2(aco_opcode::s_andn2_b64, bld.def(s2), bld.def(s1, scc),
+ ctx.info[block->index].exec[i].first, cond);
+ if (i == num - 1) {
+ andn2->operands[0].setFixed(exec);
+ andn2->definitions[0].setFixed(exec);
+ }
+ if (i == 0) {
+ instr->opcode = aco_opcode::p_exit_early_if;
+ instr->operands[0] = bld.scc(andn2->definitions[1].getTemp());
+ }
+ ctx.info[block->index].exec[i].first = andn2->definitions[0].getTemp();
}
- assert((ctx.info[block->index].exec[0].second & mask_type_wqm) == 0);
- instr->definitions[num - 1].setFixed(exec);
- instr->operands[num] = cond;
- instr->definitions[num] = bld.def(s1, scc);
+ assert(!ctx.handle_wqm || (ctx.info[block->index].exec[0].second & mask_type_wqm) == 0);
} else if (needs == WQM && state != WQM) {
transition_to_WQM(ctx, bld, block->index);
num = 1;
}
- for (unsigned i = 0; i < ctx.info[block->index].exec.size() - 1; i++)
- num += ctx.info[block->index].exec[i].second & mask_type_exact ? 1 : 0;
- instr.reset(create_instruction<Instruction>(aco_opcode::p_discard_if, Format::PSEUDO, num + 1, num + 1));
- int k = 0;
- for (unsigned i = 0; k < num; i++) {
+ num += ctx.info[block->index].exec.size() - 1;
+ for (int i = num - 1; i >= 0; i--) {
if (ctx.info[block->index].exec[i].second & mask_type_exact) {
- instr->operands[k] = Operand(ctx.info[block->index].exec[i].first);
- Temp new_mask = bld.tmp(s2);
- instr->definitions[k] = Definition(new_mask);
- if (i == ctx.info[block->index].exec.size() - 1)
- instr->definitions[k].setFixed(exec);
- k++;
- ctx.info[block->index].exec[i].first = new_mask;
+ Instruction *andn2 = bld.sop2(aco_opcode::s_andn2_b64, bld.def(s2), bld.def(s1, scc),
+ ctx.info[block->index].exec[i].first, cond);
+ if (i == num - 1) {
+ andn2->operands[0].setFixed(exec);
+ andn2->definitions[0].setFixed(exec);
+ }
+ if (i == 0) {
+ instr->opcode = aco_opcode::p_exit_early_if;
+ instr->operands[0] = bld.scc(andn2->definitions[1].getTemp());
+ }
+ ctx.info[block->index].exec[i].first = andn2->definitions[0].getTemp();
+ } else {
+ assert(i != 0);
}
}
- assert(k == num);
- instr->definitions[num] = bld.def(s1, scc);
- instr->operands[num] = Operand(cond);
state = Exact;
} else if (instr->opcode == aco_opcode::p_fs_buffer_store_smem) {
bld.exec(Definition(new_exec)), Operand(0u), bld.exec(old_exec));
ctx.info[idx].exec.back().first = new_exec;
- aco_ptr<Pseudo_instruction> discard{create_instruction<Pseudo_instruction>(aco_opcode::p_discard_if, Format::PSEUDO, num + 1, num + 1)};
- for (unsigned i = 0; i < num; i++) {
- discard->operands[i] = Operand(ctx.info[block->index].exec[i].first);
- Temp new_mask = bld.tmp(s2);
- discard->definitions[i] = Definition(new_mask);
- ctx.info[block->index].exec[i].first = new_mask;
+ for (int i = num - 1; i >= 0; i--) {
+ Instruction *andn2 = bld.sop2(aco_opcode::s_andn2_b64, bld.def(s2), bld.def(s1, scc),
+ ctx.info[block->index].exec[i].first, cond);
+ if (i == 0)
+ bld.pseudo(aco_opcode::p_exit_early_if, bld.scc(andn2->definitions[1].getTemp()));
+ ctx.info[block->index].exec[i].first = andn2->definitions[0].getTemp();
}
assert(!ctx.handle_wqm || (ctx.info[block->index].exec[0].second & mask_type_wqm) == 0);
- discard->operands[num] = Operand(cond);
- discard->definitions[num] = bld.def(s1, scc);
- bld.insert(std::move(discard));
if ((block->kind & (block_kind_break | block_kind_uniform)) == block_kind_break)
ctx.info[idx].exec.back().first = cond;
bld.insert(std::move(branch));
handle_operands(copy_operations, &ctx, program->chip_class, pi);
break;
}
- case aco_opcode::p_discard_if:
+ case aco_opcode::p_exit_early_if:
{
- bool early_exit = false;
- if (block->instructions[j + 1]->opcode != aco_opcode::p_logical_end ||
- block->instructions[j + 2]->opcode != aco_opcode::s_endpgm) {
- early_exit = true;
+ /* don't bother with an early exit at the end of the program */
+ if (block->instructions[j + 1]->opcode == aco_opcode::p_logical_end &&
+ block->instructions[j + 2]->opcode == aco_opcode::s_endpgm) {
+ break;
}
- if (early_exit && !discard_block) {
+ if (!discard_block) {
discard_block = program->create_and_insert_block();
block = &program->blocks[i];
bld.reset(&ctx.instructions);
}
- // TODO: optimize uniform conditions
- Definition branch_cond = instr->definitions.back();
- Operand discard_cond = instr->operands.back();
- aco_ptr<Instruction> sop2;
- /* backwards, to finally branch on the global exec mask */
- for (int i = instr->operands.size() - 2; i >= 0; i--) {
- bld.sop2(aco_opcode::s_andn2_b64,
- instr->definitions[i], /* new mask */
- branch_cond, /* scc */
- instr->operands[i], /* old mask */
- discard_cond);
- }
-
- if (early_exit) {
- bld.sopp(aco_opcode::s_cbranch_scc0, bld.scc(branch_cond.getTemp()), discard_block->index);
+ //TODO: exec can be zero here with block_kind_discard
- discard_block->linear_preds.push_back(block->index);
- block->linear_succs.push_back(discard_block->index);
- }
+ assert(instr->operands[0].physReg() == scc);
+ bld.sopp(aco_opcode::s_cbranch_scc0, instr->operands[0], discard_block->index);
+ discard_block->linear_preds.push_back(block->index);
+ block->linear_succs.push_back(discard_block->index);
break;
}
case aco_opcode::p_spill: