blob: b4870e0da8ad2fdf92274cfb3a5ebbabb6792f14 [file] [log] [blame]
uniform half4 colorRed, colorGreen;
uniform half unknownInput;
bool test() {
bool expr = unknownInput > 0;
int ok = 0, bad = 0;
// Test boolean short-circuiting with constants on the left side.
if (true && expr) { ++ok; } else { ++bad; } // -> (expr)
if (false && expr) { ++bad; } else { ++ok; } // -> (false) -> block removed
if (true ^^ expr) { ++bad; } else { ++ok; } // -> unchanged
if (false ^^ expr) { ++ok; } else { ++bad; } // -> (expr)
if (true || expr) { ++ok; } else { ++bad; } // -> (true)
if (false || expr) { ++ok; } else { ++bad; } // -> (expr)
if (true == expr) { ++ok; } else { ++bad; } // -> (expr)
if (false == expr) { ++bad; } else { ++ok; } // -> unchanged
if (true != expr) { ++bad; } else { ++ok; } // -> unchanged
if (false != expr) { ++ok; } else { ++bad; } // -> (expr)
// Test boolean short-circuiting with constants on the right side.
if (expr && true ) { ++ok; } else { ++bad; } // -> (expr)
if (expr && false) { ++bad; } else { ++ok; } // -> (false) -> block removed
if (expr ^^ true ) { ++bad; } else { ++ok; } // -> unchanged
if (expr ^^ false) { ++ok; } else { ++bad; } // -> (expr)
if (expr || true ) { ++ok; } else { ++bad; } // -> (true)
if (expr || false) { ++ok; } else { ++bad; } // -> (expr)
if (expr == true ) { ++ok; } else { ++bad; } // -> (expr)
if (expr == false) { ++bad; } else { ++ok; } // -> unchanged
if (expr != true ) { ++bad; } else { ++ok; } // -> unchanged
if (expr != false) { ++ok; } else { ++bad; } // -> (expr)
// Test that side-effects in the left-side expression prevent right-side expr elimination.
float a = sqrt(1), b = sqrt(2);
true || bool(a = b); // -> true
if (a == b) { ++bad; } else { ++ok; }
bool(a = b) || true; // -> unchanged
if (a == b) { ++ok; } else { ++bad; }
return ok == 22 && bad == 0;
}
half4 main() {
return test() ? colorGreen : colorRed;
}