Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

2.3 KB
Raw Blame
;;! target = "x86_64"
;;! test = "optimize"
;;! flags = "-Wbranch-hinting=n"

;; With branch hinting disabled, codegen ignores the `metadata.code.branch_hint`
;; custom section entirely: no block is marked `cold`.

(module
  (func $if_unlikely (param i32) (result i32)
    local.get 0
    (@metadata.code.branch_hint "\00")
    if (result i32)
      i32.const 1
    else
      i32.const 2
    end
  )

  (func $br_if_likely (param i32) (result i32)
    (block $target
      local.get 0
      (@metadata.code.branch_hint "\01")
      br_if $target
      i32.const 1
      return
    )
    i32.const 2
  )
)
;; function u0:0(i64 vmctx, i64, i32) -> i32 tail {
;;     region0 = 123 ""
;;     region1 = 160 ""
;;     gv0 = vmctx
;;     gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8
;;     gv2 = load.i64 notrap aligned region1 gv1+24
;;     stack_limit = gv2
;;
;;                                 block0(v0: i64, v1: i64, v2: i32):
;; @0043                               brif v2, block2, block4
;;
;;                                 block2:
;; @0045                               v3 = iconst.i32 1
;; @0047                               jump block3(v3)  ; v3 = 1
;;
;;                                 block4:
;; @0048                               v4 = iconst.i32 2
;; @004a                               jump block3(v4)  ; v4 = 2
;;
;;                                 block3(v5: i32):
;; @004b                               jump block1
;;
;;                                 block1:
;; @004b                               return v5
;; }
;;
;; function u0:1(i64 vmctx, i64, i32) -> i32 tail {
;;     region0 = 123 ""
;;     region1 = 160 ""
;;     gv0 = vmctx
;;     gv1 = load.i64 notrap aligned readonly can_move region0 gv0+8
;;     gv2 = load.i64 notrap aligned region1 gv1+24
;;     stack_limit = gv2
;;
;;                                 block0(v0: i64, v1: i64, v2: i32):
;; @0052                               brif v2, block2, block3
;;
;;                                 block3:
;; @0054                               v3 = iconst.i32 1
;; @0056                               return v3  ; v3 = 1
;;
;;                                 block2:
;; @005a                               jump block1
;;
;;                                 block1:
;; @0058                               v4 = iconst.i32 2
;; @005a                               return v4  ; v4 = 2
;; }