Title: Boolean peephole: short-circuit fusion and push `not` through all ordering comparisons · Issue #238 · purescript-lua/purescript-lua · GitHub
Open Graph Title: Boolean peephole: short-circuit fusion and push `not` through all ordering comparisons · Issue #238 · purescript-lua/purescript-lua
X Title: Boolean peephole: short-circuit fusion and push `not` through all ordering comparisons · Issue #238 · purescript-lua/purescript-lua
Description: 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: ...
Open Graph Description: 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 conditi...
X Description: 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...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/238
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Boolean peephole: short-circuit fusion and push `not` through all ordering comparisons","articleBody":"## Problem\n\nTwo small conditional simplifications pslua does not do:\n\n- **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 `&&`/`||`.\n- **`not` through ordering**: `not (a \u003c b) → a >= b` for every ordering comparison. pslua pushes `not` through `==`/`~=` (`foldNotEqual`) and cancels double negation (`foldPrimNot`), but leaves `not (a \u003c b)` and the other three orderings wrapped.\n\n## Approach\n\nTwo peephole-local rewrites in `IR/Optimizer.hs`:\n\n- extend the `not`-pushing fold to the four ordering primops (`\u003c`, `\u003c=`, `>`, `>=`), each flipping to its complement;\n- 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.\n\n## Prerequisites / Relations\n\nIndependent. 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.\n\n## Verification / Measurement\n\n`not (a \u003c 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.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-11T12:02:48Z","url":"https://github.com/purescript-lua/purescript-lua/issues/238"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f5497037-3327-c144-2684-f6fa5719678a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 821A:2AAD2E:70F2DD:98B5B1:6B00DB6D |
| html-safe-nonce | 741cbcd62059791ba70b77c1523b9355b5384e51688e409e3d6b56537fd72661 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjFBOjJBQUQyRTo3MEYyREQ6OThCNUIxOjZCMDBEQjZEIiwidmlzaXRvcl9pZCI6IjU2MzMzNTU5ODcxNDM0MTY2ODUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 488e9ac5d7a7fdb1d2ecb81cedaea07f03263d51b8ae7f82be291f5cca03f379 |
| hovercard-subject-tag | issue:4862140429 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/purescript-lua/purescript-lua/238/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fb1606ad1ec9b54c9fb9b60a6d852dbc172145cb9ee6c80b89e3725e4edef985/purescript-lua/purescript-lua/issues/238 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fb1606ad1ec9b54c9fb9b60a6d852dbc172145cb9ee6c80b89e3725e4edef985/purescript-lua/purescript-lua/issues/238 |
| og:image:alt | 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 conditi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Unisay |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| turbo-cache-control | no-preview |
| go-import | github.com/purescript-lua/purescript-lua git https://github.com/purescript-lua/purescript-lua.git |
| octolytics-dimension-user_id | 131581790 |
| octolytics-dimension-user_login | purescript-lua |
| octolytics-dimension-repository_id | 587200487 |
| octolytics-dimension-repository_nwo | purescript-lua/purescript-lua |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 587200487 |
| octolytics-dimension-repository_network_root_nwo | purescript-lua/purescript-lua |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width