Skip to content

Commit b3c97a9

Browse files
committed
merge blocks before and after remove-unused-brs
1 parent a42f224 commit b3c97a9

File tree

6 files changed

+64
-62
lines changed

6 files changed

+64
-62
lines changed

src/passes/pass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ void PassRunner::addDefaultFunctionOptimizationPasses() {
135135
add("simplify-locals");
136136
add("vacuum"); // previous pass creates garbage
137137
add("reorder-locals");
138+
add("merge-blocks"); // makes remove-unused-brs more effective
138139
add("remove-unused-brs"); // coalesce-locals opens opportunities for optimizations
139-
add("merge-blocks");
140+
add("merge-blocks"); // clean up remove-unused-brs new blocks
140141
add("optimize-instructions");
141142
add("precompute");
142143
if (options.shrinkLevel >= 2) {

test/emcc_hello_world.fromasm.imprecise

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,69 +2741,71 @@
27412741
(block
27422742
(set_local $10
27432743
(block $__rjto$0 i32
2744-
(block $__rjti$0
2745-
(br_if $__rjti$0
2746-
(i32.ge_u
2747-
(tee_local $11
2748-
(i32.add
2749-
(i32.load8_s
2750-
(tee_local $6
2751-
(i32.add
2752-
(get_local $10)
2753-
(i32.const 1)
2744+
(if
2745+
(i32.eqz
2746+
(i32.or
2747+
(i32.ge_u
2748+
(tee_local $11
2749+
(i32.add
2750+
(i32.load8_s
2751+
(tee_local $6
2752+
(i32.add
2753+
(get_local $10)
2754+
(i32.const 1)
2755+
)
27542756
)
27552757
)
2758+
(i32.const -48)
27562759
)
2757-
(i32.const -48)
27582760
)
2761+
(i32.const 10)
27592762
)
2760-
(i32.const 10)
2761-
)
2762-
)
2763-
(br_if $__rjti$0
2764-
(i32.ne
2765-
(i32.load8_s offset=2
2766-
(get_local $10)
2763+
(i32.ne
2764+
(i32.load8_s offset=2
2765+
(get_local $10)
2766+
)
2767+
(i32.const 36)
27672768
)
2768-
(i32.const 36)
27692769
)
27702770
)
2771-
(i32.store
2772-
(i32.add
2773-
(get_local $4)
2774-
(i32.shl
2775-
(get_local $11)
2776-
(i32.const 2)
2771+
(block
2772+
(i32.store
2773+
(i32.add
2774+
(get_local $4)
2775+
(i32.shl
2776+
(get_local $11)
2777+
(i32.const 2)
2778+
)
27772779
)
2780+
(i32.const 10)
27782781
)
2779-
(i32.const 10)
2780-
)
2781-
(set_local $6
2782-
(i32.add
2783-
(get_local $3)
2784-
(i32.shl
2785-
(i32.add
2786-
(i32.load8_s
2787-
(get_local $6)
2782+
(set_local $6
2783+
(i32.add
2784+
(get_local $3)
2785+
(i32.shl
2786+
(i32.add
2787+
(i32.load8_s
2788+
(get_local $6)
2789+
)
2790+
(i32.const -48)
27882791
)
2789-
(i32.const -48)
2792+
(i32.const 3)
27902793
)
2791-
(i32.const 3)
27922794
)
27932795
)
2794-
)
2795-
(set_local $8
2796-
(i32.const 1)
2797-
)
2798-
(set_local $14
2799-
(i32.load
2800-
(get_local $6)
2796+
(set_local $8
2797+
(i32.const 1)
28012798
)
2802-
)
2803-
(br $__rjto$0
2804-
(i32.add
2805-
(get_local $10)
2806-
(i32.const 3)
2799+
(set_local $14
2800+
(i32.load
2801+
(get_local $6)
2802+
)
2803+
)
2804+
(br $__rjto$0
2805+
(i32.add
2806+
(get_local $10)
2807+
(i32.const 3)
2808+
)
28072809
)
28082810
)
28092811
)

test/example/relooper-fuzz.txt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,19 @@
519519
)
520520
(br $shape$3$continue)
521521
)
522+
(block
523+
(call $print
524+
(i32.const 2)
525+
)
526+
(drop
527+
(call $check)
528+
)
529+
(set_local $0
530+
(i32.const 6)
531+
)
532+
(br $shape$3$continue)
533+
)
522534
)
523-
(call $print
524-
(i32.const 2)
525-
)
526-
(drop
527-
(call $check)
528-
)
529-
(set_local $0
530-
(i32.const 6)
531-
)
532-
(br $shape$3$continue)
533535
)
534536
)
535537
)

test/wasm-only.fromasm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@
363363
(get_local $1)
364364
)
365365
(block
366-
(nop)
367366
(br_if $__rjto$0
368367
(get_local $2)
369368
)

test/wasm-only.fromasm.clamp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@
363363
(get_local $1)
364364
)
365365
(block
366-
(nop)
367366
(br_if $__rjto$0
368367
(get_local $2)
369368
)

test/wasm-only.fromasm.imprecise

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@
278278
(get_local $1)
279279
)
280280
(block
281-
(nop)
282281
(br_if $__rjto$0
283282
(get_local $2)
284283
)

0 commit comments

Comments
 (0)