{
/* Look for "if (...) discard" with no else clause or extra statements. */
if (ir->then_instructions.is_empty() ||
- !ir->then_instructions.head->next->is_tail_sentinel() ||
- !((ir_instruction *) ir->then_instructions.head)->as_discard() ||
+ !ir->then_instructions.get_head_raw()->next->is_tail_sentinel() ||
+ !((ir_instruction *) ir->then_instructions.get_head_raw())->as_discard() ||
!ir->else_instructions.is_empty())
return visit_continue;
/* Move the condition and replace the ir_if with the ir_discard. */
- ir_discard *discard = (ir_discard *) ir->then_instructions.head;
- discard->condition = ir->condition;
+ ir_discard *discard = (ir_discard *) ir->then_instructions.get_head_raw();
+ if (!discard->condition)
+ discard->condition = ir->condition;
+ else {
+ void *ctx = ralloc_parent(ir);
+ discard->condition = new(ctx) ir_expression(ir_binop_logic_and,
+ ir->condition,
+ discard->condition);
+ }
ir->replace_with(discard);
progress = true;