}
};
+class nir_opt_dead_cf_test : public nir_test {
+protected:
+ nir_opt_dead_cf_test()
+ : nir_test::nir_test("nir_opt_dead_cf_test")
+ {
+ }
+};
+
nir_phi_instr *create_one_source_phi(nir_shader *shader, nir_block *pred,
nir_ssa_def *def)
{
nir_validate_shader(b->shader, NULL);
}
+
+TEST_F(nir_opt_dead_cf_test, jump_before_constant_if)
+{
+ /*
+ * Test that nir_opt_dead_cf removes everything after the jump, instead of trying and failing to
+ * stitch b0 and b3.
+ *
+ * block b0: // preds:
+ * 1 %0 = load_const (false)
+ * return
+ * // succs: b4
+ * if %0 (false) {
+ * block b1: // preds:
+ * 32 %1 = load_const (0x00000001)
+ * 32 %2 = deref_var &out (shader_out int)
+ * @store_deref (%2, %1 (0x1)) (wrmask=x, access=0)
+ * // succs: b3
+ * } else {
+ * block b2: // preds: , succs: b3
+ * }
+ * block b3: // preds: b1 b2
+ * 32 %3 = load_const (0x00000000)
+ * 32 %4 = deref_var &out (shader_out int)
+ * @store_deref (%4, %3 (0x0)) (wrmask=x, access=0)
+ * // succs: b4
+ * block b4:
+ */
+ nir_variable *var = nir_variable_create(b->shader, nir_var_shader_out, glsl_int_type(), "out");
+
+ nir_ssa_def *cond = nir_imm_false(b);
+ nir_jump(b, nir_jump_return);
+ nir_push_if(b, cond);
+ nir_store_var(b, var, nir_imm_int(b, 1), 0x1);
+ nir_pop_if(b, NULL);
+
+ nir_store_var(b, var, nir_imm_int(b, 0), 0x1);
+
+ ASSERT_TRUE(nir_opt_dead_cf(b->shader));
+
+ nir_validate_shader(b->shader, NULL);
+}