399 lines · plain
1# Generated with2#3# clang -g -O1 -S -emit-llvm test.c4# llc -stop-before=branch-folder test.ll5#6# typedef struct bar {7# int data;8# } bar;9#10# int foo(int a)11# {12# return a;13# }14#15# int baz(int *out)16# {17# int ret;18#19# if ((ret = foo(*out)) < 0)20# return ret;21# if (out)22# *out = 1;23#24# return 0;25# }26#27# int test(bar *s)28# {29# int idx, ret;30#31# retry:32# do {33# ret = baz(&idx);34# if (ret < 0)35# return ret;36# } while (idx < 0 || !s->data);37#38# goto retry;39# }40#41# RUN: llc -o - %s -mtriple=x86_64-- -run-pass=branch-folder | FileCheck %s42# RUN: llc -o - %s -mtriple=x86_64-- -passes="require<profile-summary>,function(machine-function(branch-folder<enable-tail-merge>))" | FileCheck %s43--- |44 ; ModuleID = 'test.ll'45 source_filename = "test.ll"46 47 %struct.bar = type { i32 }48 49 define i32 @foo(i32 returned %a) local_unnamed_addr {50 entry:51 ret i32 %a52 }53 54 define i32 @baz(ptr %out) local_unnamed_addr !dbg !4 {55 entry:56 %0 = load i32, ptr %out, align 457 %call = tail call i32 @foo(i32 %0), !dbg !958 %cmp = icmp slt i32 %call, 059 br i1 %cmp, label %cleanup, label %if.then160 61 if.then1: ; preds = %entry62 store i32 1, ptr %out, align 463 br label %cleanup64 65 cleanup: ; preds = %if.then1, %entry66 %retval.0 = phi i32 [ %call, %entry ], [ 0, %if.then1 ]67 ret i32 %retval.068 }69 70 define i32 @test(ptr nocapture readonly %s) local_unnamed_addr !dbg !11 {71 entry:72 %idx = alloca i32, align 473 call void @llvm.dbg.label(metadata !20), !dbg !2174 %call58 = call i32 @baz(ptr nonnull %idx), !dbg !2275 %cmp69 = icmp slt i32 %call58, 076 br i1 %cmp69, label %if.then, label %do.cond.lr.ph.lr.ph77 78 do.cond.lr.ph.lr.ph: ; preds = %entry79 br label %do.cond80 81 retry.loopexit: ; preds = %lor.rhs82 call void @llvm.dbg.label(metadata !20), !dbg !2183 %call5 = call i32 @baz(ptr nonnull %idx), !dbg !2284 %cmp6 = icmp slt i32 %call5, 085 br i1 %cmp6, label %if.then, label %do.cond86 87 if.then: ; preds = %do.body.backedge, %retry.loopexit, %entry88 %call.lcssa = phi i32 [ %call58, %entry ], [ %call, %do.body.backedge ], [ %call5, %retry.loopexit ]89 ret i32 %call.lcssa90 91 do.cond: ; preds = %retry.loopexit, %do.body.backedge, %do.cond.lr.ph.lr.ph92 %0 = load i32, ptr %idx, align 493 %cmp1 = icmp slt i32 %0, 094 br i1 %cmp1, label %do.body.backedge, label %lor.rhs95 96 lor.rhs: ; preds = %do.cond97 %1 = bitcast ptr %s to ptr98 %2 = load i32, ptr %1, align 499 %tobool = icmp eq i32 %2, 0100 br i1 %tobool, label %do.body.backedge, label %retry.loopexit101 102 do.body.backedge: ; preds = %lor.rhs, %do.cond103 %call = call i32 @baz(ptr nonnull %idx), !dbg !22104 %cmp = icmp slt i32 %call, 0105 br i1 %cmp, label %if.then, label %do.cond106 }107 108 ; Function Attrs: nounwind readnone speculatable109 declare void @llvm.dbg.label(metadata) #0110 111 ; Function Attrs: nounwind112 declare void @llvm.stackprotector(ptr, ptr) #1113 114 attributes #0 = { nounwind readnone speculatable }115 attributes #1 = { nounwind }116 117 !llvm.dbg.cu = !{!0}118 !llvm.module.flags = !{!3}119 120 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: GNU)121 !1 = !DIFile(filename: "test.c", directory: "/home/users")122 !2 = !{}123 !3 = !{i32 2, !"Debug Info Version", i32 3}124 !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)125 !5 = !DISubroutineType(types: !6)126 !6 = !{!7, !8}127 !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)128 !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)129 !9 = !DILocation(line: 14, column: 14, scope: !10)130 !10 = distinct !DILexicalBlock(scope: !4, file: !1, line: 14, column: 7)131 !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)132 !12 = !DISubroutineType(types: !13)133 !13 = !{!7, !14}134 !14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64)135 !15 = !DIDerivedType(tag: DW_TAG_typedef, name: "bar", file: !1, line: 3, baseType: !16)136 !16 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "bar", file: !1, line: 1, size: 32, elements: !17)137 !17 = !{!18}138 !18 = !DIDerivedType(tag: DW_TAG_member, name: "data", scope: !16, file: !1, line: 2, baseType: !7, size: 32)139 !19 = !{!20}140 !20 = !DILabel(scope: !11, name: "retry", file: !1, line: 26)141 !21 = !DILocation(line: 26, column: 1, scope: !11)142 !22 = !DILocation(line: 28, column: 11, scope: !23)143 !23 = distinct !DILexicalBlock(scope: !11, file: !1, line: 27, column: 6)144 145...146---147name: foo148alignment: 16149exposesReturnsTwice: false150legalized: false151regBankSelected: false152selected: false153failedISel: false154tracksRegLiveness: true155hasWinCFI: false156registers: 157liveins: 158 - { reg: '$edi', virtual-reg: '' }159frameInfo: 160 isFrameAddressTaken: false161 isReturnAddressTaken: false162 hasStackMap: false163 hasPatchPoint: false164 stackSize: 0165 offsetAdjustment: 0166 maxAlignment: 0167 adjustsStack: false168 hasCalls: false169 stackProtector: ''170 maxCallFrameSize: 0171 cvBytesOfCalleeSavedRegisters: 0172 hasOpaqueSPAdjustment: false173 hasVAStart: false174 hasMustTailInVarArgFunc: false175 localFrameSize: 0176 savePoint: []177 restorePoint: []178fixedStack: 179stack: 180constants: 181body: |182 bb.0.entry:183 liveins: $edi184 185 renamable $eax = COPY $edi186 RET 0, $eax187 188...189---190name: baz191alignment: 16192exposesReturnsTwice: false193legalized: false194regBankSelected: false195selected: false196failedISel: false197tracksRegLiveness: true198hasWinCFI: false199registers: 200liveins: 201 - { reg: '$rdi', virtual-reg: '' }202frameInfo: 203 isFrameAddressTaken: false204 isReturnAddressTaken: false205 hasStackMap: false206 hasPatchPoint: false207 stackSize: 8208 offsetAdjustment: 0209 maxAlignment: 0210 adjustsStack: true211 hasCalls: true212 stackProtector: ''213 maxCallFrameSize: 0214 cvBytesOfCalleeSavedRegisters: 8215 hasOpaqueSPAdjustment: false216 hasVAStart: false217 hasMustTailInVarArgFunc: false218 localFrameSize: 0219 savePoint: []220 restorePoint: []221fixedStack: 222 - { id: 0, type: spill-slot, offset: -16, size: 8, alignment: 16, stack-id: default,223 callee-saved-register: '$rbx', callee-saved-restored: true, debug-info-variable: '', 224 debug-info-expression: '', debug-info-location: '' }225stack: 226constants: 227body: |228 bb.0.entry:229 successors: %bb.1(0x30000000), %bb.2(0x50000000)230 liveins: $rdi, $rbx231 232 frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp233 CFI_INSTRUCTION def_cfa_offset 16234 CFI_INSTRUCTION offset $rbx, -16235 renamable $rbx = COPY $rdi236 renamable $edi = MOV32rm $rdi, 1, $noreg, 0, $noreg :: (load (s32) from %ir.out)237 CALL64pcrel32 @foo, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !9238 TEST32rr renamable $eax, renamable $eax, implicit-def $eflags239 JCC_1 %bb.2, 9, implicit killed $eflags240 ; CHECK: JCC_1 %bb.2, 8, implicit $eflags241 242 bb.1:243 successors: %bb.3(0x80000000)244 liveins: $eax245 246 JMP_1 %bb.3247 248 bb.2.if.then1:249 successors: %bb.3(0x80000000)250 liveins: $rbx251 252 MOV32mi killed renamable $rbx, 1, $noreg, 0, $noreg, 1 :: (store (s32) into %ir.out)253 renamable $eax = MOV32r0 implicit-def dead $eflags254 255 bb.3.cleanup:256 liveins: $eax257 258 $rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp259 CFI_INSTRUCTION def_cfa_offset 8260 RET 0, $eax261 262...263---264name: test265alignment: 16266exposesReturnsTwice: false267legalized: false268regBankSelected: false269selected: false270failedISel: false271tracksRegLiveness: true272hasWinCFI: false273registers: 274liveins: 275 - { reg: '$rdi', virtual-reg: '' }276frameInfo: 277 isFrameAddressTaken: false278 isReturnAddressTaken: false279 hasStackMap: false280 hasPatchPoint: false281 stackSize: 24282 offsetAdjustment: 0283 maxAlignment: 4284 adjustsStack: true285 hasCalls: true286 stackProtector: ''287 maxCallFrameSize: 0288 cvBytesOfCalleeSavedRegisters: 16289 hasOpaqueSPAdjustment: false290 hasVAStart: false291 hasMustTailInVarArgFunc: false292 localFrameSize: 0293 savePoint: []294 restorePoint: []295fixedStack: 296 - { id: 0, type: spill-slot, offset: -24, size: 8, alignment: 8, stack-id: default,297 callee-saved-register: '$rbx', callee-saved-restored: true, debug-info-variable: '', 298 debug-info-expression: '', debug-info-location: '' }299 - { id: 1, type: spill-slot, offset: -16, size: 8, alignment: 16, stack-id: default,300 callee-saved-register: '$r14', callee-saved-restored: true, debug-info-variable: '', 301 debug-info-expression: '', debug-info-location: '' }302stack: 303 - { id: 0, name: idx, type: default, offset: -28, size: 4, alignment: 4, 304 stack-id: default, callee-saved-register: '', callee-saved-restored: true,305 debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }306constants: 307body: |308 bb.0.entry:309 successors: %bb.1(0x30000000), %bb.2(0x50000000)310 liveins: $rdi, $r14, $rbx311 312 frame-setup PUSH64r killed $r14, implicit-def $rsp, implicit $rsp313 CFI_INSTRUCTION def_cfa_offset 16314 frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp315 CFI_INSTRUCTION def_cfa_offset 24316 frame-setup PUSH64r undef $rax, implicit-def $rsp, implicit $rsp317 CFI_INSTRUCTION def_cfa_offset 32318 CFI_INSTRUCTION offset $rbx, -24319 CFI_INSTRUCTION offset $r14, -16320 renamable $rbx = COPY $rdi321 DBG_LABEL !20, debug-location !21322 renamable $rdi = LEA64r $rsp, 1, $noreg, 4, $noreg323 CALL64pcrel32 @baz, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !22324 TEST32rr renamable $eax, renamable $eax, implicit-def $eflags325 JCC_1 %bb.2, 9, implicit killed $eflags326 ; CHECK: JCC_1 %bb.5, 8, implicit $eflags327 328 bb.1:329 successors: %bb.5(0x80000000)330 liveins: $eax331 332 JMP_1 %bb.5333 334 bb.2:335 successors: %bb.6(0x80000000)336 liveins: $rbx337 338 renamable $r14 = LEA64r $rsp, 1, $noreg, 4, $noreg339 JMP_1 %bb.6340 341 bb.3.retry.loopexit:342 successors: %bb.4(0x04000000), %bb.6(0x7c000000)343 liveins: $rbx, $r14344 345 DBG_LABEL !20, debug-location !21346 $rdi = COPY renamable $r14, debug-location !22347 CALL64pcrel32 @baz, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !22348 TEST32rr renamable $eax, renamable $eax, implicit-def $eflags349 JCC_1 %bb.6, 9, implicit killed $eflags350 351 bb.4:352 successors: %bb.5(0x80000000)353 liveins: $eax354 355 356 bb.5.if.then:357 liveins: $eax358 359 $rsp = frame-destroy ADD64ri32 $rsp, 8, implicit-def dead $eflags360 CFI_INSTRUCTION def_cfa_offset 24361 $rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp362 CFI_INSTRUCTION def_cfa_offset 16363 $r14 = frame-destroy POP64r implicit-def $rsp, implicit $rsp364 CFI_INSTRUCTION def_cfa_offset 8365 RET 0, $eax366 367 bb.6.do.cond:368 successors: %bb.8(0x30000000), %bb.7(0x50000000)369 liveins: $rbx, $r14370 371 CMP32mi $rsp, 1, $noreg, 4, $noreg, 0, implicit-def $eflags :: (dereferenceable load (s32) from %ir.idx)372 JCC_1 %bb.8, 8, implicit killed $eflags373 JMP_1 %bb.7374 375 bb.7.lor.rhs:376 successors: %bb.8(0x30000000), %bb.3(0x50000000)377 liveins: $rbx, $r14378 379 CMP32mi renamable $rbx, 1, $noreg, 0, $noreg, 0, implicit-def $eflags :: (load (s32) from %ir.1)380 JCC_1 %bb.3, 5, implicit killed $eflags381 JMP_1 %bb.8382 383 bb.8.do.body.backedge:384 successors: %bb.9(0x04000000), %bb.6(0x7c000000)385 liveins: $rbx, $r14386 387 $rdi = COPY renamable $r14, debug-location !22388 CALL64pcrel32 @baz, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !22389 TEST32rr renamable $eax, renamable $eax, implicit-def $eflags390 JCC_1 %bb.6, 9, implicit killed $eflags391 392 bb.9:393 successors: %bb.5(0x80000000)394 liveins: $eax395 396 JMP_1 %bb.5397 398...399