3 # clang -g -O1 -S -emit-llvm test.c
4 # llc -stop-before=branch-folder test.ll
19 # if ((ret = foo(*out)) < 0)
36 # } while (idx < 0 || !s->data);
41 # RUN: llc -o - %s -mtriple=x86_64-- -run-pass=branch-folder | FileCheck %s
43 ; ModuleID = 'test.ll'
44 source_filename = "test.ll"
46 %struct.bar = type { i32 }
48 define i32 @foo(i32 returned %a) local_unnamed_addr {
53 define i32 @baz(i32* %out) local_unnamed_addr !dbg !4 {
55 %0 = load i32, i32* %out, align 4
56 %call = tail call i32 @foo(i32 %0), !dbg !9
57 %cmp = icmp slt i32 %call, 0
58 br i1 %cmp, label %cleanup, label %if.then1
60 if.then1: ; preds = %entry
61 store i32 1, i32* %out, align 4
64 cleanup: ; preds = %if.then1, %entry
65 %retval.0 = phi i32 [ %call, %entry ], [ 0, %if.then1 ]
69 define i32 @test(%struct.bar* nocapture readonly %s) local_unnamed_addr !dbg !11 {
71 %idx = alloca i32, align 4
72 call void @llvm.dbg.label(metadata !20), !dbg !21
73 %call58 = call i32 @baz(i32* nonnull %idx), !dbg !22
74 %cmp69 = icmp slt i32 %call58, 0
75 br i1 %cmp69, label %if.then, label %do.cond.lr.ph.lr.ph
77 do.cond.lr.ph.lr.ph: ; preds = %entry
80 retry.loopexit: ; preds = %lor.rhs
81 call void @llvm.dbg.label(metadata !20), !dbg !21
82 %call5 = call i32 @baz(i32* nonnull %idx), !dbg !22
83 %cmp6 = icmp slt i32 %call5, 0
84 br i1 %cmp6, label %if.then, label %do.cond
86 if.then: ; preds = %do.body.backedge, %retry.loopexit, %entry
87 %call.lcssa = phi i32 [ %call58, %entry ], [ %call, %do.body.backedge ], [ %call5, %retry.loopexit ]
90 do.cond: ; preds = %retry.loopexit, %do.body.backedge, %do.cond.lr.ph.lr.ph
91 %0 = load i32, i32* %idx, align 4
92 %cmp1 = icmp slt i32 %0, 0
93 br i1 %cmp1, label %do.body.backedge, label %lor.rhs
95 lor.rhs: ; preds = %do.cond
96 %1 = bitcast %struct.bar* %s to i32*
97 %2 = load i32, i32* %1, align 4
98 %tobool = icmp eq i32 %2, 0
99 br i1 %tobool, label %do.body.backedge, label %retry.loopexit
101 do.body.backedge: ; preds = %lor.rhs, %do.cond
102 %call = call i32 @baz(i32* nonnull %idx), !dbg !22
103 %cmp = icmp slt i32 %call, 0
104 br i1 %cmp, label %if.then, label %do.cond
107 ; Function Attrs: nounwind readnone speculatable
108 declare void @llvm.dbg.label(metadata) #0
110 ; Function Attrs: nounwind
111 declare void @llvm.stackprotector(i8*, i8**) #1
113 attributes #0 = { nounwind readnone speculatable }
114 attributes #1 = { nounwind }
117 !llvm.module.flags = !{!3}
119 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: GNU)
120 !1 = !DIFile(filename: "test.c", directory: "/home/users")
122 !3 = !{i32 2, !"Debug Info Version", i32 3}
123 !4 = distinct !DISubprogram(name: "baz", scope: !1, file: !1, line: 10, type: !5, isLocal: false, isDefinition: true, scopeLine: 11, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2)
124 !5 = !DISubroutineType(types: !6)
126 !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
127 !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)
128 !9 = !DILocation(line: 14, column: 14, scope: !10)
129 !10 = distinct !DILexicalBlock(scope: !4, file: !1, line: 14, column: 7)
130 !11 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 22, type: !12, isLocal: false, isDefinition: true, scopeLine: 23, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !19)
131 !12 = !DISubroutineType(types: !13)
133 !14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64)
134 !15 = !DIDerivedType(tag: DW_TAG_typedef, name: "bar", file: !1, line: 3, baseType: !16)
135 !16 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "bar", file: !1, line: 1, size: 32, elements: !17)
137 !18 = !DIDerivedType(tag: DW_TAG_member, name: "data", scope: !16, file: !1, line: 2, baseType: !7, size: 32)
139 !20 = !DILabel(scope: !11, name: "retry", file: !1, line: 26)
140 !21 = !DILocation(line: 26, column: 1, scope: !11)
141 !22 = !DILocation(line: 28, column: 11, scope: !23)
142 !23 = distinct !DILexicalBlock(scope: !11, file: !1, line: 27, column: 6)
148 exposesReturnsTwice: false
150 regBankSelected: false
153 tracksRegLiveness: true
157 - { reg: '$edi', virtual-reg: '' }
159 isFrameAddressTaken: false
160 isReturnAddressTaken: false
170 cvBytesOfCalleeSavedRegisters: 0
171 hasOpaqueSPAdjustment: false
173 hasMustTailInVarArgFunc: false
184 renamable $eax = COPY $edi
191 exposesReturnsTwice: false
193 regBankSelected: false
196 tracksRegLiveness: true
200 - { reg: '$rdi', virtual-reg: '' }
202 isFrameAddressTaken: false
203 isReturnAddressTaken: false
213 cvBytesOfCalleeSavedRegisters: 8
214 hasOpaqueSPAdjustment: false
216 hasMustTailInVarArgFunc: false
221 - { id: 0, type: spill-slot, offset: -16, size: 8, alignment: 16, stack-id: default,
222 callee-saved-register: '$rbx', callee-saved-restored: true, debug-info-variable: '',
223 debug-info-expression: '', debug-info-location: '' }
228 successors: %bb.1(0x30000000), %bb.2(0x50000000)
231 frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp
232 CFI_INSTRUCTION def_cfa_offset 16
233 CFI_INSTRUCTION offset $rbx, -16
234 renamable $rbx = COPY $rdi
235 renamable $edi = MOV32rm $rdi, 1, $noreg, 0, $noreg :: (load 4 from %ir.out)
236 CALL64pcrel32 @foo, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !9
237 TEST32rr renamable $eax, renamable $eax, implicit-def $eflags
238 JCC_1 %bb.2, 9, implicit killed $eflags
239 ; CHECK: JCC_1 %bb.2, 8, implicit $eflags
242 successors: %bb.3(0x80000000)
248 successors: %bb.3(0x80000000)
251 MOV32mi killed renamable $rbx, 1, $noreg, 0, $noreg, 1 :: (store 4 into %ir.out)
252 renamable $eax = MOV32r0 implicit-def dead $eflags
257 $rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp
258 CFI_INSTRUCTION def_cfa_offset 8
265 exposesReturnsTwice: false
267 regBankSelected: false
270 tracksRegLiveness: true
274 - { reg: '$rdi', virtual-reg: '' }
276 isFrameAddressTaken: false
277 isReturnAddressTaken: false
287 cvBytesOfCalleeSavedRegisters: 16
288 hasOpaqueSPAdjustment: false
290 hasMustTailInVarArgFunc: false
295 - { id: 0, type: spill-slot, offset: -24, size: 8, alignment: 8, stack-id: default,
296 callee-saved-register: '$rbx', callee-saved-restored: true, debug-info-variable: '',
297 debug-info-expression: '', debug-info-location: '' }
298 - { id: 1, type: spill-slot, offset: -16, size: 8, alignment: 16, stack-id: default,
299 callee-saved-register: '$r14', callee-saved-restored: true, debug-info-variable: '',
300 debug-info-expression: '', debug-info-location: '' }
302 - { id: 0, name: idx, type: default, offset: -28, size: 4, alignment: 4,
303 stack-id: default, callee-saved-register: '', callee-saved-restored: true,
304 debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
308 successors: %bb.1(0x30000000), %bb.2(0x50000000)
309 liveins: $rdi, $r14, $rbx
311 frame-setup PUSH64r killed $r14, implicit-def $rsp, implicit $rsp
312 CFI_INSTRUCTION def_cfa_offset 16
313 frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp
314 CFI_INSTRUCTION def_cfa_offset 24
315 frame-setup PUSH64r undef $rax, implicit-def $rsp, implicit $rsp
316 CFI_INSTRUCTION def_cfa_offset 32
317 CFI_INSTRUCTION offset $rbx, -24
318 CFI_INSTRUCTION offset $r14, -16
319 renamable $rbx = COPY $rdi
320 DBG_LABEL !20, debug-location !21
321 renamable $rdi = LEA64r $rsp, 1, $noreg, 4, $noreg
322 CALL64pcrel32 @baz, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !22
323 TEST32rr renamable $eax, renamable $eax, implicit-def $eflags
324 JCC_1 %bb.2, 9, implicit killed $eflags
325 ; CHECK: JCC_1 %bb.5, 8, implicit $eflags
328 successors: %bb.5(0x80000000)
334 successors: %bb.6(0x80000000)
337 renamable $r14 = LEA64r $rsp, 1, $noreg, 4, $noreg
341 successors: %bb.4(0x04000000), %bb.6(0x7c000000)
344 DBG_LABEL !20, debug-location !21
345 $rdi = COPY renamable $r14, debug-location !22
346 CALL64pcrel32 @baz, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !22
347 TEST32rr renamable $eax, renamable $eax, implicit-def $eflags
348 JCC_1 %bb.6, 9, implicit killed $eflags
351 successors: %bb.5(0x80000000)
358 $rsp = frame-destroy ADD64ri8 $rsp, 8, implicit-def dead $eflags
359 CFI_INSTRUCTION def_cfa_offset 24
360 $rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp
361 CFI_INSTRUCTION def_cfa_offset 16
362 $r14 = frame-destroy POP64r implicit-def $rsp, implicit $rsp
363 CFI_INSTRUCTION def_cfa_offset 8
367 successors: %bb.8(0x30000000), %bb.7(0x50000000)
370 CMP32mi8 $rsp, 1, $noreg, 4, $noreg, 0, implicit-def $eflags :: (dereferenceable load 4 from %ir.idx)
371 JCC_1 %bb.8, 8, implicit killed $eflags
375 successors: %bb.8(0x30000000), %bb.3(0x50000000)
378 CMP32mi8 renamable $rbx, 1, $noreg, 0, $noreg, 0, implicit-def $eflags :: (load 4 from %ir.1)
379 JCC_1 %bb.3, 5, implicit killed $eflags
382 bb.8.do.body.backedge:
383 successors: %bb.9(0x04000000), %bb.6(0x7c000000)
386 $rdi = COPY renamable $r14, debug-location !22
387 CALL64pcrel32 @baz, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !22
388 TEST32rr renamable $eax, renamable $eax, implicit-def $eflags
389 JCC_1 %bb.6, 9, implicit killed $eflags
392 successors: %bb.5(0x80000000)