brw_inst_set_jip(devinfo, if_inst, br * (else_inst - if_inst + 1));
/* The IF instruction's UIP and ELSE's JIP should point to ENDIF */
brw_inst_set_uip(devinfo, if_inst, br * (endif_inst - if_inst));
- brw_inst_set_jip(devinfo, else_inst, br * (endif_inst - else_inst));
+
+ if (devinfo->ver >= 8 && devinfo->ver < 11) {
+ /* Set the ELSE instruction to use branch_ctrl with a join
+ * jump target pointing at the NOP inserted right before
+ * the ENDIF instruction in order to make sure it is
+ * executed in all cases, since attempting to do the same
+ * as on other generations could cause the EU to jump at
+ * the instruction immediately after the ENDIF due to
+ * Wa_220160235, which could cause the program to continue
+ * running with all channels disabled.
+ */
+ brw_inst_set_jip(devinfo, else_inst, br * (endif_inst - else_inst - 1));
+ brw_inst_set_branch_control(devinfo, else_inst, true);
+ } else {
+ brw_inst_set_jip(devinfo, else_inst, br * (endif_inst - else_inst));
+ }
+
if (devinfo->ver >= 8) {
- /* Since we don't set branch_ctrl, the ELSE's JIP and UIP both
- * should point to ENDIF.
+ /* Since we don't set branch_ctrl on Gfx11+, the ELSE's
+ * JIP and UIP both should point to ENDIF on those
+ * platforms.
*/
brw_inst_set_uip(devinfo, else_inst, br * (endif_inst - else_inst));
}
brw_inst *tmp;
bool emit_endif = true;
+ assert(p->if_stack_depth > 0);
+
+ if (devinfo->ver >= 8 && devinfo->ver < 11 &&
+ brw_inst_opcode(p->isa, &p->store[p->if_stack[
+ p->if_stack_depth - 1]]) == BRW_OPCODE_ELSE) {
+ /* Insert a NOP to be specified as join instruction within the
+ * ELSE block, which is valid for an ELSE instruction with
+ * branch_ctrl on. The ELSE instruction will be set to jump
+ * here instead of to the ENDIF instruction, since attempting to
+ * do the latter would prevent the ENDIF from being executed in
+ * some cases due to Wa_220160235, which could cause the program
+ * to continue running with all channels disabled.
+ */
+ brw_NOP(p);
+ }
+
/* In single program flow mode, we can express IF and ELSE instructions
* equivalently as ADD instructions that operate on IP. On platforms prior
* to Gfx6, flow control instructions cause an implied thread switch, so