Conversation
…n ops Add four new algebraic simplification rules based on De Morgan's laws: Bitwise: - bnot(a) & bnot(b) → bnot(a | b) (saves one i64.xor instruction) - bnot(a) | bnot(b) → bnot(a & b) (saves one i64.xor instruction) Boolean: - not(a) and not(b) → not(a or b) (saves one i32.eqz instruction) - not(a) or not(b) → not(a and b) (saves one i32.eqz instruction) These transformations reduce two negation operations to one while preserving semantic equivalence, producing smaller and faster WASM output for bitwise-heavy code patterns. Includes 10 new tests covering unit, complex sub-expression, negative (no-op), and end-to-end pipeline cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add four new algebraic simplification rules based on De Morgan's laws to the optimizer.
Bitwise De Morgan's Laws
bnot(a) & bnot(b)→bnot(a | b)— saves onei64.xorinstructionbnot(a) | bnot(b)→bnot(a & b)— saves onei64.xorinstructionBoolean De Morgan's Laws
not(a) and not(b)→not(a or b)— saves onei32.eqzinstructionnot(a) or not(b)→not(a and b)— saves onei32.eqzinstructionThese transformations reduce two negation operations to one while preserving semantic equivalence, producing smaller and faster WASM output for bitwise-heavy code patterns.
Changes
lib/firebird/compiler/optimizer.ex— 4 new pattern-match clauses inalgebraic_simplify/1, updated moduledoctest/compiler/optimizer_algebraic_test.exs— 10 new tests (unit, complex sub-expressions, negative/no-op, and end-to-end pipeline)Test Results