mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-01 18:20:10 +01:00
glsl: replace 'x + (-x)' with constant 0
This fixes a hang in shadertoy for radeonsi where a buffer was initialized with: value -= value with value being undefined. In this case LLVM replace the operation with an assignment to NaN. Cc: 19.1 19.2 <mesa-stable@lists.freedesktop.org> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=111241 Reviewed-by: Marek Olšák <marek.olsak@amd.com>
This commit is contained in:
parent
8d03a6b700
commit
47cc660d9c
1 changed files with 12 additions and 0 deletions
|
|
@ -507,6 +507,18 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
|
|||
if (is_vec_zero(op_const[1]))
|
||||
return ir->operands[0];
|
||||
|
||||
/* Replace (x + (-x)) with constant 0 */
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (op_expr[i]) {
|
||||
if (op_expr[i]->operation == ir_unop_neg) {
|
||||
ir_rvalue *other = ir->operands[(i + 1) % 2];
|
||||
if (other && op_expr[i]->operands[0]->equals(other)) {
|
||||
return ir_constant::zero(ir, ir->type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Reassociate addition of constants so that we can do constant
|
||||
* folding.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue