diff options
author | Alon Zakai <azakai@google.com> | 2023-11-13 17:00:12 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-13 17:00:12 -0800 |
commit | c0d19024c7b11ccb30d452d81d3c32252d6bc924 (patch) | |
tree | 66aed0d82601ed98bbb43d1f75c9fb796db4f52d /test/lit/passes/optimize-instructions-mvp.wast | |
parent | 84f51cd5af96ef4d9e157452d98965301251016a (diff) | |
download | binaryen-c0d19024c7b11ccb30d452d81d3c32252d6bc924.tar.gz binaryen-c0d19024c7b11ccb30d452d81d3c32252d6bc924.tar.bz2 binaryen-c0d19024c7b11ccb30d452d81d3c32252d6bc924.zip |
OptimizeAddedConstants: Handle a final added constant properly (#6115)
We had an assert there that was wrong. In fact the assert is just in one of two code paths,
and an optional one: the end situation is we have an expression and a constant to add to it,
and the assert was in the case that the expression is a Const so we can do the add at
compile time (the other code path does the add at runtime). This code path is optional as
Precompute would do such compile-time addition anyhow, but it is nice to fix and leave that
path so that this pass emits fully optimal code.
Diffstat (limited to 'test/lit/passes/optimize-instructions-mvp.wast')
-rw-r--r-- | test/lit/passes/optimize-instructions-mvp.wast | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/lit/passes/optimize-instructions-mvp.wast b/test/lit/passes/optimize-instructions-mvp.wast index 953ccd37c..550db4094 100644 --- a/test/lit/passes/optimize-instructions-mvp.wast +++ b/test/lit/passes/optimize-instructions-mvp.wast @@ -16949,4 +16949,29 @@ ) ) ) + + ;; CHECK: (func $added-constants-remaining-constant (result i32) + ;; CHECK-NEXT: (i32.const 32) + ;; CHECK-NEXT: ) + (func $added-constants-remaining-constant (result i32) + ;; optimizeAddedConstants will simplify this step by step and end up with + ;; both an accumulated value and a constant to add it to (the 1 at the + ;; bottom). We should not hit an assert here and return the proper value, + ;; 32. (This is tricky for optimizeAddedConstants because of the shift that + ;; does nothing, which it correctly ignores, but it also leads to having + ;; something to add at the very end of the process.) + (i32.sub ;; This subtracts 33 by 1 to get 32. + (i32.add ;; This adds 1 to 32 to get 33. + (i32.shl ;; This shift by 32 does nothing, so it is 1. + (i32.const 1) + (i32.add ;; This is 32 + (i32.const 0) + (i32.const 32) + ) + ) + (i32.const 32) + ) + (i32.const 1) + ) + ) ) |