blob: c31220fc2467b35e303d2929b1e58e8d2cb01cce [file] [edit]
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; RUN: foreach %s %t wasm-opt -all --delete-branch-hints=10,30 -S -o - | filecheck %s
(module
;; CHECK: (type $0 (func))
;; CHECK: (type $1 (func (param i32 i32 i32) (result i32)))
;; CHECK: (type $2 (func (param i32) (result i32)))
;; CHECK: (import "fuzzing-support" "log-branch" (func $log (type $1) (param i32 i32 i32) (result i32)))
(import "fuzzing-support" "log-branch" (func $log (param i32 i32 i32) (result i32)))
;; CHECK: (func $if-10 (type $0)
;; CHECK-NEXT: (if
;; CHECK-NEXT: (call $log
;; CHECK-NEXT: (i32.const 42)
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: (i32.const 10)
;; CHECK-NEXT: )
;; CHECK-NEXT: (then
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 1337)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (else
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 99)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $if-10
;; The branch hint should be removed, since the ID "10" is in the list of
;; 10, 30.
(@metadata.code.branch_hint "\00")
(if
(call $log
(i32.const 42)
(i32.const 0)
(i32.const 10)
)
(then
(drop
(i32.const 1337)
)
)
(else
(drop
(i32.const 99)
)
)
)
)
;; CHECK: (func $if-20 (type $0)
;; CHECK-NEXT: (@metadata.code.branch_hint "\00")
;; CHECK-NEXT: (if
;; CHECK-NEXT: (call $log
;; CHECK-NEXT: (i32.const 42)
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: (i32.const 20)
;; CHECK-NEXT: )
;; CHECK-NEXT: (then
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 1337)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (else
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 99)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $if-20
;; The branch hint should *not* be removed: 20 is not in the list.
(@metadata.code.branch_hint "\00")
(if
(call $log
(i32.const 42)
(i32.const 0)
(i32.const 20)
)
(then
(drop
(i32.const 1337)
)
)
(else
(drop
(i32.const 99)
)
)
)
)
;; CHECK: (func $br-30 (type $0)
;; CHECK-NEXT: (block $out
;; CHECK-NEXT: (br_if $out
;; CHECK-NEXT: (call $log
;; CHECK-NEXT: (i32.const 42)
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: (i32.const 30)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $br-30
;; The hint should be removed.
(block $out
(@metadata.code.branch_hint "\01")
(br_if $out
(call $log
(i32.const 42)
(i32.const 0)
(i32.const 30)
)
)
)
)
;; CHECK: (func $stacky (type $2) (param $c i32) (result i32)
;; CHECK-NEXT: (block $l (result i32)
;; CHECK-NEXT: (br_if $l
;; CHECK-NEXT: (i32.const 42)
;; CHECK-NEXT: (block (result i32)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: (call $log
;; CHECK-NEXT: (local.get $c)
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: (i32.const 10)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $stacky (param $c i32) (result i32)
block $l (result i32)
i32.const 42
;; Because the parser greedily pulls previous none-typed expressions into
;; block, this condition will be parsed as this:
;;
;; (block
;; (nop)
;; (call $log-branch ...))
;; )
;;
;; We must be able to find and handle this pattern to remove the hint.
nop
local.get $c
i32.const 1
i32.const 10
call $log
(@metadata.code.branch_hint "\01")
br_if $l
end
)
)