140 lines · plain
1# RUN: llc -run-pass=branch-folder %s -o - | FileCheck %s2 3# PR339804 5# Don't form conditional tail calls when the original conditional branch has6# the same true and false destination. Otherwise, when we remove the tail call7# successor we will also remove the fallthrough successor from the CFG.8 9# CHECK: body: |10# CHECK: bb.0.entry:11# CHECK: successors: %bb.1(0x40000000)12# CHECK: liveins: $edi13# CHECK: CMP32ri8 killed $edi, 2, implicit-def $eflags14# CHECK: TCRETURNdi64cc @mergeable_conditional_tailcall15 16# This was the unconditional branch to a dead MBB that we left behind before17# this bug was fixed.18# CHECK-NOT: JMP_1 %bb.-119 20--- |21 ; ModuleID = 't.ll'22 source_filename = "t.ll"23 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"24 target triple = "x86_64--linux"25 26 @static_local_guard = external global i64, align 827 28 ; Function Attrs: optsize29 define void @f(i32 %arg) #0 {30 entry:31 switch i32 %arg, label %sw.epilog [32 i32 0, label %sw.bb33 i32 1, label %sw.bb34 i32 2, label %sw.bb235 ]36 37 sw.bb: ; preds = %entry, %entry38 %tmp = load atomic i8, i8* bitcast (i64* @static_local_guard to i8*) acquire, align 839 %guard.uninitialized.i = icmp eq i8 %tmp, 040 br i1 %guard.uninitialized.i, label %init.check.i, label %return, !prof !041 42 init.check.i: ; preds = %sw.bb43 tail call void @initialize_static_local(i64* nonnull @static_local_guard)44 ret void45 46 sw.bb2: ; preds = %entry47 tail call void @mergeable_conditional_tailcall()48 ret void49 50 sw.epilog: ; preds = %entry51 tail call void @mergeable_conditional_tailcall()52 ret void53 54 return: ; preds = %sw.bb55 ret void56 }57 58 declare void @mergeable_conditional_tailcall()59 60 declare void @initialize_static_local(i64*)61 62 ; Function Attrs: nounwind63 declare void @llvm.stackprotector(i8*, i8**) #164 65 attributes #0 = { optsize }66 attributes #1 = { nounwind }67 68 !0 = !{!"branch_weights", i32 1, i32 1048575}69 70...71---72name: f73alignment: 174exposesReturnsTwice: false75legalized: false76regBankSelected: false77selected: false78tracksRegLiveness: true79registers:80liveins:81 - { reg: '$edi', virtual-reg: '' }82frameInfo:83 isFrameAddressTaken: false84 isReturnAddressTaken: false85 hasStackMap: false86 hasPatchPoint: false87 stackSize: 088 offsetAdjustment: 089 maxAlignment: 090 adjustsStack: false91 hasCalls: false92 stackProtector: ''93 maxCallFrameSize: 094 hasOpaqueSPAdjustment: false95 hasVAStart: false96 hasMustTailInVarArgFunc: false97 savePoint: []98 restorePoint: []99fixedStack:100stack:101constants:102body: |103 bb.0.entry:104 successors: %bb.2(0x40000000), %bb.1(0x40000000)105 liveins: $edi106 107 CMP32ri8 killed $edi, 2, implicit-def $eflags108 JCC_1 %bb.2, 2, implicit $eflags109 JMP_1 %bb.1110 111 bb.1.entry:112 successors: %bb.4(0x40000000), %bb.5(0x40000000)113 liveins: $eflags114 115 JCC_1 %bb.4, 4, implicit killed $eflags116 JMP_1 %bb.5117 118 bb.2.sw.bb:119 successors: %bb.3(0x00000800), %bb.6(0x7ffff800)120 121 $al = MOV8rm $rip, 1, $noreg, @static_local_guard, $noreg :: (volatile load acquire (s8) from `i8* bitcast (i64* @static_local_guard to i8*)`, align 8)122 TEST8rr killed $al, $al, implicit-def $eflags123 JCC_1 %bb.6, 5, implicit killed $eflags124 JMP_1 %bb.3125 126 bb.3.init.check.i:127 dead $edi = MOV32ri @static_local_guard, implicit-def $rdi128 TCRETURNdi64 @initialize_static_local, 0, csr_64, implicit $rsp, implicit $rdi129 130 bb.4.sw.bb2:131 TCRETURNdi64 @mergeable_conditional_tailcall, 0, csr_64, implicit $rsp132 133 bb.5.sw.epilog:134 TCRETURNdi64 @mergeable_conditional_tailcall, 0, csr_64, implicit $rsp135 136 bb.6.return:137 RET 0138 139...140