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@{{.*}}(%rip), %rax
34 ; CHECK-NEXT: movq (%rax), %rax
35 ; CHECK-NEXT: movq %rax, {{[0-9]+}}(%rsp)
36 ; CHECK-NEXT: xorl %r12d, %r12d
37 ; CHECK-NEXT: leaq -{{[0-9]+}}(%rsp), %r14
38 ; CHECK-NEXT: movq %rsp, %r15
39 ; CHECK-NEXT: cmpl $999, %r12d ## imm = 0x3E7
40 ; CHECK-NEXT: jle LBB0_2
41 ; CHECK-NEXT: jmp LBB0_7
42 ; CHECK-NEXT: .p2align 4, 0x90
43 ; CHECK-NEXT: LBB0_6: ## %for.inc9
44 ; CHECK-NEXT: ## in Loop: Header=BB0_2 Depth=1
45 ; CHECK-NEXT: incl %r12d
46 ; CHECK-NEXT: cmpl $999, %r12d ## imm = 0x3E7
47 ; CHECK-NEXT: jg LBB0_7
48 ; CHECK-NEXT: LBB0_2: ## %for.cond1.preheader
49 ; CHECK-NEXT: ## =>This Loop Header: Depth=1
50 ; CHECK-NEXT: ## Child Loop BB0_3 Depth 2
51 ; CHECK-NEXT: movl $-1, %r13d
52 ; CHECK-NEXT: movq %r15, %rbx
53 ; CHECK-NEXT: movq %r14, %rbp
54 ; CHECK-NEXT: .p2align 4, 0x90
55 ; CHECK-NEXT: LBB0_3: ## %for.cond1
56 ; CHECK-NEXT: ## Parent Loop BB0_2 Depth=1
57 ; CHECK-NEXT: ## => This Inner Loop Header: Depth=2
58 ; CHECK-NEXT: incl %r13d
59 ; CHECK-NEXT: cmpl $999, %r13d ## 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, %rbp ## imm = 0x3EA
64 ; CHECK-NEXT: movq %rbx, %rdi
65 ; CHECK-NEXT: addq $1001, %rbx ## imm = 0x3E9
66 ; CHECK-NEXT: movl $1000, %edx ## imm = 0x3E8
67 ; CHECK-NEXT: movl $120, %esi
68 ; CHECK-NEXT: callq _memchr
69 ; CHECK-NEXT: cmpq %rax, %rbp
70 ; CHECK-NEXT: je LBB0_3
71 ; CHECK-NEXT: jmp LBB0_5
72 ; CHECK-NEXT: LBB0_7: ## %for.end11
73 ; CHECK-NEXT: leaq {{.*}}(%rip), %rdi
74 ; CHECK-NEXT: callq _puts
75 ; CHECK-NEXT: xorl %eax, %eax
76 ; CHECK-NEXT: movq %rsp, %rcx
77 ; CHECK-NEXT: cmpl $999, %eax ## imm = 0x3E7
78 ; CHECK-NEXT: jle LBB0_9
79 ; CHECK-NEXT: jmp LBB0_16
80 ; CHECK-NEXT: .p2align 4, 0x90
81 ; CHECK-NEXT: LBB0_15: ## %for.inc38
82 ; CHECK-NEXT: ## in Loop: Header=BB0_9 Depth=1
83 ; CHECK-NEXT: incl %eax
84 ; CHECK-NEXT: cmpl $999, %eax ## imm = 0x3E7
85 ; CHECK-NEXT: jg LBB0_16
86 ; CHECK-NEXT: LBB0_9: ## %for.cond18.preheader
87 ; CHECK-NEXT: ## =>This Loop Header: Depth=1
88 ; CHECK-NEXT: ## Child Loop BB0_11 Depth 2
89 ; CHECK-NEXT: ## Child Loop BB0_12 Depth 3
90 ; CHECK-NEXT: movq %rcx, %rdx
91 ; CHECK-NEXT: xorl %esi, %esi
92 ; CHECK-NEXT: xorl %edi, %edi
93 ; CHECK-NEXT: cmpl $999, %edi ## imm = 0x3E7
94 ; CHECK-NEXT: jle LBB0_11
95 ; CHECK-NEXT: jmp LBB0_15
96 ; CHECK-NEXT: .p2align 4, 0x90
97 ; CHECK-NEXT: LBB0_14: ## %exit
98 ; CHECK-NEXT: ## in Loop: Header=BB0_11 Depth=2
99 ; CHECK-NEXT: addq %rsi, %rbp
100 ; CHECK-NEXT: incq %rdi
101 ; CHECK-NEXT: decq %rsi
102 ; CHECK-NEXT: addq $1001, %rdx ## imm = 0x3E9
103 ; CHECK-NEXT: cmpq $-1000, %rbp ## imm = 0xFC18
104 ; CHECK-NEXT: jne LBB0_5
105 ; CHECK-NEXT: ## %bb.10: ## %for.cond18
106 ; CHECK-NEXT: ## in Loop: Header=BB0_11 Depth=2
107 ; CHECK-NEXT: cmpl $999, %edi ## imm = 0x3E7
108 ; CHECK-NEXT: jg LBB0_15
109 ; CHECK-NEXT: LBB0_11: ## %for.body20
110 ; CHECK-NEXT: ## Parent Loop BB0_9 Depth=1
111 ; CHECK-NEXT: ## => This Loop Header: Depth=2
112 ; CHECK-NEXT: ## Child Loop BB0_12 Depth 3
113 ; CHECK-NEXT: movq $-1000, %rbp ## imm = 0xFC18
114 ; CHECK-NEXT: .p2align 4, 0x90
115 ; CHECK-NEXT: LBB0_12: ## %do.body.i
116 ; CHECK-NEXT: ## Parent Loop BB0_9 Depth=1
117 ; CHECK-NEXT: ## Parent Loop BB0_11 Depth=2
118 ; CHECK-NEXT: ## => This Inner Loop Header: Depth=3
119 ; CHECK-NEXT: cmpb $120, 1000(%rdx,%rbp)
120 ; CHECK-NEXT: je LBB0_14
121 ; CHECK-NEXT: ## %bb.13: ## %do.cond.i
122 ; CHECK-NEXT: ## in Loop: Header=BB0_12 Depth=3
123 ; CHECK-NEXT: incq %rbp
124 ; CHECK-NEXT: jne LBB0_12
125 ; CHECK-NEXT: LBB0_5: ## %if.then
126 ; CHECK-NEXT: leaq {{.*}}(%rip), %rdi
127 ; CHECK-NEXT: callq _puts
128 ; CHECK-NEXT: movl $1, %edi
129 ; CHECK-NEXT: callq _exit
130 ; CHECK-NEXT: LBB0_16: ## %for.end40
131 ; CHECK-NEXT: leaq {{.*}}(%rip), %rdi
132 ; CHECK-NEXT: callq _puts
133 ; CHECK-NEXT: movq ___stack_chk_guard@{{.*}}(%rip), %rax
134 ; CHECK-NEXT: movq (%rax), %rax
135 ; CHECK-NEXT: cmpq {{[0-9]+}}(%rsp), %rax
136 ; CHECK-NEXT: jne LBB0_18
137 ; CHECK-NEXT: ## %bb.17: ## %for.end40
138 ; CHECK-NEXT: xorl %eax, %eax
139 ; CHECK-NEXT: addq $1001016, %rsp ## imm = 0xF4638
140 ; CHECK-NEXT: popq %rbx
141 ; CHECK-NEXT: popq %r12
142 ; CHECK-NEXT: popq %r13
143 ; CHECK-NEXT: popq %r14
144 ; CHECK-NEXT: popq %r15
145 ; CHECK-NEXT: popq %rbp
147 ; CHECK-NEXT: LBB0_18: ## %for.end40
148 ; CHECK-NEXT: callq ___stack_chk_fail
150 %strs = alloca [1000 x [1001 x i8]], align 16
154 %j.0 = phi i32 [ 0, %entry ], [ %inc10, %for.inc9 ]
155 %cmp = icmp slt i32 %j.0, 1000
156 br i1 %cmp, label %for.cond1, label %for.end11
159 %indvars.iv50 = phi i64 [ %indvars.iv.next51, %for.body3 ], [ 0, %for.cond ]
160 %0 = trunc i64 %indvars.iv50 to i32
161 %cmp2 = icmp slt i32 %0, 1000
162 br i1 %cmp2, label %for.body3, label %for.inc9
165 %arraydecay = getelementptr inbounds [1000 x [1001 x i8]], [1000 x [1001 x i8]]* %strs, i64 0, i64 %indvars.iv50, i64 0
166 %call = call i8* @memchr(i8* %arraydecay, i32 120, i64 1000)
167 %add.ptr = getelementptr inbounds [1000 x [1001 x i8]], [1000 x [1001 x i8]]* %strs, i64 0, i64 %indvars.iv50, i64 %indvars.iv50
168 %cmp7 = icmp eq i8* %call, %add.ptr
169 %indvars.iv.next51 = add i64 %indvars.iv50, 1
170 br i1 %cmp7, label %for.cond1, label %if.then
173 %puts = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @str4, i64 0, i64 0))
174 call void @exit(i32 1) noreturn
178 %inc10 = add nsw i32 %j.0, 1
182 %puts42 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str2, i64 0, i64 0))
186 %j13.0 = phi i32 [ 0, %for.end11 ], [ %inc39, %for.inc38 ]
187 %cmp15 = icmp slt i32 %j13.0, 1000
188 br i1 %cmp15, label %for.cond18, label %for.end40
191 %indvars.iv = phi i64 [ %indvars.iv.next, %exit ], [ 0, %for.cond14 ]
192 %1 = trunc i64 %indvars.iv to i32
193 %cmp19 = icmp slt i32 %1, 1000
194 br i1 %cmp19, label %for.body20, label %for.inc38
197 %arraydecay24 = getelementptr inbounds [1000 x [1001 x i8]], [1000 x [1001 x i8]]* %strs, i64 0, i64 %indvars.iv, i64 0
201 %n.addr.0.i = phi i64 [ %dec.i, %do.cond.i ], [ 1000, %for.body20 ]
202 %p.0.i = phi i8* [ %incdec.ptr.i, %do.cond.i ], [ %arraydecay24, %for.body20 ]
203 %2 = load i8, i8* %p.0.i, align 1
204 %cmp3.i = icmp eq i8 %2, 120
205 br i1 %cmp3.i, label %exit, label %do.cond.i
208 %incdec.ptr.i = getelementptr inbounds i8, i8* %p.0.i, i64 1
209 %dec.i = add i64 %n.addr.0.i, -1
210 %cmp5.i = icmp eq i64 %dec.i, 0
211 br i1 %cmp5.i, label %if.then32, label %do.body.i
214 %add.ptr30 = getelementptr inbounds [1000 x [1001 x i8]], [1000 x [1001 x i8]]* %strs, i64 0, i64 %indvars.iv, i64 %indvars.iv
215 %cmp31 = icmp eq i8* %p.0.i, %add.ptr30
216 %indvars.iv.next = add i64 %indvars.iv, 1
217 br i1 %cmp31, label %for.cond18, label %if.then32
220 %puts43 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @str4, i64 0, i64 0))
221 call void @exit(i32 1) noreturn
225 %inc39 = add nsw i32 %j13.0, 1
229 %puts44 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str3, i64 0, i64 0))
233 declare i8* @memchr(i8*, i32, i64) nounwind readonly
234 declare void @exit(i32) noreturn
235 declare i32 @puts(i8* nocapture) nounwind