From: Rhys Perry Date: Fri, 22 Nov 2019 17:50:29 +0000 (+0000) Subject: aco: improve clamp optimization X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fa8357eb7008115413a9f3219e98a0f718687223;p=mesa.git aco: improve clamp optimization Not sure why it checked the use count, it doesn't apply the constants. pipeline-db (Navi): Totals from affected shaders: SGPRS: 269409 -> 269745 (0.12 %) VGPRS: 238120 -> 238132 (0.01 %) Spilled SGPRs: 305 -> 305 (0.00 %) Spilled VGPRs: 0 -> 0 (0.00 %) Code Size: 22908584 -> 22904672 (-0.02 %) bytes Max Waves: 20217 -> 20217 (0.00 %) Instructions: 4275312 -> 4263869 (-0.27 %) pipeline-db (Vega): Totals from affected shaders: SGPRS: 155409 -> 155233 (-0.11 %) VGPRS: 153072 -> 153072 (0.00 %) Spilled SGPRs: 269 -> 269 (0.00 %) Spilled VGPRs: 0 -> 0 (0.00 %) Code Size: 14650824 -> 14650396 (-0.00 %) bytes Max Waves: 9609 -> 9609 (0.00 %) Instructions: 2762802 -> 2755517 (-0.26 %) Signed-off-by: Rhys Perry Reviewed-by: Daniel Schürmann Part-of: --- diff --git a/src/amd/compiler/aco_optimizer.cpp b/src/amd/compiler/aco_optimizer.cpp index 44ce5289ff5..96fa17e62d8 100644 --- a/src/amd/compiler/aco_optimizer.cpp +++ b/src/amd/compiler/aco_optimizer.cpp @@ -1794,6 +1794,9 @@ bool get_minmax_info(aco_opcode op, aco_opcode *min, aco_opcode *max, aco_opcode bool combine_clamp(opt_ctx& ctx, aco_ptr& instr, aco_opcode min, aco_opcode max, aco_opcode med) { + /* TODO: GLSL's clamp(x, minVal, maxVal) and SPIR-V's + * FClamp(x, minVal, maxVal)/NClamp(x, minVal, maxVal) are undefined if + * minVal > maxVal, which means we can always select it to a v_med3_f32 */ aco_opcode other_op; if (instr->opcode == min) other_op = max; @@ -1818,8 +1821,7 @@ bool combine_clamp(opt_ctx& ctx, aco_ptr& instr, uint32_t val; if (operands[i].isConstant()) { val = operands[i].constantValue(); - } else if (operands[i].isTemp() && ctx.uses[operands[i].tempId()] == 1 && - ctx.info[operands[i].tempId()].is_constant_or_literal()) { + } else if (operands[i].isTemp() && ctx.info[operands[i].tempId()].is_constant_or_literal()) { val = ctx.info[operands[i].tempId()].val; } else { continue;