https://bugs.freedesktop.org/show_bug.cgi?id=111241
--- Comment #6 from Pierre-Eric Pelloux-Prayer pierre-eric.pelloux-prayer@amd.com --- I've created a different shadertoy showing the problem: https://www.shadertoy.com/view/Wt2SW1 (but this one doesn't hang the GPU).
The shader for "Buffer A" is:
0: MOV TEMP[0], SV[0] 1: MAD TEMP[0].y, SV[0], CONST[0][2].xxxx, CONST[0][2].yyyy 2: MOV OUT[0], IMM[0].xxxx 3: USEQ TEMP[1].x, CONST[0][1].xxxx, IMM[1].xxxx 4: UIF TEMP[1].xxxx 5: ADD TEMP[2], TEMP[2], -TEMP[2] 6: ELSE [...] 13: MOV OUT[0], TEMP[2] 14: END
TEMP[2] is used before being assigned a value, so I suppose that's what allows LLVM to turn line 5 in:
v_mov_b32_e32 v3, 0x7fc00000 v_mov_b32_e32 v2, 0x7fc00000 v_mov_b32_e32 v1, 0x7fc00000 v_mov_b32_e32 v0, 0x7fc00000
(ie: output is NaN)
A possible way to fix this is to transform "dst = x - x" operations in "dst = 0" which is what nir does in its nir_opt_algebraic pass.
I've open a MR to fix/discuss this issue: https://gitlab.freedesktop.org/mesa/mesa/merge_requests/1681