Skip to content

Commit 33ccea3

Browse files
authored
Remove optimization for memory.copy(x, x, C) (#3073)
That can trap, so we can only remove it if traps are ignored, which was not handled properly. Revert it as we consider the options.
1 parent 1f439f7 commit 33ccea3

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

src/passes/OptimizeInstructions.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,16 +1399,6 @@ struct OptimizeInstructions
13991399
}
14001400

14011401
Expression* optimizeMemoryCopy(MemoryCopy* memCopy) {
1402-
FeatureSet features = getModule()->features;
1403-
1404-
// memory.copy(x, x, sz) ==> nop
1405-
if (!EffectAnalyzer(getPassOptions(), features, memCopy->dest)
1406-
.hasSideEffects() &&
1407-
!EffectAnalyzer(getPassOptions(), features, memCopy->size)
1408-
.hasSideEffects() &&
1409-
ExpressionAnalyzer::equal(memCopy->dest, memCopy->source)) {
1410-
return ExpressionManipulator::nop(memCopy);
1411-
}
14121402
// memory.copy(dst, src, C) ==> store(dst, load(src))
14131403
if (auto* csize = memCopy->size->dynCast<Const>()) {
14141404
auto bytes = csize->value.geti32();
@@ -1444,7 +1434,7 @@ struct OptimizeInstructions
14441434
if (getPassOptions().shrinkLevel == 0) {
14451435
// This adds an extra 2 bytes so apply it only for
14461436
// minimal shrink level
1447-
if (features.hasSIMD()) {
1437+
if (getModule()->features.hasSIMD()) {
14481438
return builder.makeStore(
14491439
bytes, // bytes
14501440
0, // offset

test/passes/optimize-instructions_all-features.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3729,7 +3729,11 @@
37293729
)
37303730
)
37313731
(func $optimize-bulk-memory-copy (param $dst i32) (param $src i32) (param $sz i32)
3732-
(nop)
3732+
(memory.copy
3733+
(local.get $dst)
3734+
(local.get $dst)
3735+
(local.get $sz)
3736+
)
37333737
(block
37343738
(drop
37353739
(local.get $dst)

test/passes/optimize-instructions_all-features.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4234,7 +4234,7 @@
42344234
))
42354235
)
42364236
(func $optimize-bulk-memory-copy (param $dst i32) (param $src i32) (param $sz i32)
4237-
(memory.copy ;; nop
4237+
(memory.copy ;; skip
42384238
(local.get $dst)
42394239
(local.get $dst)
42404240
(local.get $sz)

0 commit comments

Comments
 (0)