vkd3d-shader/hlsl: Implement simplification of associative and commutative binary expressions.
The simplification process applies the following rewrite rules, if OP is associative:
(x OP y) OP z -> x OP (y OP z), if (y OP z) simplifies
x OP (y OP z) -> (x OP y) OP z, if (x OP y) simplifies
And the following rewrite rule, if OP is commutative, c is a constant, and x is a non-constant:
c OP x -> x OP c
For example, the following HLSL
uint x;
float4 main() : sv_target
{
return 3 + (4 * x * 5) - 6 + 7;
}
gets simplified to
2: uint | x[0c]
3: uint | 20
4: uint | * (@2 @3 )
5: uint | 4
6: uint | + (@4 @5 )
7: float | cast (@6 )
8: float4 | @7.xxxx
9: | = (<output-sv_target0>[0c] @8)
Edited by Shaun Ren