Problem
Two small conditional simplifications pslua does not do:
- Short-circuit fusion:
if p then B else false → p && B, if p then true else q → p || q for a cheap q, fusing nested one-armed conditionals into &&/||.
not through ordering: not (a < b) → a >= b for every ordering comparison. pslua pushes not through ==/~= (foldNotEqual) and cancels double negation (foldPrimNot), but leaves not (a < b) and the other three orderings wrapped.
Approach
Two peephole-local rewrites in IR/Optimizer.hs:
- extend the
not-pushing fold to the four ordering primops (<, <=, >, >=), each flipping to its complement;
- add the short-circuit fusions for
if p then _ else false and if p then true else _, gated so the fused branch is cheap by the isInlinableExpr test and evaluation order is preserved in the strict setting.
Prerequisites / Relations
Independent. Adjacent to the residual-conditional folds from #180: #220 (fold Eq through a literal conditional), #222 (fold ordering on ASCII Char literals), #223 (collapse Boolean matches). This adds the operator-level simplifications those folds do not reach. None block the others.
Verification / Measurement
not (a < b) reduces to a >= b, and if p then q else false to p && q, in focused optimizer tests; a fusion whose folded branch is non-trivial is left alone (the evaluation-order guard). Eval goldens unchanged; structural goldens shrink where these shapes occur.
Problem
Two small conditional simplifications pslua does not do:
if p then B else false → p && B,if p then true else q → p || qfor a cheapq, fusing nested one-armed conditionals into&&/||.notthrough ordering:not (a < b) → a >= bfor every ordering comparison. pslua pushesnotthrough==/~=(foldNotEqual) and cancels double negation (foldPrimNot), but leavesnot (a < b)and the other three orderings wrapped.Approach
Two peephole-local rewrites in
IR/Optimizer.hs:not-pushing fold to the four ordering primops (<,<=,>,>=), each flipping to its complement;if p then _ else falseandif p then true else _, gated so the fused branch is cheap by theisInlinableExprtest and evaluation order is preserved in the strict setting.Prerequisites / Relations
Independent. Adjacent to the residual-conditional folds from #180: #220 (fold
Eqthrough a literal conditional), #222 (fold ordering on ASCIICharliterals), #223 (collapse Boolean matches). This adds the operator-level simplifications those folds do not reach. None block the others.Verification / Measurement
not (a < b)reduces toa >= b, andif p then q else falsetop && q, in focused optimizer tests; a fusion whose folded branch is non-trivial is left alone (the evaluation-order guard). Eval goldens unchanged; structural goldens shrink where these shapes occur.