aco/ra: fix usage of invalidated iterator
authorRhys Perry <pendingchaos02@gmail.com>
Wed, 11 May 2022 14:10:22 +0000 (15:10 +0100)
committerMarge Bot <emma+marge@anholt.net>
Mon, 30 May 2022 16:41:32 +0000 (16:41 +0000)
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Fixes: 58bd9a379ef ("aco/ra: fix live-range splits of phi definitions")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16454>

src/amd/compiler/aco_register_allocation.cpp

index 5cd2928..b9ed0c7 100644 (file)
@@ -2120,7 +2120,10 @@ get_regs_for_phis(ra_ctx& ctx, Block& block, RegisterFile& register_file,
    }
 
    /* find registers for phis where the register was blocked or no operand was assigned */
-   for (aco_ptr<Instruction>& phi : instructions) {
+
+   /* Don't use iterators because get_reg_phi() can add phis to the end of the vector. */
+   for (unsigned i = 0; i < instructions.size(); i++) {
+      aco_ptr<Instruction>& phi = instructions[i];
       Definition& definition = phi->definitions[0];
       if (definition.isFixed())
          continue;