From 268158a758551a46feb120af3f3cff5fb9292310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Wed, 1 Sep 2021 18:28:51 +0200 Subject: [PATCH] aco/optimize_postRA: Use iterators instead of operator[] of std::array. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Rhys Perry Reviewed-by: Tony Wasserka Reviewed-by: Joshua Ashton Part-of: --- src/amd/compiler/aco_optimizer_postRA.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/amd/compiler/aco_optimizer_postRA.cpp b/src/amd/compiler/aco_optimizer_postRA.cpp index 4c385174b0b..c24c0fadd72 100644 --- a/src/amd/compiler/aco_optimizer_postRA.cpp +++ b/src/amd/compiler/aco_optimizer_postRA.cpp @@ -112,8 +112,8 @@ save_reg_writes(pr_opt_ctx& ctx, aco_ptr& 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