1*a07c08f7SThomas Lively; RUN: llc < %s -asm-verbose=false -verify-machineinstrs | FileCheck %s 2*a07c08f7SThomas Lively 3*a07c08f7SThomas Lively; Test lowering of __builtin_debugtrap in cases where lowering it via 4*a07c08f7SThomas Lively; the normal UNREACHABLE instruction would yield invalid 5*a07c08f7SThomas Lively; MachineFunctions. 6*a07c08f7SThomas Lively 7*a07c08f7SThomas Livelytarget triple = "wasm32" 8*a07c08f7SThomas Lively 9*a07c08f7SThomas Livelydeclare void @llvm.debugtrap() 10*a07c08f7SThomas Lively 11*a07c08f7SThomas Lively; CHECK-LABEL: foo: 12*a07c08f7SThomas Lively; CHECK-NEXT: .functype foo (i32) -> () 13*a07c08f7SThomas Lively; CHECK-NEXT: .LBB0_1: 14*a07c08f7SThomas Lively; CHECK-NEXT: loop 15*a07c08f7SThomas Lively; CHECK-NEXT: unreachable 16*a07c08f7SThomas Lively; CHECK-NEXT: i32.const 0 17*a07c08f7SThomas Lively; CHECK-NEXT: br_if 0 18*a07c08f7SThomas Lively; CHECK-NEXT: end_loop 19*a07c08f7SThomas Lively; CHECK-NEXT: end_function 20*a07c08f7SThomas Livelydefine void @foo(i32 %g) { 21*a07c08f7SThomas Livelyentry: 22*a07c08f7SThomas Lively br label %for.body 23*a07c08f7SThomas Lively 24*a07c08f7SThomas Livelyfor.body: 25*a07c08f7SThomas Lively call void @llvm.debugtrap() 26*a07c08f7SThomas Lively %exitcond = icmp eq i32 undef, %g 27*a07c08f7SThomas Lively br i1 %exitcond, label %for.cond.cleanup, label %for.body 28*a07c08f7SThomas Lively 29*a07c08f7SThomas Livelyfor.cond.cleanup: 30*a07c08f7SThomas Lively ret void 31*a07c08f7SThomas Lively} 32*a07c08f7SThomas Lively 33*a07c08f7SThomas Lively; CHECK-LABEL: middle_of_block: 34*a07c08f7SThomas Lively; CHECK-NEXT: .functype middle_of_block (i32, i32) -> (i32) 35*a07c08f7SThomas Lively; CHECK-NEXT: unreachable 36*a07c08f7SThomas Lively; CHECK-NEXT: local.get 0 37*a07c08f7SThomas Lively; CHECK-NEXT: local.get 1 38*a07c08f7SThomas Lively; CHECK-NEXT: i32.add 39*a07c08f7SThomas Lively; CHECK-NEXT: end_function 40*a07c08f7SThomas Livelydefine i32 @middle_of_block(i32 %x, i32 %y) { 41*a07c08f7SThomas Lively %r = add i32 %x, %y 42*a07c08f7SThomas Lively call void @llvm.debugtrap() 43*a07c08f7SThomas Lively ret i32 %r 44*a07c08f7SThomas Lively} 45*a07c08f7SThomas Lively 46*a07c08f7SThomas Lively; CHECK-LABEL: really_middle_of_block: 47*a07c08f7SThomas Lively; CHECK-NEXT: .functype really_middle_of_block () -> (i32) 48*a07c08f7SThomas Lively; CHECK-NEXT: call bar 49*a07c08f7SThomas Lively; CHECK-NEXT: drop 50*a07c08f7SThomas Lively; CHECK-NEXT: unreachable 51*a07c08f7SThomas Lively; CHECK-NEXT: call bar 52*a07c08f7SThomas Lively; CHECK-NEXT: end_function 53*a07c08f7SThomas Livelydeclare i32 @bar() 54*a07c08f7SThomas Livelydefine i32 @really_middle_of_block() { 55*a07c08f7SThomas Lively %x = call i32 @bar() 56*a07c08f7SThomas Lively call void @llvm.debugtrap() 57*a07c08f7SThomas Lively %r = call i32 @bar() 58*a07c08f7SThomas Lively ret i32 %r 59*a07c08f7SThomas Lively} 60