summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/OptimizeInstructions.cpp8
-rw-r--r--test/emcc_hello_world.fromasm3
-rw-r--r--test/emcc_hello_world.fromasm.imprecise3
-rw-r--r--test/unit.fromasm6
-rw-r--r--test/unit.fromasm.imprecise6
5 files changed, 8 insertions, 18 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 003d2ff60..2315b9e8e 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -24,6 +24,7 @@
#include <pass.h>
#include <wasm-s-parser.h>
#include <support/threads.h>
+#include <ast_utils.h>
namespace wasm {
@@ -208,6 +209,13 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
}
}
}
+ } else if (auto* set = curr->dynCast<SetGlobal>()) {
+ // optimize out a set of a get
+ auto* get = set->value->dynCast<GetGlobal>();
+ if (get && get->name == set->name) {
+ ExpressionManipulator::nop(curr);
+ return curr;
+ }
}
return nullptr;
}
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm
index 36a6c1ff1..94eb84af9 100644
--- a/test/emcc_hello_world.fromasm
+++ b/test/emcc_hello_world.fromasm
@@ -17682,9 +17682,6 @@
(set_global $STACKTOP
(get_local $6)
)
- (set_global $tempRet0
- (get_global $tempRet0)
- )
(get_local $0)
)
(func $___muldi3 (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise
index cb25aad51..79b6acbc8 100644
--- a/test/emcc_hello_world.fromasm.imprecise
+++ b/test/emcc_hello_world.fromasm.imprecise
@@ -17675,9 +17675,6 @@
(set_global $STACKTOP
(get_local $6)
)
- (set_global $tempRet0
- (get_global $tempRet0)
- )
(get_local $0)
)
(func $___muldi3 (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
diff --git a/test/unit.fromasm b/test/unit.fromasm
index 578385db3..ed9248552 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -690,12 +690,6 @@
(i32.const 12)
)
)
- (set_global $Double
- (get_global $Double)
- )
- (set_global $Int
- (get_global $Int)
- )
(call $globalOpts)
(set_local $0
(get_global $Int)
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise
index 1f303aef6..5d43b9e04 100644
--- a/test/unit.fromasm.imprecise
+++ b/test/unit.fromasm.imprecise
@@ -671,12 +671,6 @@
(i32.const 12)
)
)
- (set_global $Double
- (get_global $Double)
- )
- (set_global $Int
- (get_global $Int)
- )
(call $globalOpts)
(set_local $0
(get_global $Int)