1; REQUIRES: aarch64-registered-target 2; RUN: opt -codegenprepare < %s -mtriple=aarch64-none-linux-gnu -S | FileCheck %s 3 4target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" 5target triple = "aarch64--linux-gnu" 6 7; Expect to skip merging two empty blocks (sw.bb and sw.bb2) into sw.epilog 8; as both of them are unlikely executed. 9define i32 @f_switch(i32 %c) { 10; CHECK-LABEL: @f_switch 11; CHECK-LABEL: entry: 12; CHECK: i32 10, label %sw.bb 13; CHECK: i32 20, label %sw.bb2 14entry: 15 switch i32 %c, label %sw.default [ 16 i32 10, label %sw.bb 17 i32 20, label %sw.bb2 18 i32 30, label %sw.bb3 19 i32 40, label %sw.bb4 20 ], !prof !0 21 22sw.bb: ; preds = %entry 23 br label %sw.epilog 24 25sw.bb2: ; preds = %entry 26 br label %sw.epilog 27 28sw.bb3: ; preds = %entry 29 call void bitcast (void (...)* @callcase3 to void ()*)() 30 br label %sw.epilog 31 32sw.bb4: ; preds = %entry 33 call void bitcast (void (...)* @callcase4 to void ()*)() 34 br label %sw.epilog 35 36sw.default: ; preds = %entry 37 call void bitcast (void (...)* @calldefault to void ()*)() 38 br label %sw.epilog 39 40; CHECK-LABEL: sw.epilog: 41; CHECK: %fp.0 = phi void (...)* [ @FD, %sw.default ], [ @F4, %sw.bb4 ], [ @F3, %sw.bb3 ], [ @F2, %sw.bb2 ], [ @F1, %sw.bb ] 42sw.epilog: ; preds = %sw.default, %sw.bb3, %sw.bb2, %sw.bb 43 %fp.0 = phi void (...)* [ @FD, %sw.default ], [ @F4, %sw.bb4 ], [ @F3, %sw.bb3 ], [ @F2, %sw.bb2 ], [ @F1, %sw.bb ] 44 %callee.knr.cast = bitcast void (...)* %fp.0 to void ()* 45 call void %callee.knr.cast() 46 ret i32 0 47} 48 49; Expect not to merge sw.bb2 because of the conflict in the incoming value from 50; sw.bb which is already merged. 51define i32 @f_switch2(i32 %c) { 52; CHECK-LABEL: @f_switch2 53; CHECK-LABEL: entry: 54; CHECK: i32 10, label %sw.epilog 55; CHECK: i32 20, label %sw.bb2 56entry: 57 switch i32 %c, label %sw.default [ 58 i32 10, label %sw.bb 59 i32 20, label %sw.bb2 60 i32 30, label %sw.bb3 61 i32 40, label %sw.bb4 62 ], !prof !1 63 64sw.bb: ; preds = %entry 65 br label %sw.epilog 66 67sw.bb2: ; preds = %entry 68 br label %sw.epilog 69 70sw.bb3: ; preds = %entry 71 call void bitcast (void (...)* @callcase3 to void ()*)() 72 br label %sw.epilog 73 74sw.bb4: ; preds = %entry 75 call void bitcast (void (...)* @callcase4 to void ()*)() 76 br label %sw.epilog 77 78sw.default: ; preds = %entry 79 call void bitcast (void (...)* @calldefault to void ()*)() 80 br label %sw.epilog 81 82; CHECK-LABEL: sw.epilog: 83; CHECK: %fp.0 = phi void (...)* [ @FD, %sw.default ], [ @F4, %sw.bb4 ], [ @F3, %sw.bb3 ], [ @F2, %sw.bb2 ], [ @F1, %entry ] 84sw.epilog: ; preds = %sw.default, %sw.bb3, %sw.bb2, %sw.bb 85 %fp.0 = phi void (...)* [ @FD, %sw.default ], [ @F4, %sw.bb4 ], [ @F3, %sw.bb3 ], [ @F2, %sw.bb2 ], [ @F1, %sw.bb ] 86 %callee.knr.cast = bitcast void (...)* %fp.0 to void ()* 87 call void %callee.knr.cast() 88 ret i32 0 89} 90 91; Multiple empty blocks should be considered together if all incoming values 92; from them are same. We expect to merge both empty blocks (sw.bb and sw.bb2) 93; because the sum of frequencies are higer than the threshold. 94define i32 @f_switch3(i32 %c) { 95; CHECK-LABEL: @f_switch3 96; CHECK-LABEL: entry: 97; CHECK: i32 10, label %sw.epilog 98; CHECK: i32 20, label %sw.epilog 99entry: 100 switch i32 %c, label %sw.default [ 101 i32 10, label %sw.bb 102 i32 20, label %sw.bb2 103 i32 30, label %sw.bb3 104 i32 40, label %sw.bb4 105 ], !prof !2 106 107sw.bb: ; preds = %entry 108 br label %sw.epilog 109 110sw.bb2: ; preds = %entry 111 br label %sw.epilog 112 113sw.bb3: ; preds = %entry 114 call void bitcast (void (...)* @callcase3 to void ()*)() 115 br label %sw.epilog 116 117sw.bb4: ; preds = %entry 118 call void bitcast (void (...)* @callcase4 to void ()*)() 119 br label %sw.epilog 120 121sw.default: ; preds = %entry 122 call void bitcast (void (...)* @calldefault to void ()*)() 123 br label %sw.epilog 124 125; CHECK-LABEL: sw.epilog: 126; CHECK: %fp.0 = phi void (...)* [ @FD, %sw.default ], [ @F4, %sw.bb4 ], [ @F3, %sw.bb3 ], [ @F1, %entry ], [ @F1, %entry ] 127sw.epilog: ; preds = %sw.default, %sw.bb3, %sw.bb2, %sw.bb 128 %fp.0 = phi void (...)* [ @FD, %sw.default ], [ @F4, %sw.bb4 ], [ @F3, %sw.bb3 ], [ @F1, %sw.bb2 ], [ @F1, %sw.bb ] 129 %callee.knr.cast = bitcast void (...)* %fp.0 to void ()* 130 call void %callee.knr.cast() 131 ret i32 0 132} 133 134declare void @F1(...) local_unnamed_addr 135declare void @F2(...) local_unnamed_addr 136declare void @F3(...) local_unnamed_addr 137declare void @F4(...) local_unnamed_addr 138declare void @FD(...) local_unnamed_addr 139declare void @callcase3(...) local_unnamed_addr 140declare void @callcase4(...) local_unnamed_addr 141declare void @calldefault(...) local_unnamed_addr 142 143!0 = !{!"branch_weights", i32 5, i32 1, i32 1,i32 5, i32 5} 144!1 = !{!"branch_weights", i32 1 , i32 5, i32 1,i32 1, i32 1} 145!2 = !{!"branch_weights", i32 1 , i32 4, i32 1,i32 1, i32 1} 146 147 148; This test that BFI/BPI is created without any assertion in isMergingEmptyBlockProfitable() 149; in the case where empty blocks are removed before creating BFI/BPI. 150@b = common global i32 0, align 4 151@a = common global i32* null, align 8 152define i32 @should_not_assert(i32 %i) local_unnamed_addr { 153entry: 154 %0 = load i32, i32* @b, align 4 155 %cond = icmp eq i32 %0, 6 156 br i1 %cond, label %while.cond.preheader, label %sw.epilog 157 158while.cond.preheader: ; preds = %entry 159 %1 = load i32*, i32** @a, align 8 160 %magicptr = ptrtoint i32* %1 to i64 161 %arrayidx = getelementptr inbounds i32, i32* %1, i64 1 162 br label %while.cond 163 164while.cond: ; preds = %while.cond.preheader, %land.rhs 165 switch i64 %magicptr, label %land.rhs [ 166 i64 32, label %while.cond2.loopexit 167 i64 0, label %while.cond2.loopexit 168 ] 169 170land.rhs: ; preds = %while.cond 171 %2 = load i32, i32* %arrayidx, align 4 172 %tobool1 = icmp eq i32 %2, 0 173 br i1 %tobool1, label %while.cond2thread-pre-split.loopexit, label %while.cond 174 175while.cond2thread-pre-split.loopexit: ; preds = %land.rhs 176 br label %while.cond2thread-pre-split 177 178while.cond2thread-pre-split: ; preds = %while.cond2thread-pre-split.loopexit, %while.body4 179 %.pr = phi i32* [ %.pr.pre, %while.body4 ], [ %1, %while.cond2thread-pre-split.loopexit ] 180 br label %while.cond2 181 182while.cond2.loopexit: ; preds = %while.cond, %while.cond 183 br label %while.cond2 184 185while.cond2: ; preds = %while.cond2.loopexit, %while.cond2thread-pre-split 186 %3 = phi i32* [ %.pr, %while.cond2thread-pre-split ], [ %1, %while.cond2.loopexit ] 187 %tobool3 = icmp eq i32* %3, null 188 br i1 %tobool3, label %sw.epilog, label %while.body4 189 190while.body4: ; preds = %while.cond2 191 tail call void bitcast (void (...)* @fn2 to void ()*)() 192 %.pr.pre = load i32*, i32** @a, align 8 193 br label %while.cond2thread-pre-split 194 195sw.epilog: ; preds = %while.cond2, %entry 196 ret i32 undef 197} 198 199 200declare void @fn2(...) local_unnamed_addr 201 202