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(ptr %ops, i32 %len) {
43 %cmp6 = icmp sgt i32 %len, 0
44 br i1 %cmp6, label %for.body, label %for.cond.cleanup
46 for.cond.cleanup.loopexit: ; preds = %sw.epilog
47 %.pre = load i32, ptr %res
48 br label %for.cond.cleanup
50 for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry
51 %0 = phi i32 [ %.pre, %for.cond.cleanup.loopexit ], [ 0, %entry ]
54 for.body: ; preds = %entry, %sw.epilog
55 %i.07 = phi i32 [ %inc, %sw.epilog ], [ 0, %entry ]
56 %arrayidx = getelementptr inbounds i32, ptr %ops, i32 %i.07
57 %1 = load i32, ptr %arrayidx
58 switch i32 %1, label %sw.epilog [
63 sw.bb: ; preds = %for.body
64 call void @a(ptr nonnull %res)
67 sw.bb1: ; preds = %for.body
68 call void @b(ptr nonnull %res)
71 sw.epilog: ; preds = %for.body, %sw.bb1, %sw.bb
72 %inc = add nuw nsw i32 %i.07, 1
73 %exitcond = icmp eq i32 %inc, %len
74 br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body