Mesa (main): aco: combine additions and constants into scratch load/store
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Jul 8 15:29:36 UTC 2022
Module: Mesa
Branch: main
Commit: 52934f6cdb86f0292a42da8a68038c3dda06d763
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=52934f6cdb86f0292a42da8a68038c3dda06d763
Author: Rhys Perry <pendingchaos02 at gmail.com>
Date: Thu May 19 15:19:12 2022 +0100
aco: combine additions and constants into scratch load/store
Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Daniel Schürmann <daniel at schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17079>
---
src/amd/compiler/aco_optimizer.cpp | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/src/amd/compiler/aco_optimizer.cpp b/src/amd/compiler/aco_optimizer.cpp
index 87d824b8f8b..f8ceb61f276 100644
--- a/src/amd/compiler/aco_optimizer.cpp
+++ b/src/amd/compiler/aco_optimizer.cpp
@@ -1233,6 +1233,20 @@ is_op_canonicalized(opt_ctx& ctx, Operand op)
return false;
}
+bool
+is_scratch_offset_valid(opt_ctx& ctx, Instruction* instr, int32_t offset)
+{
+ bool negative_unaligned_scratch_offset_bug = ctx.program->gfx_level == GFX10;
+ int32_t min = ctx.program->dev.scratch_global_offset_min;
+ int32_t max = ctx.program->dev.scratch_global_offset_max;
+
+ bool has_vgpr_offset = instr && !instr->operands[0].isUndefined();
+ if (negative_unaligned_scratch_offset_bug && has_vgpr_offset && offset < 0 && offset % 4)
+ return false;
+
+ return offset >= min && offset <= max;
+}
+
void
label_instruction(opt_ctx& ctx, aco_ptr<Instruction>& instr)
{
@@ -1416,6 +1430,30 @@ label_instruction(opt_ctx& ctx, aco_ptr<Instruction>& instr)
}
}
+ /* SCRATCH: propagate constants and combine additions */
+ else if (instr->isScratch()) {
+ FLAT_instruction& scratch = instr->scratch();
+ Temp base;
+ uint32_t offset;
+ while (info.is_temp())
+ info = ctx.info[info.temp.id()];
+
+ if (i <= 1 && parse_base_offset(ctx, instr.get(), i, &base, &offset, false) &&
+ base.regClass() == instr->operands[i].regClass() &&
+ is_scratch_offset_valid(ctx, instr.get(), scratch.offset + (int32_t)offset)) {
+ instr->operands[i].setTemp(base);
+ scratch.offset += (int32_t)offset;
+ continue;
+ } else if (i <= 1 && info.is_constant_or_literal(32) &&
+ ctx.program->gfx_level >= GFX10_3 &&
+ is_scratch_offset_valid(ctx, NULL, scratch.offset + (int32_t)info.val)) {
+ /* GFX10.3+ can disable both SADDR and ADDR. */
+ instr->operands[i] = Operand(instr->operands[i].regClass());
+ scratch.offset += (int32_t)info.val;
+ continue;
+ }
+ }
+
/* DS: combine additions */
else if (instr->isDS()) {
More information about the mesa-commit
mailing list