agx: fold zext into int sources

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32081>
This commit is contained in:
Alyssa Rosenzweig
2024-10-30 12:21:48 -04:00
committed by Marge Bot
parent 200d0794e2
commit 6d56c8bc02
+41 -1
View File
@@ -248,6 +248,35 @@ agx_optimizer_fmov_rev(agx_instr *I, agx_instr *use)
return true;
}
static bool
agx_supports_zext(agx_instr *I, unsigned s)
{
switch (I->op) {
case AGX_OPCODE_IADD:
case AGX_OPCODE_IMAD:
case AGX_OPCODE_ICMP:
case AGX_OPCODE_INTL:
case AGX_OPCODE_FFS:
case AGX_OPCODE_BITREV:
case AGX_OPCODE_BFI:
case AGX_OPCODE_BFEIL:
case AGX_OPCODE_EXTR:
case AGX_OPCODE_BITOP:
case AGX_OPCODE_WHILE_ICMP:
case AGX_OPCODE_IF_ICMP:
case AGX_OPCODE_ELSE_ICMP:
case AGX_OPCODE_BREAK_IF_ICMP:
case AGX_OPCODE_ICMP_BALLOT:
case AGX_OPCODE_ICMP_QUAD_BALLOT:
return true;
case AGX_OPCODE_ICMPSEL:
/* Only the comparisons can be extended, not the selection */
return s < 2;
default:
return false;
}
}
static void
agx_optimizer_copyprop(agx_context *ctx, agx_instr **defs, agx_instr *I)
{
@@ -264,7 +293,8 @@ agx_optimizer_copyprop(agx_context *ctx, agx_instr **defs, agx_instr *I)
* RA pseudo instructions don't handle size conversions. This should be
* refined in the future.
*/
if (def->src[0].size != src.size)
if (def->src[0].size != src.size &&
!(def->src[0].size < src.size && agx_supports_zext(I, s)))
continue;
/* Optimize split(64-bit uniform) so we can get better copyprop of the
@@ -301,6 +331,16 @@ agx_optimizer_copyprop(agx_context *ctx, agx_instr **defs, agx_instr *I)
continue;
agx_replace_src(I, s, def->src[0]);
/* If we are zero-extending into an instruction that distinguishes sign
* and zero extend, make sure we pick zero-extend.
*/
if (def->src[0].size < src.size &&
(I->op == AGX_OPCODE_IMAD || I->op == AGX_OPCODE_IADD)) {
assert(agx_supports_zext(I, s));
I->src[s].abs = true;
}
}
}