summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/OptimizeInstructions.cpp7
-rw-r--r--test/emcc_O2_hello_world.fromasm12
-rw-r--r--test/emcc_O2_hello_world.fromasm.imprecise12
-rw-r--r--test/memorygrowth.fromasm12
-rw-r--r--test/memorygrowth.fromasm.imprecise12
-rw-r--r--test/passes/optimize-instructions.txt10
-rw-r--r--test/passes/optimize-instructions.wast13
7 files changed, 42 insertions, 36 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index ef18ea777..561e7882c 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -468,6 +468,13 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
default: {}
}
}
+ // eqz of a sign extension can be of zero-extension
+ if (auto* ext = getSignExt(unary->value)) {
+ // we are comparing a sign extend to a constant, which means we can use a cheaper zext
+ auto bits = getSignExtBits(unary->value);
+ unary->value = makeZeroExt(ext, bits);
+ return unary;
+ }
}
} else if (auto* set = curr->dynCast<SetGlobal>()) {
// optimize out a set of a get
diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm
index 5aa32979b..599ecffb9 100644
--- a/test/emcc_O2_hello_world.fromasm
+++ b/test/emcc_O2_hello_world.fromasm
@@ -8555,15 +8555,9 @@
)
)
(if
- (i32.shr_s
- (i32.shl
- (i32.and
- (get_local $1)
- (i32.const 255)
- )
- (i32.const 24)
- )
- (i32.const 24)
+ (i32.and
+ (get_local $1)
+ (i32.const 255)
)
(block
(set_local $1
diff --git a/test/emcc_O2_hello_world.fromasm.imprecise b/test/emcc_O2_hello_world.fromasm.imprecise
index 39ed6731f..231af0290 100644
--- a/test/emcc_O2_hello_world.fromasm.imprecise
+++ b/test/emcc_O2_hello_world.fromasm.imprecise
@@ -8554,15 +8554,9 @@
)
)
(if
- (i32.shr_s
- (i32.shl
- (i32.and
- (get_local $1)
- (i32.const 255)
- )
- (i32.const 24)
- )
- (i32.const 24)
+ (i32.and
+ (get_local $1)
+ (i32.const 255)
)
(block
(set_local $1
diff --git a/test/memorygrowth.fromasm b/test/memorygrowth.fromasm
index ef7dc1a78..9f17a3cc4 100644
--- a/test/memorygrowth.fromasm
+++ b/test/memorygrowth.fromasm
@@ -8474,15 +8474,9 @@
)
)
(if
- (i32.shr_s
- (i32.shl
- (i32.and
- (get_local $1)
- (i32.const 255)
- )
- (i32.const 24)
- )
- (i32.const 24)
+ (i32.and
+ (get_local $1)
+ (i32.const 255)
)
(block
(set_local $1
diff --git a/test/memorygrowth.fromasm.imprecise b/test/memorygrowth.fromasm.imprecise
index 2a32f7528..914f119d1 100644
--- a/test/memorygrowth.fromasm.imprecise
+++ b/test/memorygrowth.fromasm.imprecise
@@ -8473,15 +8473,9 @@
)
)
(if
- (i32.shr_s
- (i32.shl
- (i32.and
- (get_local $1)
- (i32.const 255)
- )
- (i32.const 24)
- )
- (i32.const 24)
+ (i32.and
+ (get_local $1)
+ (i32.const 255)
)
(block
(set_local $1
diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt
index 25f2dfaa1..eddb2b6b3 100644
--- a/test/passes/optimize-instructions.txt
+++ b/test/passes/optimize-instructions.txt
@@ -1111,4 +1111,14 @@
)
)
)
+ (func $sign-ext-eqz (type $4) (param $0 i32) (param $1 i32)
+ (drop
+ (i32.eqz
+ (i32.and
+ (get_local $0)
+ (i32.const 255)
+ )
+ )
+ )
+ )
)
diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast
index 191450897..d9e6fcc71 100644
--- a/test/passes/optimize-instructions.wast
+++ b/test/passes/optimize-instructions.wast
@@ -1377,4 +1377,17 @@
)
)
)
+ (func $sign-ext-eqz (param $0 i32) (param $1 i32)
+ (drop
+ (i32.eqz
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ )
+ )
)