diff --git a/src/compiler/nir/nir_loop_analyze.c b/src/compiler/nir/nir_loop_analyze.c index 0568d058784..9064030f19f 100644 --- a/src/compiler/nir/nir_loop_analyze.c +++ b/src/compiler/nir/nir_loop_analyze.c @@ -423,7 +423,6 @@ compute_induction_information(loop_info_state *state) nir_phi_instr *phi = nir_instr_as_phi(var->def->parent_instr); nir_basic_induction_var *biv = rzalloc(state, nir_basic_induction_var); - nir_src *init_src = NULL; nir_loop_variable *alu_src_var = NULL; nir_foreach_phi_src(src, phi) { nir_loop_variable *src_var = get_loop_var(src->src.ssa, state); @@ -448,9 +447,8 @@ compute_induction_information(loop_info_state *state) } } - if (!src_var->in_loop && !biv->def_outside_loop) { - biv->def_outside_loop = src_var->def; - init_src = &src->src; + if (!src_var->in_loop && !var->init_src) { + var->init_src = &src->src; } else if (is_var_alu(src_var) && !var->update_src) { alu_src_var = src_var; nir_alu_instr *alu = nir_instr_as_alu(src_var->def->parent_instr); @@ -480,8 +478,8 @@ compute_induction_information(loop_info_state *state) } } - if (var->update_src && biv->def_outside_loop) { - nir_instr *inst = biv->def_outside_loop->parent_instr; + if (var->update_src && var->init_src) { + nir_instr *inst = var->init_src->ssa->parent_instr; if (inst->type == nir_instr_type_load_const) { /* Initial value of induction variable is a constant */ alu_src_var->init_src = var->init_src; @@ -493,20 +491,20 @@ compute_induction_information(loop_info_state *state) found_induction_var = true; num_induction_vars += 2; - } else if (is_only_uniform_src(init_src)) { + } else if (is_only_uniform_src(var->init_src)) { /* Initial value of induction variable is a uniform */ - var->init_src = init_src; - alu_src_var->init_src = var->init_src; alu_src_var->update_src = var->update_src; num_induction_vars += 2; ralloc_free(biv); } else { + var->init_src = NULL; var->update_src = NULL; ralloc_free(biv); } } else { + var->init_src = NULL; var->update_src = NULL; ralloc_free(biv); } @@ -1195,13 +1193,12 @@ find_trip_count(loop_info_state *state, unsigned execution_mode) */ nir_loop_variable *lv = get_loop_var(basic_ind.def, state); - nir_basic_induction_var *ind_var = lv->ind; /* The basic induction var might be a vector but, because we guarantee * earlier that the phi source has a scalar swizzle, we can take the * component from basic_ind. */ - nir_ssa_scalar initial_s = { ind_var->def_outside_loop, basic_ind.comp }; + nir_ssa_scalar initial_s = { lv->init_src->ssa, basic_ind.comp }; nir_ssa_scalar alu_s = { lv->update_src->src.ssa, lv->update_src->swizzle[basic_ind.comp] diff --git a/src/compiler/nir/tests/loop_analyze_tests.cpp b/src/compiler/nir/tests/loop_analyze_tests.cpp index f0769cec9a5..b4a9cb5c0e8 100644 --- a/src/compiler/nir/tests/loop_analyze_tests.cpp +++ b/src/compiler/nir/tests/loop_analyze_tests.cpp @@ -248,15 +248,15 @@ TEST_F(nir_loop_analyze_test, infinite_loop_feq) EXPECT_EQ(2, loop->info->num_induction_vars); ASSERT_NE((void *)0, loop->info->induction_vars); - /* Since the initializer is a constant, the init_src field will be - * NULL. The def field should not be NULL. The update_src field should - * point to a load_const. + /* The def field should not be NULL. The init_src field should point to a + * load_const. The update_src field should point to a load_const. */ const nir_loop_induction_variable *const ivars = loop->info->induction_vars; for (unsigned i = 0; i < loop->info->num_induction_vars; i++) { EXPECT_NE((void *)0, ivars[i].def); - EXPECT_EQ((void *)0, ivars[i].init_src); + ASSERT_NE((void *)0, ivars[i].init_src); + EXPECT_TRUE(nir_src_is_const(*ivars[i].init_src)); ASSERT_NE((void *)0, ivars[i].update_src); EXPECT_TRUE(nir_src_is_const(ivars[i].update_src->src)); } @@ -330,15 +330,15 @@ TEST_F(nir_loop_analyze_test, zero_iterations_ine) EXPECT_EQ(2, loop->info->num_induction_vars); ASSERT_NE((void *)0, loop->info->induction_vars); - /* Since the initializer is a constant, the init_src field will be - * NULL. The def field should not be NULL. The update_src field should - * point to a load_const. + /* The def field should not be NULL. The init_src field should point to a + * load_const. The update_src field should point to a load_const. */ const nir_loop_induction_variable *const ivars = loop->info->induction_vars; for (unsigned i = 0; i < loop->info->num_induction_vars; i++) { EXPECT_NE((void *)0, ivars[i].def); - EXPECT_EQ((void *)0, ivars[i].init_src); + ASSERT_NE((void *)0, ivars[i].init_src); + EXPECT_TRUE(nir_src_is_const(*ivars[i].init_src)); ASSERT_NE((void *)0, ivars[i].update_src); EXPECT_TRUE(nir_src_is_const(ivars[i].update_src->src)); } @@ -409,15 +409,15 @@ TEST_F(nir_loop_analyze_test, one_iteration_uge) EXPECT_EQ(2, loop->info->num_induction_vars); ASSERT_NE((void *)0, loop->info->induction_vars); - /* Since the initializer is a constant, the init_src field will be - * NULL. The def field should not be NULL. The update_src field should - * point to a load_const. + /* The def field should not be NULL. The init_src field should point to a + * load_const. The update_src field should point to a load_const. */ const nir_loop_induction_variable *const ivars = loop->info->induction_vars; for (unsigned i = 0; i < loop->info->num_induction_vars; i++) { EXPECT_NE((void *)0, ivars[i].def); - EXPECT_EQ((void *)0, ivars[i].init_src); + ASSERT_NE((void *)0, ivars[i].init_src); + EXPECT_TRUE(nir_src_is_const(*ivars[i].init_src)); ASSERT_NE((void *)0, ivars[i].update_src); EXPECT_TRUE(nir_src_is_const(ivars[i].update_src->src)); } @@ -488,15 +488,15 @@ TEST_F(nir_loop_analyze_test, one_iteration_ine) EXPECT_EQ(2, loop->info->num_induction_vars); ASSERT_NE((void *)0, loop->info->induction_vars); - /* Since the initializer is a constant, the init_src field will be - * NULL. The def field should not be NULL. The update_src field should - * point to a load_const. + /* The def field should not be NULL. The init_src field should point to a + * load_const. The update_src field should point to a load_const. */ const nir_loop_induction_variable *const ivars = loop->info->induction_vars; for (unsigned i = 0; i < loop->info->num_induction_vars; i++) { EXPECT_NE((void *)0, ivars[i].def); - EXPECT_EQ((void *)0, ivars[i].init_src); + ASSERT_NE((void *)0, ivars[i].init_src); + EXPECT_TRUE(nir_src_is_const(*ivars[i].init_src)); ASSERT_NE((void *)0, ivars[i].update_src); EXPECT_TRUE(nir_src_is_const(ivars[i].update_src->src)); } @@ -567,15 +567,15 @@ TEST_F(nir_loop_analyze_test, one_iteration_ieq) EXPECT_EQ(2, loop->info->num_induction_vars); ASSERT_NE((void *)0, loop->info->induction_vars); - /* Since the initializer is a constant, the init_src field will be - * NULL. The def field should not be NULL. The update_src field should - * point to a load_const. + /* The def field should not be NULL. The init_src field should point to a + * load_const. The update_src field should point to a load_const. */ const nir_loop_induction_variable *const ivars = loop->info->induction_vars; for (unsigned i = 0; i < loop->info->num_induction_vars; i++) { EXPECT_NE((void *)0, ivars[i].def); - EXPECT_EQ((void *)0, ivars[i].init_src); + ASSERT_NE((void *)0, ivars[i].init_src); + EXPECT_TRUE(nir_src_is_const(*ivars[i].init_src)); ASSERT_NE((void *)0, ivars[i].update_src); EXPECT_TRUE(nir_src_is_const(ivars[i].update_src->src)); } @@ -646,15 +646,15 @@ TEST_F(nir_loop_analyze_test, one_iteration_easy_fneu) EXPECT_EQ(2, loop->info->num_induction_vars); ASSERT_NE((void *)0, loop->info->induction_vars); - /* Since the initializer is a constant, the init_src field will be - * NULL. The def field should not be NULL. The update_src field should - * point to a load_const. + /* The def field should not be NULL. The init_src field should point to a + * load_const. The update_src field should point to a load_const. */ const nir_loop_induction_variable *const ivars = loop->info->induction_vars; for (unsigned i = 0; i < loop->info->num_induction_vars; i++) { EXPECT_NE((void *)0, ivars[i].def); - EXPECT_EQ((void *)0, ivars[i].init_src); + ASSERT_NE((void *)0, ivars[i].init_src); + EXPECT_TRUE(nir_src_is_const(*ivars[i].init_src)); ASSERT_NE((void *)0, ivars[i].update_src); EXPECT_TRUE(nir_src_is_const(ivars[i].update_src->src)); } @@ -730,15 +730,15 @@ TEST_F(nir_loop_analyze_test, one_iteration_fneu) EXPECT_EQ(2, loop->info->num_induction_vars); ASSERT_NE((void *)0, loop->info->induction_vars); - /* Since the initializer is a constant, the init_src field will be - * NULL. The def field should not be NULL. The update_src field should - * point to a load_const. + /* The def field should not be NULL. The init_src field should point to a + * load_const. The update_src field should point to a load_const. */ const nir_loop_induction_variable *const ivars = loop->info->induction_vars; for (unsigned i = 0; i < loop->info->num_induction_vars; i++) { EXPECT_NE((void *)0, ivars[i].def); - EXPECT_EQ((void *)0, ivars[i].init_src); + ASSERT_NE((void *)0, ivars[i].init_src); + EXPECT_TRUE(nir_src_is_const(*ivars[i].init_src)); ASSERT_NE((void *)0, ivars[i].update_src); EXPECT_TRUE(nir_src_is_const(ivars[i].update_src->src)); } @@ -811,15 +811,15 @@ TEST_F(nir_loop_analyze_test, zero_iterations_ine_inverted) EXPECT_EQ(2, loop->info->num_induction_vars); ASSERT_NE((void *)0, loop->info->induction_vars); - /* Since the initializer is a constant, the init_src field will be - * NULL. The def field should not be NULL. The update_src field should - * point to a load_const. + /* The def field should not be NULL. The init_src field should point to a + * load_const. The update_src field should point to a load_const. */ const nir_loop_induction_variable *const ivars = loop->info->induction_vars; for (unsigned i = 0; i < loop->info->num_induction_vars; i++) { EXPECT_NE((void *)0, ivars[i].def); - EXPECT_EQ((void *)0, ivars[i].init_src); + ASSERT_NE((void *)0, ivars[i].init_src); + EXPECT_TRUE(nir_src_is_const(*ivars[i].init_src)); ASSERT_NE((void *)0, ivars[i].update_src); EXPECT_TRUE(nir_src_is_const(ivars[i].update_src->src)); } @@ -892,15 +892,15 @@ TEST_F(nir_loop_analyze_test, five_iterations_ige_inverted) EXPECT_EQ(2, loop->info->num_induction_vars); ASSERT_NE((void *)0, loop->info->induction_vars); - /* Since the initializer is a constant, the init_src field will be - * NULL. The def field should not be NULL. The update_src field should - * point to a load_const. + /* The def field should not be NULL. The init_src field should point to a + * load_const. The update_src field should point to a load_const. */ const nir_loop_induction_variable *const ivars = loop->info->induction_vars; for (unsigned i = 0; i < loop->info->num_induction_vars; i++) { EXPECT_NE((void *)0, ivars[i].def); - EXPECT_EQ((void *)0, ivars[i].init_src); + ASSERT_NE((void *)0, ivars[i].init_src); + EXPECT_TRUE(nir_src_is_const(*ivars[i].init_src)); ASSERT_NE((void *)0, ivars[i].update_src); EXPECT_TRUE(nir_src_is_const(ivars[i].update_src->src)); }