diff options
-rw-r--r-- | src/ir/properties.h | 8 | ||||
-rw-r--r-- | test/passes/optimize-instructions_all-features.txt | 13 | ||||
-rw-r--r-- | test/passes/optimize-instructions_all-features.wast | 13 |
3 files changed, 34 insertions, 0 deletions
diff --git a/src/ir/properties.h b/src/ir/properties.h index 1331eeb73..b86032ba0 100644 --- a/src/ir/properties.h +++ b/src/ir/properties.h @@ -132,6 +132,10 @@ inline Literals getLiterals(const Expression* curr) { // Check if an expression is a sign-extend, and if so, returns the value // that is extended, otherwise nullptr inline Expression* getSignExtValue(Expression* curr) { + // We only care about i32s here, and ignore i64s, unreachables, etc. + if (curr->type != Type::i32) { + return nullptr; + } using namespace Match; int32_t leftShift = 0, rightShift = 0; Expression* extended = nullptr; @@ -184,6 +188,10 @@ inline Index getAlmostSignExtBits(Expression* curr, Index& extraLeftShifts) { // Check if an expression is a zero-extend, and if so, returns the value // that is extended, otherwise nullptr inline Expression* getZeroExtValue(Expression* curr) { + // We only care about i32s here, and ignore i64s, unreachables, etc. + if (curr->type != Type::i32) { + return nullptr; + } using namespace Match; int32_t mask = 0; Expression* extended = nullptr; diff --git a/test/passes/optimize-instructions_all-features.txt b/test/passes/optimize-instructions_all-features.txt index a093fbffa..677b220cb 100644 --- a/test/passes/optimize-instructions_all-features.txt +++ b/test/passes/optimize-instructions_all-features.txt @@ -969,6 +969,19 @@ (i32.const 0) ) ) + (drop + (if (result i32) + (i32.shr_s + (i32.shl + (unreachable) + (i32.const 16) + ) + (i32.const 16) + ) + (i32.const 111) + (i32.const 222) + ) + ) ) (func $sign-ext-input (param $0 i32) (param $1 i32) (drop diff --git a/test/passes/optimize-instructions_all-features.wast b/test/passes/optimize-instructions_all-features.wast index 3b25238c0..d90dd7aeb 100644 --- a/test/passes/optimize-instructions_all-features.wast +++ b/test/passes/optimize-instructions_all-features.wast @@ -805,6 +805,19 @@ (i32.const 0) ) ) + (drop + (if (result i32) + (i32.shr_s + (i32.shl + (unreachable) ;; ignore an unreachable value + (i32.const 16) + ) + (i32.const 16) + ) + (i32.const 111) + (i32.const 222) + ) + ) ) (func $sign-ext-input (param $0 i32) (param $1 i32) (drop |