Skip to content

Commit f7c2851

Browse files
authored
[Branch Hints] Fix if hint flip in Vacuum (#7713)
1 parent fc29e30 commit f7c2851

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/passes/Vacuum.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//
2020

2121
#include <ir/block-utils.h>
22+
#include <ir/branch-hints.h>
2223
#include <ir/drop.h>
2324
#include <ir/effects.h>
2425
#include <ir/iteration.h>
@@ -297,6 +298,7 @@ struct Vacuum : public WalkerPass<ExpressionStackWalker<Vacuum>> {
297298
curr->ifFalse = nullptr;
298299
curr->condition =
299300
Builder(*getModule()).makeUnary(EqZInt32, curr->condition);
301+
BranchHints::flip(curr, getFunction());
300302
} else if (curr->ifTrue->is<Drop>() && curr->ifFalse->is<Drop>()) {
301303
// instead of dropping both sides, drop the if, if they are the same
302304
// type
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
2+
;; RUN: wasm-opt %s --vacuum -all -S -o - | filecheck %s
3+
4+
(module
5+
;; CHECK: (func $if (type $0) (param $x i32)
6+
;; CHECK-NEXT: (@metadata.code.branch_hint "\01")
7+
;; CHECK-NEXT: (if
8+
;; CHECK-NEXT: (i32.eqz
9+
;; CHECK-NEXT: (i32.eqz
10+
;; CHECK-NEXT: (local.get $x)
11+
;; CHECK-NEXT: )
12+
;; CHECK-NEXT: )
13+
;; CHECK-NEXT: (then
14+
;; CHECK-NEXT: (call $if
15+
;; CHECK-NEXT: (local.get $x)
16+
;; CHECK-NEXT: )
17+
;; CHECK-NEXT: )
18+
;; CHECK-NEXT: )
19+
;; CHECK-NEXT: )
20+
(func $if (param $x i32)
21+
;; When we flip the if, the hint should flip too.
22+
(@metadata.code.branch_hint "\00")
23+
(if
24+
(i32.eqz
25+
(local.get $x)
26+
)
27+
(then
28+
(nop)
29+
)
30+
(else
31+
(call $if
32+
(local.get $x)
33+
)
34+
)
35+
)
36+
)
37+
)
38+

0 commit comments

Comments
 (0)