vkd3d-shader/hlsl: Fold some general unary and ternary expressions.
The following identities are applied:
||x|| -> |x|
|-x| -> |x|
~(~x) -> x
f(g(x)) -> g(x), where f, g are floor or ceil functions
-(-x) -> x
!!x -> x
!(x == y) -> x != y, !(x < y) -> x >= y, etc.
c ? x : x -> x
false ? x : y -> y; true ? x : y -> x
c ? true : false -> c; c ? false : true -> !c
!c ? x : y -> c ? y : x
Lastly, for expression chains x
, y
in a conditional expression
c ? x : y,
we evaluate all conditionals in the expression
chains with the condition c
, assuming c
is true (for x
), or
false (for y
).
The ternary identities can be helpful in simplifying the IR generated from conditional branch flattening.
Edited by Shaun Ren