1 ; RUN: llc < %s -asm-verbose=false -verify-machineinstrs | FileCheck %s
3 ;; Test that a small but nontrivial switch in a loop (like in a
4 ;; bytecode interpreter) lowers reasonably without any irreducible
5 ;; control flow being introduced.
7 target triple = "wasm32"
12 ; CHECK-LABEL: switch_in_loop:
13 ; CHECK-NEXT: .functype switch_in_loop (i32, i32) -> (i32)
14 ; CHECK: global.get __stack_pointer
15 ; CHECK: global.set __stack_pointer
23 ; CHECK: br_table {0, 1, 2}
37 ; CHECK: global.set __stack_pointer
39 define i32 @switch_in_loop(i32* %ops, i32 %len) {
42 %0 = bitcast i32* %res to i8*
43 store i32 0, i32* %res
44 %cmp6 = icmp sgt i32 %len, 0
45 br i1 %cmp6, label %for.body, label %for.cond.cleanup
47 for.cond.cleanup.loopexit: ; preds = %sw.epilog
48 %.pre = load i32, i32* %res
49 br label %for.cond.cleanup
51 for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry
52 %1 = phi i32 [ %.pre, %for.cond.cleanup.loopexit ], [ 0, %entry ]
55 for.body: ; preds = %entry, %sw.epilog
56 %i.07 = phi i32 [ %inc, %sw.epilog ], [ 0, %entry ]
57 %arrayidx = getelementptr inbounds i32, i32* %ops, i32 %i.07
58 %2 = load i32, i32* %arrayidx
59 switch i32 %2, label %sw.epilog [
64 sw.bb: ; preds = %for.body
65 call void @a(i32* nonnull %res)
68 sw.bb1: ; preds = %for.body
69 call void @b(i32* nonnull %res)
72 sw.epilog: ; preds = %for.body, %sw.bb1, %sw.bb
73 %inc = add nuw nsw i32 %i.07, 1
74 %exitcond = icmp eq i32 %inc, %len
75 br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body