ShaderLang icon indicating copy to clipboard operation
ShaderLang copied to clipboard

[Feature] Handle absorbing constant propagation

Open SirLynix opened this issue 3 years ago • 0 comments

Currently, constant propagation on binary expressions requires to know both operands, but there are cases than can be optimized when knowing only one operand:

  • a + 0 -> a
  • 0 + a -> a
  • a - 0 -> a
  • 0 - a -> -a
  • -(-a) -> a
  • 0 * a -> 0
  • a * 0 -> 0
  • 1 * a -> a
  • a * 1 -> a
  • a / 1 -> a (only with integers, because of NaN/inf)
  • a / a -> 1 (only with integers, because of NaN/inf, no need to handle 0 / 0 as it's UB anyway)
  • a && true -> a
  • a && false -> false
  • a || true -> true
  • a || false -> a
  • a < 0 -> false (only with unsigned integers)
  • a >= 0 -> true (only with unsigned integers)
  • a == NaN -> false
  • a == a -> true (only with integers, because of NaN/inf)
  • a != a -> false (only with integers, because of NaN/inf)
  • x * po2 -> x << sqrt(po2)
  • x / po2 -> x >> sqrt(po2)

This will become more important once function inlining is implemented.

SirLynix avatar Jun 21 '22 06:06 SirLynix