From 0c1ebc63ca26980cf5ee445ddb5bcfb94f78fab7 Mon Sep 17 00:00:00 2001 From: Job Noorman Date: Sun, 31 Aug 2025 17:48:52 +0200 Subject: [PATCH] ir3/cf: don't swap signedness of (sat) instructions Signed and unsigned saturation give different results. Signed-off-by: Job Noorman Fixes: e894e83e478 ("ir3/cf: Rewrite pass") Part-of: --- src/freedreno/ir3/ir3_cf.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/freedreno/ir3/ir3_cf.c b/src/freedreno/ir3/ir3_cf.c index d41682e028f..71696397b06 100644 --- a/src/freedreno/ir3/ir3_cf.c +++ b/src/freedreno/ir3/ir3_cf.c @@ -9,7 +9,8 @@ #include "ir3_shader.h" static bool -is_safe_conv(struct ir3_instruction *instr, type_t src_type, opc_t *src_opc) +is_safe_conv(struct ir3_instruction *instr, type_t src_type, opc_t *src_opc, + struct ir3_instruction *src_instr) { if (instr->opc != OPC_MOV) return false; @@ -66,6 +67,12 @@ is_safe_conv(struct ir3_instruction *instr, type_t src_type, opc_t *src_opc) if (type_size(instr->cat1.dst_type) < type_size(instr->cat1.src_type)) return true; + /* Don't swap opcodes when the result is saturated as signed and unsigned + * saturation give different results. + */ + if (src_instr->flags & IR3_INSTR_SAT) + return false; + /* Try swapping the opcode: */ bool can_swap = true; *src_opc = ir3_try_swap_signedness(*src_opc, &can_swap); @@ -79,7 +86,7 @@ all_uses_safe_conv(struct ir3_instruction *conv_src, type_t src_type) bool first = true; foreach_ssa_use (use, conv_src) { opc_t new_opc = opc; - if (!is_safe_conv(use, src_type, &new_opc)) + if (!is_safe_conv(use, src_type, &new_opc, conv_src)) return false; /* Check if multiple uses have conflicting requirements on the opcode. */