aco/optimize_postRA: Use iterators instead of operator[] of std::array.
authorTimur Kristóf <timur.kristof@gmail.com>
Wed, 1 Sep 2021 16:28:51 +0000 (18:28 +0200)
committerMarge Bot <eric+marge@anholt.net>
Fri, 3 Sep 2021 15:00:55 +0000 (15:00 +0000)
Also add a few more assertions to make sure the registers are
within the bounds of the array.

Cc: mesa-stable
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Tony Wasserka <tony.wasserka@gmx.de>
Reviewed-by: Joshua Ashton <joshua@froggi.es>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12682>

src/amd/compiler/aco_optimizer_postRA.cpp

index 4c385174b0b16fc3f7613c800407bf64d52aea91..c24c0fadd7258ce3314a54472df2ee24f494923c 100644 (file)
@@ -112,8 +112,8 @@ save_reg_writes(pr_opt_ctx& ctx, aco_ptr<Instruction>& instr)
 
       assert((r + dw_size) <= max_reg_cnt);
       assert(def.size() == dw_size || def.regClass().is_subdword());
-      std::fill(&ctx.instr_idx_by_regs[ctx.current_block->index][r],
-                &ctx.instr_idx_by_regs[ctx.current_block->index][r] + dw_size, idx);
+      std::fill(ctx.instr_idx_by_regs[ctx.current_block->index].begin() + r,
+                ctx.instr_idx_by_regs[ctx.current_block->index].begin() + r + dw_size, idx);
    }
 }
 
@@ -121,11 +121,12 @@ Idx
 last_writer_idx(pr_opt_ctx& ctx, PhysReg physReg, RegClass rc)
 {
    /* Verify that all of the operand's registers are written by the same instruction. */
+   assert(physReg.reg() < max_reg_cnt);
    Idx instr_idx = ctx.instr_idx_by_regs[ctx.current_block->index][physReg.reg()];
    unsigned dw_size = DIV_ROUND_UP(rc.bytes(), 4u);
    unsigned r = physReg.reg();
-   bool all_same = std::all_of(&ctx.instr_idx_by_regs[ctx.current_block->index][r],
-                               &ctx.instr_idx_by_regs[ctx.current_block->index][r + dw_size],
+   bool all_same = std::all_of(ctx.instr_idx_by_regs[ctx.current_block->index].begin() + r,
+                               ctx.instr_idx_by_regs[ctx.current_block->index].begin() + r + dw_size,
                                [instr_idx](Idx i) { return i == instr_idx; });
 
    return all_same ? instr_idx : written_by_multiple_instrs;
@@ -137,6 +138,7 @@ last_writer_idx(pr_opt_ctx& ctx, const Operand& op)
    if (op.isConstant() || op.isUndefined())
       return const_or_undef;
 
+   assert(op.physReg().reg() < max_reg_cnt);
    Idx instr_idx = ctx.instr_idx_by_regs[ctx.current_block->index][op.physReg().reg()];
 
 #ifndef NDEBUG