glsl: fix the type of ir_constant_data::u16
[mesa.git] / src / compiler / glsl / opt_conditional_discard.cpp
index 1ca8803f643a43acaffdf1eb7838025c4563651f..6d8a23460d9a34e9e4d2def40c6f0646c14cbcee 100644 (file)
@@ -65,14 +65,21 @@ opt_conditional_discard_visitor::visit_leave(ir_if *ir)
 {
    /* 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;