1; pr23772 - [ARM] r226200 can emit illegal thumb2 instruction: "sub sp, r12, #80"
2; RUN: llc -march=thumb -mcpu=cortex-m3 -O3 -filetype=asm -o - %s | FileCheck %s
3; CHECK-NOT: sub{{.*}} sp, r{{.*}}, #
4; CHECK:     .fnend
5; TODO: Missed optimization. The three instructions generated to subtract SP can be converged to a single one
6target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:32"
7target triple = "thumbv7m-unknown-unknown"
8%B = type {%B*}
9%R = type {i32}
10%U = type {%U*, i8, i8}
11%E = type {%B*, %U*}
12%X = type {i32, i8, i8}
13declare external [0 x i8]* @memalloc(i32, i32, i32)
14declare external void @memfree([0 x i8]*, i32, i32)
15define void @foo(%B* %pb$, %R* %pr$) nounwind {
16L.0:
17	%pb = alloca %B*
18	%pr = alloca %R*
19	store %B* %pb$, %B** %pb
20	store %R* %pr$, %R** %pr
21	%pe = alloca %E*
22	%0 = load %B*, %B** %pb
23	%1 = bitcast %B* %0 to %E*
24	store %E* %1, %E** %pe
25	%2 = load %R*, %R** %pr
26	%3 = getelementptr %R, %R* %2, i32 0, i32 0
27	%4 = load i32, i32* %3
28	switch i32 %4, label %L.1 [
29		i32 1, label %L.3
30	]
31L.3:
32	%px = alloca %X*
33	%5 = load %R*, %R** %pr
34	%6 = bitcast %R* %5 to %X*
35	store %X* %6, %X** %px
36	%7 = load %X*, %X** %px
37	%8 = getelementptr %X, %X* %7, i32 0, i32 0
38	%9 = load i32, i32* %8
39	%10 = icmp ne i32 %9, 0
40	br i1 %10, label %L.5, label %L.4
41L.5:
42	%pu = alloca %U*
43	%11 = call [0 x i8]* @memalloc(i32 8, i32 4, i32 0)
44	%12 = bitcast [0 x i8]* %11 to %U*
45	store %U* %12, %U** %pu
46	%13 = load %X*, %X** %px
47	%14 = getelementptr %X, %X* %13, i32 0, i32 1
48	%15 = load i8, i8* %14
49	%16 = load %U*, %U** %pu
50	%17 = getelementptr %U, %U* %16, i32 0, i32 1
51	store i8 %15, i8* %17
52	%18 = load %E*, %E** %pe
53	%19 = getelementptr %E, %E* %18, i32 0, i32 1
54	%20 = load %U*, %U** %19
55	%21 = load %U*, %U** %pu
56	%22 = getelementptr %U, %U* %21, i32 0, i32 0
57	store %U* %20, %U** %22
58	%23 = load %U*, %U** %pu
59	%24 = load %E*, %E** %pe
60	%25 = getelementptr %E, %E* %24, i32 0, i32 1
61	store %U* %23, %U** %25
62	br label %L.4
63L.4:
64	%26 = load %X*, %X** %px
65	%27 = bitcast %X* %26 to [0 x i8]*
66	call void @memfree([0 x i8]* %27, i32 8, i32 0)
67	br label %L.2
68L.1:
69	br label %L.2
70L.2:
71	br label %return
72return:
73	ret void
74}
75