1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s
4 @.str2 = private unnamed_addr constant [7 x i8] c"memchr\00", align 1
5 @.str3 = private unnamed_addr constant [11 x i8] c"bsd_memchr\00", align 1
6 @str4 = private unnamed_addr constant [5 x i8] c"Bug!\00"
8 ; Make sure at end of do.cond.i, we jump to do.body.i first to have a tighter
10 define i32 @test_branches_order() uwtable ssp {
11 ; CHECK-LABEL: test_branches_order:
12 ; CHECK: ## %bb.0: ## %entry
13 ; CHECK-NEXT: pushq %rbp
14 ; CHECK-NEXT: .cfi_def_cfa_offset 16
15 ; CHECK-NEXT: pushq %r15
16 ; CHECK-NEXT: .cfi_def_cfa_offset 24
17 ; CHECK-NEXT: pushq %r14
18 ; CHECK-NEXT: .cfi_def_cfa_offset 32
19 ; CHECK-NEXT: pushq %r13
20 ; CHECK-NEXT: .cfi_def_cfa_offset 40
21 ; CHECK-NEXT: pushq %r12
22 ; CHECK-NEXT: .cfi_def_cfa_offset 48
23 ; CHECK-NEXT: pushq %rbx
24 ; CHECK-NEXT: .cfi_def_cfa_offset 56
25 ; CHECK-NEXT: subq $1001016, %rsp ## imm = 0xF4638
26 ; CHECK-NEXT: .cfi_def_cfa_offset 1001072
27 ; CHECK-NEXT: .cfi_offset %rbx, -56
28 ; CHECK-NEXT: .cfi_offset %r12, -48
29 ; CHECK-NEXT: .cfi_offset %r13, -40
30 ; CHECK-NEXT: .cfi_offset %r14, -32
31 ; CHECK-NEXT: .cfi_offset %r15, -24
32 ; CHECK-NEXT: .cfi_offset %rbp, -16
33 ; CHECK-NEXT: movq ___stack_chk_guard@GOTPCREL(%rip), %rax
34 ; CHECK-NEXT: movq (%rax), %rax
35 ; CHECK-NEXT: movq %rax, {{[0-9]+}}(%rsp)
36 ; CHECK-NEXT: xorl %ebx, %ebx
37 ; CHECK-NEXT: leaq -{{[0-9]+}}(%rsp), %r14
38 ; CHECK-NEXT: movq %rsp, %r15
39 ; CHECK-NEXT: jmp LBB0_1
40 ; CHECK-NEXT: .p2align 4
41 ; CHECK-NEXT: LBB0_6: ## %for.inc9
42 ; CHECK-NEXT: ## in Loop: Header=BB0_1 Depth=1
43 ; CHECK-NEXT: incl %ebx
44 ; CHECK-NEXT: LBB0_1: ## %for.cond
45 ; CHECK-NEXT: ## =>This Loop Header: Depth=1
46 ; CHECK-NEXT: ## Child Loop BB0_3 Depth 2
47 ; CHECK-NEXT: cmpl $999, %ebx ## imm = 0x3E7
48 ; CHECK-NEXT: jg LBB0_7
49 ; CHECK-NEXT: ## %bb.2: ## %for.cond1.preheader
50 ; CHECK-NEXT: ## in Loop: Header=BB0_1 Depth=1
51 ; CHECK-NEXT: movl $-1, %ebp
52 ; CHECK-NEXT: movq %r15, %rdi
53 ; CHECK-NEXT: movq %r14, %r12
54 ; CHECK-NEXT: .p2align 4
55 ; CHECK-NEXT: LBB0_3: ## %for.cond1
56 ; CHECK-NEXT: ## Parent Loop BB0_1 Depth=1
57 ; CHECK-NEXT: ## => This Inner Loop Header: Depth=2
58 ; CHECK-NEXT: incl %ebp
59 ; CHECK-NEXT: cmpl $999, %ebp ## imm = 0x3E7
60 ; CHECK-NEXT: jg LBB0_6
61 ; CHECK-NEXT: ## %bb.4: ## %for.body3
62 ; CHECK-NEXT: ## in Loop: Header=BB0_3 Depth=2
63 ; CHECK-NEXT: addq $1002, %r12 ## imm = 0x3EA
64 ; CHECK-NEXT: leaq 1001(%rdi), %r13
65 ; CHECK-NEXT: movl $1000, %edx ## imm = 0x3E8
66 ; CHECK-NEXT: movl $120, %esi
67 ; CHECK-NEXT: callq _memchr
68 ; CHECK-NEXT: cmpq %rax, %r12
69 ; CHECK-NEXT: movq %r13, %rdi
70 ; CHECK-NEXT: je LBB0_3
71 ; CHECK-NEXT: jmp LBB0_5
72 ; CHECK-NEXT: LBB0_7: ## %for.end11
73 ; CHECK-NEXT: leaq L_.str2(%rip), %rdi
74 ; CHECK-NEXT: callq _puts
75 ; CHECK-NEXT: xorl %eax, %eax
76 ; CHECK-NEXT: movq %rsp, %rcx
77 ; CHECK-NEXT: jmp LBB0_8
78 ; CHECK-NEXT: .p2align 4
79 ; CHECK-NEXT: LBB0_15: ## %for.inc38
80 ; CHECK-NEXT: ## in Loop: Header=BB0_8 Depth=1
81 ; CHECK-NEXT: incl %eax
82 ; CHECK-NEXT: LBB0_8: ## %for.cond14
83 ; CHECK-NEXT: ## =>This Loop Header: Depth=1
84 ; CHECK-NEXT: ## Child Loop BB0_10 Depth 2
85 ; CHECK-NEXT: ## Child Loop BB0_12 Depth 3
86 ; CHECK-NEXT: cmpl $999, %eax ## imm = 0x3E7
87 ; CHECK-NEXT: jg LBB0_16
88 ; CHECK-NEXT: ## %bb.9: ## %for.cond18.preheader
89 ; CHECK-NEXT: ## in Loop: Header=BB0_8 Depth=1
90 ; CHECK-NEXT: movq %rcx, %rdx
91 ; CHECK-NEXT: xorl %esi, %esi
92 ; CHECK-NEXT: xorl %edi, %edi
93 ; CHECK-NEXT: jmp LBB0_10
94 ; CHECK-NEXT: .p2align 4
95 ; CHECK-NEXT: LBB0_14: ## %exit
96 ; CHECK-NEXT: ## in Loop: Header=BB0_10 Depth=2
97 ; CHECK-NEXT: addq %rsi, %r8
98 ; CHECK-NEXT: incq %rdi
99 ; CHECK-NEXT: decq %rsi
100 ; CHECK-NEXT: addq $1001, %rdx ## imm = 0x3E9
101 ; CHECK-NEXT: cmpq $-1000, %r8 ## imm = 0xFC18
102 ; CHECK-NEXT: jne LBB0_5
103 ; CHECK-NEXT: LBB0_10: ## %for.cond18
104 ; CHECK-NEXT: ## Parent Loop BB0_8 Depth=1
105 ; CHECK-NEXT: ## => This Loop Header: Depth=2
106 ; CHECK-NEXT: ## Child Loop BB0_12 Depth 3
107 ; CHECK-NEXT: cmpl $999, %edi ## imm = 0x3E7
108 ; CHECK-NEXT: jg LBB0_15
109 ; CHECK-NEXT: ## %bb.11: ## %for.body20
110 ; CHECK-NEXT: ## in Loop: Header=BB0_10 Depth=2
111 ; CHECK-NEXT: movq $-1000, %r8 ## imm = 0xFC18
112 ; CHECK-NEXT: .p2align 4
113 ; CHECK-NEXT: LBB0_12: ## %do.body.i
114 ; CHECK-NEXT: ## Parent Loop BB0_8 Depth=1
115 ; CHECK-NEXT: ## Parent Loop BB0_10 Depth=2
116 ; CHECK-NEXT: ## => This Inner Loop Header: Depth=3
117 ; CHECK-NEXT: cmpb $120, 1000(%rdx,%r8)
118 ; CHECK-NEXT: je LBB0_14
119 ; CHECK-NEXT: ## %bb.13: ## %do.cond.i
120 ; CHECK-NEXT: ## in Loop: Header=BB0_12 Depth=3
121 ; CHECK-NEXT: incq %r8
122 ; CHECK-NEXT: jne LBB0_12
123 ; CHECK-NEXT: LBB0_5: ## %if.then
124 ; CHECK-NEXT: leaq L_str4(%rip), %rdi
125 ; CHECK-NEXT: callq _puts
126 ; CHECK-NEXT: movl $1, %edi
127 ; CHECK-NEXT: callq _exit
128 ; CHECK-NEXT: LBB0_16: ## %for.end40
129 ; CHECK-NEXT: leaq L_.str3(%rip), %rdi
130 ; CHECK-NEXT: callq _puts
131 ; CHECK-NEXT: movq ___stack_chk_guard@GOTPCREL(%rip), %rax
132 ; CHECK-NEXT: movq (%rax), %rax
133 ; CHECK-NEXT: cmpq {{[0-9]+}}(%rsp), %rax
134 ; CHECK-NEXT: jne LBB0_18
135 ; CHECK-NEXT: ## %bb.17: ## %for.end40
136 ; CHECK-NEXT: xorl %eax, %eax
137 ; CHECK-NEXT: addq $1001016, %rsp ## imm = 0xF4638
138 ; CHECK-NEXT: popq %rbx
139 ; CHECK-NEXT: popq %r12
140 ; CHECK-NEXT: popq %r13
141 ; CHECK-NEXT: popq %r14
142 ; CHECK-NEXT: popq %r15
143 ; CHECK-NEXT: popq %rbp
145 ; CHECK-NEXT: LBB0_18: ## %for.end40
146 ; CHECK-NEXT: callq ___stack_chk_fail
148 %strs = alloca [1000 x [1001 x i8]], align 16
152 %j.0 = phi i32 [ 0, %entry ], [ %inc10, %for.inc9 ]
153 %cmp = icmp slt i32 %j.0, 1000
154 br i1 %cmp, label %for.cond1, label %for.end11
157 %indvars.iv50 = phi i64 [ %indvars.iv.next51, %for.body3 ], [ 0, %for.cond ]
158 %0 = trunc i64 %indvars.iv50 to i32
159 %cmp2 = icmp slt i32 %0, 1000
160 br i1 %cmp2, label %for.body3, label %for.inc9
163 %arraydecay = getelementptr inbounds [1000 x [1001 x i8]], ptr %strs, i64 0, i64 %indvars.iv50, i64 0
164 %call = call ptr @memchr(ptr %arraydecay, i32 120, i64 1000)
165 %add.ptr = getelementptr inbounds [1000 x [1001 x i8]], ptr %strs, i64 0, i64 %indvars.iv50, i64 %indvars.iv50
166 %cmp7 = icmp eq ptr %call, %add.ptr
167 %indvars.iv.next51 = add i64 %indvars.iv50, 1
168 br i1 %cmp7, label %for.cond1, label %if.then
171 %puts = call i32 @puts(ptr @str4)
172 call void @exit(i32 1) noreturn
176 %inc10 = add nsw i32 %j.0, 1
180 %puts42 = call i32 @puts(ptr @.str2)
184 %j13.0 = phi i32 [ 0, %for.end11 ], [ %inc39, %for.inc38 ]
185 %cmp15 = icmp slt i32 %j13.0, 1000
186 br i1 %cmp15, label %for.cond18, label %for.end40
189 %indvars.iv = phi i64 [ %indvars.iv.next, %exit ], [ 0, %for.cond14 ]
190 %1 = trunc i64 %indvars.iv to i32
191 %cmp19 = icmp slt i32 %1, 1000
192 br i1 %cmp19, label %for.body20, label %for.inc38
195 %arraydecay24 = getelementptr inbounds [1000 x [1001 x i8]], ptr %strs, i64 0, i64 %indvars.iv, i64 0
199 %n.addr.0.i = phi i64 [ %dec.i, %do.cond.i ], [ 1000, %for.body20 ]
200 %p.0.i = phi ptr [ %incdec.ptr.i, %do.cond.i ], [ %arraydecay24, %for.body20 ]
201 %2 = load i8, ptr %p.0.i, align 1
202 %cmp3.i = icmp eq i8 %2, 120
203 br i1 %cmp3.i, label %exit, label %do.cond.i
206 %incdec.ptr.i = getelementptr inbounds i8, ptr %p.0.i, i64 1
207 %dec.i = add i64 %n.addr.0.i, -1
208 %cmp5.i = icmp eq i64 %dec.i, 0
209 br i1 %cmp5.i, label %if.then32, label %do.body.i
212 %add.ptr30 = getelementptr inbounds [1000 x [1001 x i8]], ptr %strs, i64 0, i64 %indvars.iv, i64 %indvars.iv
213 %cmp31 = icmp eq ptr %p.0.i, %add.ptr30
214 %indvars.iv.next = add i64 %indvars.iv, 1
215 br i1 %cmp31, label %for.cond18, label %if.then32
218 %puts43 = call i32 @puts(ptr @str4)
219 call void @exit(i32 1) noreturn
223 %inc39 = add nsw i32 %j13.0, 1
227 %puts44 = call i32 @puts(ptr @.str3)
231 declare ptr @memchr(ptr, i32, i64) nounwind readonly
232 declare void @exit(i32) noreturn
233 declare i32 @puts(ptr nocapture) nounwind