1b3bd7328SNikita Popov; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2cee313d2SEric Christopher; RUN: opt -S -jump-threading < %s | FileCheck %s 3cee313d2SEric Christopher 4cee313d2SEric Christopherdeclare void @foo() 5cee313d2SEric Christopherdeclare void @bar() 6cee313d2SEric Christopherdeclare void @baz() 7cee313d2SEric Christopherdeclare void @quux() 8cee313d2SEric Christopher 9cee313d2SEric Christopher 10cee313d2SEric Christopher; Jump threading of branch with select as condition. 11cee313d2SEric Christopher; Mostly theoretical since instruction combining simplifies all selects of 12cee313d2SEric Christopher; booleans where at least one operand is true/false/undef. 13cee313d2SEric Christopher 14b3bd7328SNikita Popovdefine void @test_br(i1 %cond, i1 %value) nounwind { 15cee313d2SEric Christopher; CHECK-LABEL: @test_br( 16cee313d2SEric Christopher; CHECK-NEXT: entry: 17b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[COND:%.*]], label [[L1:%.*]], label [[L0:%.*]] 18b3bd7328SNikita Popov; CHECK: L0: 19b3bd7328SNikita Popov; CHECK-NEXT: call void @baz() 20b3bd7328SNikita Popov; CHECK-NEXT: [[EXPR:%.*]] = select i1 [[COND]], i1 true, i1 [[VALUE:%.*]] 21b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[EXPR]], label [[L1]], label [[L2:%.*]] 22b3bd7328SNikita Popov; CHECK: L1: 23b3bd7328SNikita Popov; CHECK-NEXT: call void @foo() 24b3bd7328SNikita Popov; CHECK-NEXT: ret void 25b3bd7328SNikita Popov; CHECK: L2: 26b3bd7328SNikita Popov; CHECK-NEXT: call void @bar() 27b3bd7328SNikita Popov; CHECK-NEXT: ret void 28b3bd7328SNikita Popov; 29cee313d2SEric Christopherentry: 30cee313d2SEric Christopher br i1 %cond, label %L0, label %L3 31cee313d2SEric ChristopherL0: 32cee313d2SEric Christopher %expr = select i1 %cond, i1 true, i1 %value 33cee313d2SEric Christopher br i1 %expr, label %L1, label %L2 34cee313d2SEric Christopher 35cee313d2SEric ChristopherL1: 36cee313d2SEric Christopher call void @foo() 37cee313d2SEric Christopher ret void 38cee313d2SEric ChristopherL2: 39cee313d2SEric Christopher call void @bar() 40cee313d2SEric Christopher ret void 41cee313d2SEric ChristopherL3: 42cee313d2SEric Christopher call void @baz() 43cee313d2SEric Christopher br label %L0 44cee313d2SEric Christopher} 45cee313d2SEric Christopher 46cee313d2SEric Christopher 47cee313d2SEric Christopher; Jump threading of switch with select as condition. 48cee313d2SEric Christopher 49b3bd7328SNikita Popovdefine void @test_switch(i1 %cond, i8 %value) nounwind { 50cee313d2SEric Christopher; CHECK-LABEL: @test_switch( 51cee313d2SEric Christopher; CHECK-NEXT: entry: 52b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[COND:%.*]], label [[L1:%.*]], label [[L0:%.*]] 53b3bd7328SNikita Popov; CHECK: L0: 54b3bd7328SNikita Popov; CHECK-NEXT: call void @quux() 55b3bd7328SNikita Popov; CHECK-NEXT: [[EXPR:%.*]] = select i1 [[COND]], i8 1, i8 [[VALUE:%.*]] 56b3bd7328SNikita Popov; CHECK-NEXT: switch i8 [[EXPR]], label [[L3:%.*]] [ 57b3bd7328SNikita Popov; CHECK-NEXT: i8 1, label [[L1]] 58b3bd7328SNikita Popov; CHECK-NEXT: i8 2, label [[L2:%.*]] 59b3bd7328SNikita Popov; CHECK-NEXT: ] 60b3bd7328SNikita Popov; CHECK: L1: 61b3bd7328SNikita Popov; CHECK-NEXT: call void @foo() 62b3bd7328SNikita Popov; CHECK-NEXT: ret void 63b3bd7328SNikita Popov; CHECK: L2: 64b3bd7328SNikita Popov; CHECK-NEXT: call void @bar() 65b3bd7328SNikita Popov; CHECK-NEXT: ret void 66b3bd7328SNikita Popov; CHECK: L3: 67b3bd7328SNikita Popov; CHECK-NEXT: call void @baz() 68b3bd7328SNikita Popov; CHECK-NEXT: ret void 69b3bd7328SNikita Popov; 70cee313d2SEric Christopherentry: 71cee313d2SEric Christopher br i1 %cond, label %L0, label %L4 72cee313d2SEric ChristopherL0: 73cee313d2SEric Christopher %expr = select i1 %cond, i8 1, i8 %value 74cee313d2SEric Christopher switch i8 %expr, label %L3 [i8 1, label %L1 i8 2, label %L2] 75cee313d2SEric Christopher 76cee313d2SEric ChristopherL1: 77cee313d2SEric Christopher call void @foo() 78cee313d2SEric Christopher ret void 79cee313d2SEric ChristopherL2: 80cee313d2SEric Christopher call void @bar() 81cee313d2SEric Christopher ret void 82cee313d2SEric ChristopherL3: 83cee313d2SEric Christopher call void @baz() 84cee313d2SEric Christopher ret void 85cee313d2SEric ChristopherL4: 86cee313d2SEric Christopher call void @quux() 87cee313d2SEric Christopher br label %L0 88cee313d2SEric Christopher} 89cee313d2SEric Christopher 90cee313d2SEric Christopher; Make sure the blocks in the indirectbr test aren't trivially removable as 91cee313d2SEric Christopher; successors by taking their addresses. 92cee313d2SEric Christopher@anchor = constant [3 x i8*] [ 93cee313d2SEric Christopher i8* blockaddress(@test_indirectbr, %L1), 94cee313d2SEric Christopher i8* blockaddress(@test_indirectbr, %L2), 95cee313d2SEric Christopher i8* blockaddress(@test_indirectbr, %L3) 96cee313d2SEric Christopher] 97cee313d2SEric Christopher 98cee313d2SEric Christopher 99cee313d2SEric Christopher; Jump threading of indirectbr with select as address. 100cee313d2SEric Christopher 101b3bd7328SNikita Popovdefine void @test_indirectbr(i1 %cond, i8* %address) nounwind { 102cee313d2SEric Christopher; CHECK-LABEL: @test_indirectbr( 103cee313d2SEric Christopher; CHECK-NEXT: entry: 104b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[COND:%.*]], label [[L1:%.*]], label [[L3:%.*]] 105b3bd7328SNikita Popov; CHECK: L1: 106b3bd7328SNikita Popov; CHECK-NEXT: call void @foo() 107b3bd7328SNikita Popov; CHECK-NEXT: ret void 108b3bd7328SNikita Popov; CHECK: L3: 109b3bd7328SNikita Popov; CHECK-NEXT: call void @baz() 110b3bd7328SNikita Popov; CHECK-NEXT: ret void 111b3bd7328SNikita Popov; 112cee313d2SEric Christopherentry: 113cee313d2SEric Christopher br i1 %cond, label %L0, label %L3 114cee313d2SEric ChristopherL0: 115cee313d2SEric Christopher %indirect.goto.dest = select i1 %cond, i8* blockaddress(@test_indirectbr, %L1), i8* %address 116cee313d2SEric Christopher indirectbr i8* %indirect.goto.dest, [label %L1, label %L2, label %L3] 117cee313d2SEric Christopher 118cee313d2SEric ChristopherL1: 119cee313d2SEric Christopher call void @foo() 120cee313d2SEric Christopher ret void 121cee313d2SEric ChristopherL2: 122cee313d2SEric Christopher call void @bar() 123cee313d2SEric Christopher ret void 124cee313d2SEric ChristopherL3: 125cee313d2SEric Christopher call void @baz() 126cee313d2SEric Christopher ret void 127cee313d2SEric Christopher} 128cee313d2SEric Christopher 129cee313d2SEric Christopher 130cee313d2SEric Christopher; Jump threading of indirectbr with select as address. Test increased 131cee313d2SEric Christopher; duplication threshold for cases where indirectbr is being threaded 132cee313d2SEric Christopher; through. 133cee313d2SEric Christopher 134b3bd7328SNikita Popovdefine void @test_indirectbr_thresh(i1 %cond, i8* %address) nounwind { 135cee313d2SEric Christopher; CHECK-LABEL: @test_indirectbr_thresh( 136cee313d2SEric Christopher; CHECK-NEXT: entry: 137b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[COND:%.*]], label [[L1:%.*]], label [[L3:%.*]] 138b3bd7328SNikita Popov; CHECK: L1: 139b3bd7328SNikita Popov; CHECK-NEXT: call void @quux() 140b3bd7328SNikita Popov; CHECK-NEXT: call void @quux() 141b3bd7328SNikita Popov; CHECK-NEXT: call void @quux() 142b3bd7328SNikita Popov; CHECK-NEXT: call void @foo() 143b3bd7328SNikita Popov; CHECK-NEXT: ret void 144b3bd7328SNikita Popov; CHECK: L3: 145b3bd7328SNikita Popov; CHECK-NEXT: call void @baz() 146b3bd7328SNikita Popov; CHECK-NEXT: ret void 147b3bd7328SNikita Popov; 148cee313d2SEric Christopherentry: 149cee313d2SEric Christopher br i1 %cond, label %L0, label %L3 150cee313d2SEric ChristopherL0: 151cee313d2SEric Christopher %indirect.goto.dest = select i1 %cond, i8* blockaddress(@test_indirectbr_thresh, %L1), i8* %address 152cee313d2SEric Christopher call void @quux() 153cee313d2SEric Christopher call void @quux() 154cee313d2SEric Christopher call void @quux() 155cee313d2SEric Christopher indirectbr i8* %indirect.goto.dest, [label %L1, label %L2, label %L3] 156cee313d2SEric Christopher 157cee313d2SEric ChristopherL1: 158cee313d2SEric Christopher call void @foo() 159cee313d2SEric Christopher ret void 160cee313d2SEric ChristopherL2: 161cee313d2SEric Christopher call void @bar() 162cee313d2SEric Christopher ret void 163cee313d2SEric ChristopherL3: 164cee313d2SEric Christopher call void @baz() 165cee313d2SEric Christopher ret void 166cee313d2SEric Christopher} 167cee313d2SEric Christopher 168cee313d2SEric Christopher 169cee313d2SEric Christopher; A more complicated case: the condition is a select based on a comparison. 170cee313d2SEric Christopher 171b3bd7328SNikita Popovdefine void @test_switch_cmp(i1 %cond, i32 %val, i8 %value) nounwind { 172cee313d2SEric Christopher; CHECK-LABEL: @test_switch_cmp( 173cee313d2SEric Christopher; CHECK-NEXT: entry: 174b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[COND:%.*]], label [[L0:%.*]], label [[L0_THREAD:%.*]] 175b3bd7328SNikita Popov; CHECK: L0: 176b3bd7328SNikita Popov; CHECK-NEXT: [[VAL_PHI:%.*]] = phi i32 [ [[VAL:%.*]], [[ENTRY:%.*]] ] 177b3bd7328SNikita Popov; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[VAL_PHI]], 0 178*6f0ca6fdSNikita Popov; CHECK-NEXT: [[COND_FR:%.*]] = freeze i1 [[CMP]] 179*6f0ca6fdSNikita Popov; CHECK-NEXT: br i1 [[COND_FR]], label [[L1:%.*]], label [[TMP0:%.*]] 180b3bd7328SNikita Popov; CHECK: 0: 181b3bd7328SNikita Popov; CHECK-NEXT: [[TMP1:%.*]] = phi i8 [ [[VALUE:%.*]], [[L0]] ] 182b3bd7328SNikita Popov; CHECK-NEXT: switch i8 [[TMP1]], label [[L3:%.*]] [ 183b3bd7328SNikita Popov; CHECK-NEXT: i8 1, label [[L1]] 184b3bd7328SNikita Popov; CHECK-NEXT: i8 2, label [[L2:%.*]] 185b3bd7328SNikita Popov; CHECK-NEXT: ] 186b3bd7328SNikita Popov; CHECK: L1: 187b3bd7328SNikita Popov; CHECK-NEXT: call void @foo() 188b3bd7328SNikita Popov; CHECK-NEXT: ret void 189b3bd7328SNikita Popov; CHECK: L2: 190b3bd7328SNikita Popov; CHECK-NEXT: call void @bar() 191b3bd7328SNikita Popov; CHECK-NEXT: ret void 192b3bd7328SNikita Popov; CHECK: L3: 193b3bd7328SNikita Popov; CHECK-NEXT: call void @baz() 194b3bd7328SNikita Popov; CHECK-NEXT: ret void 195b3bd7328SNikita Popov; CHECK: L0.thread: 196b3bd7328SNikita Popov; CHECK-NEXT: call void @quux() 197b3bd7328SNikita Popov; CHECK-NEXT: br label [[L1]] 198b3bd7328SNikita Popov; 199cee313d2SEric Christopherentry: 200cee313d2SEric Christopher br i1 %cond, label %L0, label %L4 201cee313d2SEric ChristopherL0: 202cee313d2SEric Christopher %val.phi = phi i32 [%val, %entry], [-1, %L4] 203cee313d2SEric Christopher %cmp = icmp slt i32 %val.phi, 0 204cee313d2SEric Christopher %expr = select i1 %cmp, i8 1, i8 %value 205cee313d2SEric Christopher switch i8 %expr, label %L3 [i8 1, label %L1 i8 2, label %L2] 206cee313d2SEric Christopher 207cee313d2SEric ChristopherL1: 208cee313d2SEric Christopher call void @foo() 209cee313d2SEric Christopher ret void 210cee313d2SEric ChristopherL2: 211cee313d2SEric Christopher call void @bar() 212cee313d2SEric Christopher ret void 213cee313d2SEric ChristopherL3: 214cee313d2SEric Christopher call void @baz() 215cee313d2SEric Christopher ret void 216cee313d2SEric ChristopherL4: 217cee313d2SEric Christopher call void @quux() 218cee313d2SEric Christopher br label %L0 219cee313d2SEric Christopher} 220cee313d2SEric Christopher 221cee313d2SEric Christopher; Make sure the edge value of %0 from entry to L2 includes 0 and L3 is 222cee313d2SEric Christopher; reachable. 223cee313d2SEric Christopherdefine void @test_switch_default(i32* nocapture %status) nounwind { 224b3bd7328SNikita Popov; CHECK-LABEL: @test_switch_default( 225b3bd7328SNikita Popov; CHECK-NEXT: entry: 226b3bd7328SNikita Popov; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[STATUS:%.*]], align 4 227b3bd7328SNikita Popov; CHECK-NEXT: switch i32 [[TMP0]], label [[L2:%.*]] [ 228b3bd7328SNikita Popov; CHECK-NEXT: i32 5061, label [[L2_THREAD:%.*]] 229b3bd7328SNikita Popov; CHECK-NEXT: i32 0, label [[L2]] 230b3bd7328SNikita Popov; CHECK-NEXT: ] 231b3bd7328SNikita Popov; CHECK: L2.thread: 232b3bd7328SNikita Popov; CHECK-NEXT: store i32 10025, i32* [[STATUS]], align 4 233b3bd7328SNikita Popov; CHECK-NEXT: br label [[L4:%.*]] 234b3bd7328SNikita Popov; CHECK: L2: 235b3bd7328SNikita Popov; CHECK-NEXT: [[TMP1:%.*]] = phi i32 [ [[TMP0]], [[ENTRY:%.*]] ], [ [[TMP0]], [[ENTRY]] ] 236b3bd7328SNikita Popov; CHECK-NEXT: [[CMP57_I:%.*]] = icmp eq i32 [[TMP1]], 0 237b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP57_I]], label [[L3:%.*]], label [[L4]] 238b3bd7328SNikita Popov; CHECK: L3: 239b3bd7328SNikita Popov; CHECK-NEXT: store i32 10000, i32* [[STATUS]], align 4 240b3bd7328SNikita Popov; CHECK-NEXT: br label [[L4]] 241b3bd7328SNikita Popov; CHECK: L4: 242b3bd7328SNikita Popov; CHECK-NEXT: ret void 243b3bd7328SNikita Popov; 244cee313d2SEric Christopherentry: 245cee313d2SEric Christopher %0 = load i32, i32* %status, align 4 246cee313d2SEric Christopher switch i32 %0, label %L2 [ 247cee313d2SEric Christopher i32 5061, label %L1 248cee313d2SEric Christopher i32 0, label %L2 249cee313d2SEric Christopher ] 250cee313d2SEric Christopher 251cee313d2SEric ChristopherL1: 252cee313d2SEric Christopher store i32 10025, i32* %status, align 4 253cee313d2SEric Christopher br label %L2 254cee313d2SEric Christopher 255cee313d2SEric ChristopherL2: 256cee313d2SEric Christopher %1 = load i32, i32* %status, align 4 257cee313d2SEric Christopher %cmp57.i = icmp eq i32 %1, 0 258cee313d2SEric Christopher br i1 %cmp57.i, label %L3, label %L4 259cee313d2SEric Christopher 260cee313d2SEric ChristopherL3: 261cee313d2SEric Christopher store i32 10000, i32* %status, align 4 262cee313d2SEric Christopher br label %L4 263cee313d2SEric Christopher 264cee313d2SEric ChristopherL4: 265cee313d2SEric Christopher ret void 266cee313d2SEric Christopher} 267cee313d2SEric Christopher 268cee313d2SEric Christopherdefine void @unfold1(double %x, double %y) nounwind { 269b3bd7328SNikita Popov; CHECK-LABEL: @unfold1( 270b3bd7328SNikita Popov; CHECK-NEXT: entry: 271b3bd7328SNikita Popov; CHECK-NEXT: [[SUB:%.*]] = fsub double [[X:%.*]], [[Y:%.*]] 272b3bd7328SNikita Popov; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt double [[SUB]], 1.000000e+01 273b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP]], label [[COND_END4:%.*]], label [[COND_FALSE:%.*]] 274b3bd7328SNikita Popov; CHECK: cond.false: 275b3bd7328SNikita Popov; CHECK-NEXT: [[ADD:%.*]] = fadd double [[X]], [[Y]] 276b3bd7328SNikita Popov; CHECK-NEXT: [[CMP1:%.*]] = fcmp ogt double [[ADD]], 1.000000e+01 277b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP1]], label [[COND_END4]], label [[IF_THEN:%.*]] 278b3bd7328SNikita Popov; CHECK: cond.end4: 279b3bd7328SNikita Popov; CHECK-NEXT: [[COND5:%.*]] = phi double [ [[SUB]], [[ENTRY:%.*]] ], [ [[ADD]], [[COND_FALSE]] ] 280b3bd7328SNikita Popov; CHECK-NEXT: [[CMP6:%.*]] = fcmp oeq double [[COND5]], 0.000000e+00 281b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP6]], label [[IF_THEN]], label [[IF_END:%.*]] 282b3bd7328SNikita Popov; CHECK: if.then: 283b3bd7328SNikita Popov; CHECK-NEXT: call void @foo() 284b3bd7328SNikita Popov; CHECK-NEXT: br label [[IF_END]] 285b3bd7328SNikita Popov; CHECK: if.end: 286b3bd7328SNikita Popov; CHECK-NEXT: ret void 287b3bd7328SNikita Popov; 288cee313d2SEric Christopherentry: 289cee313d2SEric Christopher %sub = fsub double %x, %y 290cee313d2SEric Christopher %cmp = fcmp ogt double %sub, 1.000000e+01 291cee313d2SEric Christopher br i1 %cmp, label %cond.end4, label %cond.false 292cee313d2SEric Christopher 293cee313d2SEric Christophercond.false: ; preds = %entry 294cee313d2SEric Christopher %add = fadd double %x, %y 295cee313d2SEric Christopher %cmp1 = fcmp ogt double %add, 1.000000e+01 296cee313d2SEric Christopher %add. = select i1 %cmp1, double %add, double 0.000000e+00 297cee313d2SEric Christopher br label %cond.end4 298cee313d2SEric Christopher 299cee313d2SEric Christophercond.end4: ; preds = %entry, %cond.false 300cee313d2SEric Christopher %cond5 = phi double [ %add., %cond.false ], [ %sub, %entry ] 301cee313d2SEric Christopher %cmp6 = fcmp oeq double %cond5, 0.000000e+00 302cee313d2SEric Christopher br i1 %cmp6, label %if.then, label %if.end 303cee313d2SEric Christopher 304cee313d2SEric Christopherif.then: ; preds = %cond.end4 305cee313d2SEric Christopher call void @foo() 306cee313d2SEric Christopher br label %if.end 307cee313d2SEric Christopher 308cee313d2SEric Christopherif.end: ; preds = %if.then, %cond.end4 309cee313d2SEric Christopher ret void 310cee313d2SEric Christopher 311cee313d2SEric Christopher} 312cee313d2SEric Christopher 313cee313d2SEric Christopher 314cee313d2SEric Christopherdefine void @unfold2(i32 %x, i32 %y) nounwind { 315b3bd7328SNikita Popov; CHECK-LABEL: @unfold2( 316b3bd7328SNikita Popov; CHECK-NEXT: entry: 317b3bd7328SNikita Popov; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]] 318b3bd7328SNikita Popov; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[SUB]], 10 319b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP]], label [[IF_END:%.*]], label [[COND_FALSE:%.*]] 320b3bd7328SNikita Popov; CHECK: cond.false: 321b3bd7328SNikita Popov; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[X]], [[Y]] 322b3bd7328SNikita Popov; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i32 [[ADD]], 10 323b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[COND_END4:%.*]] 324b3bd7328SNikita Popov; CHECK: cond.end4: 325b3bd7328SNikita Popov; CHECK-NEXT: [[COND5:%.*]] = phi i32 [ [[ADD]], [[COND_FALSE]] ] 326b3bd7328SNikita Popov; CHECK-NEXT: [[CMP6:%.*]] = icmp eq i32 [[COND5]], 0 327b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP6]], label [[IF_THEN]], label [[IF_END]] 328b3bd7328SNikita Popov; CHECK: if.then: 329b3bd7328SNikita Popov; CHECK-NEXT: call void @foo() 330b3bd7328SNikita Popov; CHECK-NEXT: br label [[IF_END]] 331b3bd7328SNikita Popov; CHECK: if.end: 332b3bd7328SNikita Popov; CHECK-NEXT: ret void 333b3bd7328SNikita Popov; 334cee313d2SEric Christopherentry: 335cee313d2SEric Christopher %sub = sub nsw i32 %x, %y 336cee313d2SEric Christopher %cmp = icmp sgt i32 %sub, 10 337cee313d2SEric Christopher br i1 %cmp, label %cond.end4, label %cond.false 338cee313d2SEric Christopher 339cee313d2SEric Christophercond.false: ; preds = %entry 340cee313d2SEric Christopher %add = add nsw i32 %x, %y 341cee313d2SEric Christopher %cmp1 = icmp sgt i32 %add, 10 342cee313d2SEric Christopher %add. = select i1 %cmp1, i32 0, i32 %add 343cee313d2SEric Christopher br label %cond.end4 344cee313d2SEric Christopher 345cee313d2SEric Christophercond.end4: ; preds = %entry, %cond.false 346cee313d2SEric Christopher %cond5 = phi i32 [ %add., %cond.false ], [ %sub, %entry ] 347cee313d2SEric Christopher %cmp6 = icmp eq i32 %cond5, 0 348cee313d2SEric Christopher br i1 %cmp6, label %if.then, label %if.end 349cee313d2SEric Christopher 350cee313d2SEric Christopherif.then: ; preds = %cond.end4 351cee313d2SEric Christopher call void @foo() 352cee313d2SEric Christopher br label %if.end 353cee313d2SEric Christopher 354cee313d2SEric Christopherif.end: ; preds = %if.then, %cond.end4 355cee313d2SEric Christopher ret void 356cee313d2SEric Christopher 357cee313d2SEric Christopher} 358cee313d2SEric Christopher 359cee313d2SEric Christopher 360cee313d2SEric Christopherdefine i32 @unfold3(i32 %u, i32 %v, i32 %w, i32 %x, i32 %y, i32 %z, i32 %j) nounwind { 361b3bd7328SNikita Popov; CHECK-LABEL: @unfold3( 362b3bd7328SNikita Popov; CHECK-NEXT: entry: 363b3bd7328SNikita Popov; CHECK-NEXT: [[ADD3:%.*]] = add nsw i32 [[J:%.*]], 2 364b3bd7328SNikita Popov; CHECK-NEXT: [[CMP_I:%.*]] = icmp slt i32 [[U:%.*]], [[V:%.*]] 365*6f0ca6fdSNikita Popov; CHECK-NEXT: br i1 [[CMP_I]], label [[DOTEXIT_THREAD4:%.*]], label [[COND_FALSE_I:%.*]] 366b3bd7328SNikita Popov; CHECK: cond.false.i: 367b3bd7328SNikita Popov; CHECK-NEXT: [[CMP4_I:%.*]] = icmp sgt i32 [[U]], [[V]] 368b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP4_I]], label [[DOTEXIT_THREAD:%.*]], label [[COND_FALSE_6_I:%.*]] 369b3bd7328SNikita Popov; CHECK: cond.false.6.i: 370b3bd7328SNikita Popov; CHECK-NEXT: [[CMP8_I:%.*]] = icmp slt i32 [[W:%.*]], [[X:%.*]] 371*6f0ca6fdSNikita Popov; CHECK-NEXT: br i1 [[CMP8_I]], label [[DOTEXIT_THREAD4]], label [[COND_FALSE_10_I:%.*]] 372b3bd7328SNikita Popov; CHECK: cond.false.10.i: 373b3bd7328SNikita Popov; CHECK-NEXT: [[CMP13_I:%.*]] = icmp sgt i32 [[W]], [[X]] 374b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP13_I]], label [[DOTEXIT_THREAD]], label [[DOTEXIT:%.*]] 375b3bd7328SNikita Popov; CHECK: .exit: 376b3bd7328SNikita Popov; CHECK-NEXT: [[PHITMP:%.*]] = icmp sge i32 [[Y:%.*]], [[Z:%.*]] 377*6f0ca6fdSNikita Popov; CHECK-NEXT: [[COND_FR:%.*]] = freeze i1 [[PHITMP]] 378*6f0ca6fdSNikita Popov; CHECK-NEXT: br i1 [[COND_FR]], label [[DOTEXIT_THREAD]], label [[DOTEXIT_THREAD4]] 379b3bd7328SNikita Popov; CHECK: .exit.thread: 380*6f0ca6fdSNikita Popov; CHECK-NEXT: br label [[DOTEXIT_THREAD4]] 381*6f0ca6fdSNikita Popov; CHECK: .exit.thread4: 382b3bd7328SNikita Popov; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ [[J]], [[DOTEXIT_THREAD]] ], [ [[ADD3]], [[DOTEXIT]] ], [ [[ADD3]], [[ENTRY:%.*]] ], [ [[ADD3]], [[COND_FALSE_6_I]] ] 383b3bd7328SNikita Popov; CHECK-NEXT: ret i32 [[TMP0]] 384b3bd7328SNikita Popov; 385cee313d2SEric Christopherentry: 386cee313d2SEric Christopher %add3 = add nsw i32 %j, 2 387cee313d2SEric Christopher %cmp.i = icmp slt i32 %u, %v 388cee313d2SEric Christopher br i1 %cmp.i, label %.exit, label %cond.false.i 389cee313d2SEric Christopher 390cee313d2SEric Christophercond.false.i: ; preds = %entry 391cee313d2SEric Christopher %cmp4.i = icmp sgt i32 %u, %v 392cee313d2SEric Christopher br i1 %cmp4.i, label %.exit, label %cond.false.6.i 393cee313d2SEric Christopher 394cee313d2SEric Christophercond.false.6.i: ; preds = %cond.false.i 395cee313d2SEric Christopher %cmp8.i = icmp slt i32 %w, %x 396cee313d2SEric Christopher br i1 %cmp8.i, label %.exit, label %cond.false.10.i 397cee313d2SEric Christopher 398cee313d2SEric Christophercond.false.10.i: ; preds = %cond.false.6.i 399cee313d2SEric Christopher %cmp13.i = icmp sgt i32 %w, %x 400cee313d2SEric Christopher br i1 %cmp13.i, label %.exit, label %cond.false.15.i 401cee313d2SEric Christopher 402cee313d2SEric Christophercond.false.15.i: ; preds = %cond.false.10.i 403cee313d2SEric Christopher %phitmp = icmp sge i32 %y, %z 404cee313d2SEric Christopher br label %.exit 405cee313d2SEric Christopher 406cee313d2SEric Christopher.exit: ; preds = %entry, %cond.false.i, %cond.false.6.i, %cond.false.10.i, %cond.false.15.i 407cee313d2SEric Christopher %cond23.i = phi i1 [ false, %entry ], [ true, %cond.false.i ], [ false, %cond.false.6.i ], [ %phitmp, %cond.false.15.i ], [ true, %cond.false.10.i ] 408cee313d2SEric Christopher %j.add3 = select i1 %cond23.i, i32 %j, i32 %add3 409cee313d2SEric Christopher ret i32 %j.add3 410cee313d2SEric Christopher 411cee313d2SEric Christopher} 412cee313d2SEric Christopher 413cee313d2SEric Christopherdefine i32 @unfold4(i32 %u, i32 %v, i32 %w, i32 %x, i32 %y, i32 %z, i32 %j) nounwind { 414b3bd7328SNikita Popov; CHECK-LABEL: @unfold4( 415b3bd7328SNikita Popov; CHECK-NEXT: entry: 416b3bd7328SNikita Popov; CHECK-NEXT: [[ADD3:%.*]] = add nsw i32 [[J:%.*]], 2 417b3bd7328SNikita Popov; CHECK-NEXT: [[CMP_I:%.*]] = icmp slt i32 [[U:%.*]], [[V:%.*]] 418b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP_I]], label [[DOTEXIT_THREAD:%.*]], label [[COND_FALSE_I:%.*]] 419b3bd7328SNikita Popov; CHECK: cond.false.i: 420b3bd7328SNikita Popov; CHECK-NEXT: [[CMP4_I:%.*]] = icmp sgt i32 [[U]], [[V]] 421*6f0ca6fdSNikita Popov; CHECK-NEXT: br i1 [[CMP4_I]], label [[DOTEXIT_THREAD5:%.*]], label [[COND_FALSE_6_I:%.*]] 422b3bd7328SNikita Popov; CHECK: cond.false.6.i: 423b3bd7328SNikita Popov; CHECK-NEXT: [[CMP8_I:%.*]] = icmp slt i32 [[W:%.*]], [[X:%.*]] 424b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP8_I]], label [[DOTEXIT_THREAD]], label [[COND_FALSE_10_I:%.*]] 425b3bd7328SNikita Popov; CHECK: cond.false.10.i: 426b3bd7328SNikita Popov; CHECK-NEXT: [[CMP13_I:%.*]] = icmp sgt i32 [[W]], [[X]] 427*6f0ca6fdSNikita Popov; CHECK-NEXT: br i1 [[CMP13_I]], label [[DOTEXIT_THREAD5]], label [[DOTEXIT:%.*]] 428b3bd7328SNikita Popov; CHECK: .exit: 429b3bd7328SNikita Popov; CHECK-NEXT: [[CMP19_I:%.*]] = icmp sge i32 [[Y:%.*]], [[Z:%.*]] 430b3bd7328SNikita Popov; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP19_I]] to i32 431b3bd7328SNikita Popov; CHECK-NEXT: [[LNOT_I18:%.*]] = icmp eq i32 [[CONV]], 1 432*6f0ca6fdSNikita Popov; CHECK-NEXT: [[COND_FR:%.*]] = freeze i1 [[LNOT_I18]] 433*6f0ca6fdSNikita Popov; CHECK-NEXT: br i1 [[COND_FR]], label [[DOTEXIT_THREAD]], label [[DOTEXIT_THREAD5]] 434b3bd7328SNikita Popov; CHECK: .exit.thread: 435*6f0ca6fdSNikita Popov; CHECK-NEXT: br label [[DOTEXIT_THREAD5]] 436*6f0ca6fdSNikita Popov; CHECK: .exit.thread5: 437b3bd7328SNikita Popov; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ [[J]], [[DOTEXIT_THREAD]] ], [ [[ADD3]], [[DOTEXIT]] ], [ [[ADD3]], [[COND_FALSE_I]] ], [ [[ADD3]], [[COND_FALSE_10_I]] ] 438b3bd7328SNikita Popov; CHECK-NEXT: ret i32 [[TMP0]] 439b3bd7328SNikita Popov; 440cee313d2SEric Christopherentry: 441cee313d2SEric Christopher %add3 = add nsw i32 %j, 2 442cee313d2SEric Christopher %cmp.i = icmp slt i32 %u, %v 443cee313d2SEric Christopher br i1 %cmp.i, label %.exit, label %cond.false.i 444cee313d2SEric Christopher 445cee313d2SEric Christophercond.false.i: ; preds = %entry 446cee313d2SEric Christopher %cmp4.i = icmp sgt i32 %u, %v 447cee313d2SEric Christopher br i1 %cmp4.i, label %.exit, label %cond.false.6.i 448cee313d2SEric Christopher 449cee313d2SEric Christophercond.false.6.i: ; preds = %cond.false.i 450cee313d2SEric Christopher %cmp8.i = icmp slt i32 %w, %x 451cee313d2SEric Christopher br i1 %cmp8.i, label %.exit, label %cond.false.10.i 452cee313d2SEric Christopher 453cee313d2SEric Christophercond.false.10.i: ; preds = %cond.false.6.i 454cee313d2SEric Christopher %cmp13.i = icmp sgt i32 %w, %x 455cee313d2SEric Christopher br i1 %cmp13.i, label %.exit, label %cond.false.15.i 456cee313d2SEric Christopher 457cee313d2SEric Christophercond.false.15.i: ; preds = %cond.false.10.i 458cee313d2SEric Christopher %cmp19.i = icmp sge i32 %y, %z 459cee313d2SEric Christopher %conv = zext i1 %cmp19.i to i32 460cee313d2SEric Christopher br label %.exit 461cee313d2SEric Christopher 462cee313d2SEric Christopher.exit: ; preds = %entry, %cond.false.i, %cond.false.6.i, %cond.false.10.i, %cond.false.15.i 463cee313d2SEric Christopher %cond23.i = phi i32 [ 1, %entry ], [ 0, %cond.false.i ], [ 1, %cond.false.6.i ], [ %conv, %cond.false.15.i ], [ 0, %cond.false.10.i ] 464cee313d2SEric Christopher %lnot.i18 = icmp eq i32 %cond23.i, 1 465cee313d2SEric Christopher %j.add3 = select i1 %lnot.i18, i32 %j, i32 %add3 466cee313d2SEric Christopher ret i32 %j.add3 467cee313d2SEric Christopher 468cee313d2SEric Christopher} 469cee313d2SEric Christopher 470cee313d2SEric Christopherdefine i32 @unfold5(i32 %u, i32 %v, i32 %w, i32 %x, i32 %y, i32 %z, i32 %j) nounwind { 471b3bd7328SNikita Popov; CHECK-LABEL: @unfold5( 472b3bd7328SNikita Popov; CHECK-NEXT: entry: 473b3bd7328SNikita Popov; CHECK-NEXT: [[ADD3:%.*]] = add nsw i32 [[J:%.*]], 2 474b3bd7328SNikita Popov; CHECK-NEXT: [[CMP_I:%.*]] = icmp slt i32 [[U:%.*]], [[V:%.*]] 475b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP_I]], label [[DOTEXIT:%.*]], label [[COND_FALSE_I:%.*]] 476b3bd7328SNikita Popov; CHECK: cond.false.i: 477b3bd7328SNikita Popov; CHECK-NEXT: [[CMP4_I:%.*]] = icmp sgt i32 [[U]], [[V]] 478b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP4_I]], label [[DOTEXIT]], label [[COND_FALSE_6_I:%.*]] 479b3bd7328SNikita Popov; CHECK: cond.false.6.i: 480b3bd7328SNikita Popov; CHECK-NEXT: [[CMP8_I:%.*]] = icmp slt i32 [[W:%.*]], [[X:%.*]] 481b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP8_I]], label [[DOTEXIT]], label [[COND_FALSE_10_I:%.*]] 482b3bd7328SNikita Popov; CHECK: cond.false.10.i: 483b3bd7328SNikita Popov; CHECK-NEXT: [[CMP13_I:%.*]] = icmp sgt i32 [[W]], [[X]] 484b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP13_I]], label [[DOTEXIT]], label [[COND_FALSE_15_I:%.*]] 485b3bd7328SNikita Popov; CHECK: cond.false.15.i: 486b3bd7328SNikita Popov; CHECK-NEXT: [[CMP19_I:%.*]] = icmp sge i32 [[Y:%.*]], [[Z:%.*]] 487b3bd7328SNikita Popov; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP19_I]] to i32 488b3bd7328SNikita Popov; CHECK-NEXT: br label [[DOTEXIT]] 489b3bd7328SNikita Popov; CHECK: .exit: 490b3bd7328SNikita Popov; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ [[J]], [[COND_FALSE_10_I]] ], [ [[CONV]], [[COND_FALSE_15_I]] ], [ 1, [[COND_FALSE_6_I]] ], [ 3, [[COND_FALSE_I]] ], [ 2, [[ENTRY:%.*]] ] 491b3bd7328SNikita Popov; CHECK-NEXT: ret i32 [[TMP0]] 492b3bd7328SNikita Popov; 493cee313d2SEric Christopherentry: 494cee313d2SEric Christopher %add3 = add nsw i32 %j, 2 495cee313d2SEric Christopher %cmp.i = icmp slt i32 %u, %v 496cee313d2SEric Christopher br i1 %cmp.i, label %.exit, label %cond.false.i 497cee313d2SEric Christopher 498cee313d2SEric Christophercond.false.i: ; preds = %entry 499cee313d2SEric Christopher %cmp4.i = icmp sgt i32 %u, %v 500cee313d2SEric Christopher br i1 %cmp4.i, label %.exit, label %cond.false.6.i 501cee313d2SEric Christopher 502cee313d2SEric Christophercond.false.6.i: ; preds = %cond.false.i 503cee313d2SEric Christopher %cmp8.i = icmp slt i32 %w, %x 504cee313d2SEric Christopher br i1 %cmp8.i, label %.exit, label %cond.false.10.i 505cee313d2SEric Christopher 506cee313d2SEric Christophercond.false.10.i: ; preds = %cond.false.6.i 507cee313d2SEric Christopher %cmp13.i = icmp sgt i32 %w, %x 508cee313d2SEric Christopher br i1 %cmp13.i, label %.exit, label %cond.false.15.i 509cee313d2SEric Christopher 510cee313d2SEric Christophercond.false.15.i: ; preds = %cond.false.10.i 511cee313d2SEric Christopher %cmp19.i = icmp sge i32 %y, %z 512cee313d2SEric Christopher %conv = zext i1 %cmp19.i to i32 513cee313d2SEric Christopher br label %.exit 514cee313d2SEric Christopher 515cee313d2SEric Christopher.exit: ; preds = %entry, %cond.false.i, %cond.false.6.i, %cond.false.10.i, %cond.false.15.i 516cee313d2SEric Christopher %cond23.i = phi i32 [ 2, %entry ], [ 3, %cond.false.i ], [ 1, %cond.false.6.i ], [ %conv, %cond.false.15.i ], [ 7, %cond.false.10.i ] 517cee313d2SEric Christopher %lnot.i18 = icmp sgt i32 %cond23.i, 5 518cee313d2SEric Christopher %j.add3 = select i1 %lnot.i18, i32 %j, i32 %cond23.i 519cee313d2SEric Christopher ret i32 %j.add3 520cee313d2SEric Christopher 521cee313d2SEric Christopher} 522cee313d2SEric Christopher 523cee313d2SEric Christopher; When a select has a constant operand in one branch, and it feeds a phi node 524cee313d2SEric Christopher; and the phi node feeds a switch we unfold the select 525cee313d2SEric Christopherdefine void @test_func(i32* nocapture readonly %a, i32* nocapture readonly %b, i32* nocapture readonly %c, i32 %n) local_unnamed_addr #0 { 526b3bd7328SNikita Popov; CHECK-LABEL: @test_func( 527b3bd7328SNikita Popov; CHECK-NEXT: entry: 528b3bd7328SNikita Popov; CHECK-NEXT: br label [[FOR_COND:%.*]] 529b3bd7328SNikita Popov; CHECK: for.cond: 530b3bd7328SNikita Popov; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[SW_DEFAULT:%.*]] ] 531b3bd7328SNikita Popov; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_0]], [[N:%.*]] 532b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]] 533b3bd7328SNikita Popov; CHECK: for.cond.cleanup: 534b3bd7328SNikita Popov; CHECK-NEXT: ret void 535b3bd7328SNikita Popov; CHECK: for.body: 536b3bd7328SNikita Popov; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[I_0]] to i64 537b3bd7328SNikita Popov; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP0]] 538b3bd7328SNikita Popov; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[ARRAYIDX]], align 4 539b3bd7328SNikita Popov; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[TMP1]], 4 540b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP1]], label [[LAND_LHS_TRUE:%.*]], label [[IF_END:%.*]] 541b3bd7328SNikita Popov; CHECK: land.lhs.true: 542b3bd7328SNikita Popov; CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds i32, i32* [[B:%.*]], i64 [[TMP0]] 543b3bd7328SNikita Popov; CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* [[ARRAYIDX3]], align 4 544b3bd7328SNikita Popov; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds i32, i32* [[C:%.*]], i64 [[TMP0]] 545b3bd7328SNikita Popov; CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* [[ARRAYIDX5]], align 4 546b3bd7328SNikita Popov; CHECK-NEXT: [[CMP6:%.*]] = icmp eq i32 [[TMP2]], [[TMP3]] 547b3bd7328SNikita Popov; CHECK-NEXT: br i1 [[CMP6]], label [[SW_BB:%.*]], label [[SW_BB7:%.*]] 548b3bd7328SNikita Popov; CHECK: if.end: 549b3bd7328SNikita Popov; CHECK-NEXT: [[LOCAL_VAR_0:%.*]] = phi i32 [ [[TMP1]], [[FOR_BODY]] ] 550b3bd7328SNikita Popov; CHECK-NEXT: switch i32 [[LOCAL_VAR_0]], label [[SW_DEFAULT]] [ 551b3bd7328SNikita Popov; CHECK-NEXT: i32 2, label [[SW_BB]] 552b3bd7328SNikita Popov; CHECK-NEXT: i32 4, label [[SW_BB7]] 553b3bd7328SNikita Popov; CHECK-NEXT: i32 5, label [[SW_BB8:%.*]] 554b3bd7328SNikita Popov; CHECK-NEXT: i32 7, label [[SW_BB9:%.*]] 555b3bd7328SNikita Popov; CHECK-NEXT: ] 556b3bd7328SNikita Popov; CHECK: sw.bb: 557b3bd7328SNikita Popov; CHECK-NEXT: call void @foo() 558b3bd7328SNikita Popov; CHECK-NEXT: br label [[SW_BB7]] 559b3bd7328SNikita Popov; CHECK: sw.bb7: 560b3bd7328SNikita Popov; CHECK-NEXT: call void @bar() 561b3bd7328SNikita Popov; CHECK-NEXT: br label [[SW_BB8]] 562b3bd7328SNikita Popov; CHECK: sw.bb8: 563b3bd7328SNikita Popov; CHECK-NEXT: call void @baz() 564b3bd7328SNikita Popov; CHECK-NEXT: br label [[SW_BB9]] 565b3bd7328SNikita Popov; CHECK: sw.bb9: 566b3bd7328SNikita Popov; CHECK-NEXT: call void @quux() 567b3bd7328SNikita Popov; CHECK-NEXT: br label [[SW_DEFAULT]] 568b3bd7328SNikita Popov; CHECK: sw.default: 569b3bd7328SNikita Popov; CHECK-NEXT: call void @baz() 570b3bd7328SNikita Popov; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_0]], 1 571b3bd7328SNikita Popov; CHECK-NEXT: br label [[FOR_COND]] 572b3bd7328SNikita Popov; 573cee313d2SEric Christopherentry: 574cee313d2SEric Christopher br label %for.cond 575cee313d2SEric Christopher 576cee313d2SEric Christopherfor.cond: ; preds = %sw.default, %entry 577cee313d2SEric Christopher %i.0 = phi i32 [ 0, %entry ], [ %inc, %sw.default ] 578cee313d2SEric Christopher %cmp = icmp slt i32 %i.0, %n 579cee313d2SEric Christopher br i1 %cmp, label %for.body, label %for.cond.cleanup 580cee313d2SEric Christopher 581cee313d2SEric Christopherfor.cond.cleanup: ; preds = %for.cond 582cee313d2SEric Christopher ret void 583cee313d2SEric Christopher 584cee313d2SEric Christopherfor.body: ; preds = %for.cond 585cee313d2SEric Christopher %0 = zext i32 %i.0 to i64 586cee313d2SEric Christopher %arrayidx = getelementptr inbounds i32, i32* %a, i64 %0 587cee313d2SEric Christopher %1 = load i32, i32* %arrayidx, align 4 588cee313d2SEric Christopher %cmp1 = icmp eq i32 %1, 4 589cee313d2SEric Christopher br i1 %cmp1, label %land.lhs.true, label %if.end 590cee313d2SEric Christopher 591cee313d2SEric Christopherland.lhs.true: ; preds = %for.body 592cee313d2SEric Christopher %arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %0 593cee313d2SEric Christopher %2 = load i32, i32* %arrayidx3, align 4 594cee313d2SEric Christopher %arrayidx5 = getelementptr inbounds i32, i32* %c, i64 %0 595cee313d2SEric Christopher %3 = load i32, i32* %arrayidx5, align 4 596cee313d2SEric Christopher %cmp6 = icmp eq i32 %2, %3 597cee313d2SEric Christopher %spec.select = select i1 %cmp6, i32 2, i32 4 598cee313d2SEric Christopher br label %if.end 599cee313d2SEric Christopher 600cee313d2SEric Christopherif.end: ; preds = %land.lhs.true, %for.body 601cee313d2SEric Christopher %local_var.0 = phi i32 [ %1, %for.body ], [ %spec.select, %land.lhs.true ] 602cee313d2SEric Christopher switch i32 %local_var.0, label %sw.default [ 603cee313d2SEric Christopher i32 2, label %sw.bb 604cee313d2SEric Christopher i32 4, label %sw.bb7 605cee313d2SEric Christopher i32 5, label %sw.bb8 606cee313d2SEric Christopher i32 7, label %sw.bb9 607cee313d2SEric Christopher ] 608cee313d2SEric Christopher 609cee313d2SEric Christophersw.bb: ; preds = %if.end 610cee313d2SEric Christopher call void @foo() 611cee313d2SEric Christopher br label %sw.bb7 612cee313d2SEric Christopher 613cee313d2SEric Christophersw.bb7: ; preds = %if.end, %sw.bb 614cee313d2SEric Christopher call void @bar() 615cee313d2SEric Christopher br label %sw.bb8 616cee313d2SEric Christopher 617cee313d2SEric Christophersw.bb8: ; preds = %if.end, %sw.bb7 618cee313d2SEric Christopher call void @baz() 619cee313d2SEric Christopher br label %sw.bb9 620cee313d2SEric Christopher 621cee313d2SEric Christophersw.bb9: ; preds = %if.end, %sw.bb8 622cee313d2SEric Christopher call void @quux() 623cee313d2SEric Christopher br label %sw.default 624cee313d2SEric Christopher 625cee313d2SEric Christophersw.default: ; preds = %if.end, %sw.bb9 626cee313d2SEric Christopher call void @baz() 627cee313d2SEric Christopher %inc = add nuw nsw i32 %i.0, 1 628cee313d2SEric Christopher br label %for.cond 629cee313d2SEric Christopher} 63022c66c1aSSanjay Patel 63122c66c1aSSanjay Pateldefine i32 @TryToUnfoldSelectInCurrBB(i1 %b, i1 %ui, i32 %s, i1 %x) { 63222c66c1aSSanjay Patel; CHECK-LABEL: @TryToUnfoldSelectInCurrBB( 63322c66c1aSSanjay Patel; CHECK-NEXT: entry: 63422c66c1aSSanjay Patel; CHECK-NEXT: br i1 [[B:%.*]], label [[IF_END_THREAD:%.*]], label [[IF_END:%.*]] 63522c66c1aSSanjay Patel; CHECK: if.end: 636*6f0ca6fdSNikita Popov; CHECK-NEXT: [[COND_FR:%.*]] = freeze i1 [[X:%.*]] 637*6f0ca6fdSNikita Popov; CHECK-NEXT: br i1 [[COND_FR]], label [[TMP0:%.*]], label [[IF_END_THREAD]] 63822c66c1aSSanjay Patel; CHECK: 0: 63922c66c1aSSanjay Patel; CHECK-NEXT: br label [[IF_END_THREAD]] 64022c66c1aSSanjay Patel; CHECK: if.end.thread: 64122c66c1aSSanjay Patel; CHECK-NEXT: [[TMP1:%.*]] = phi i32 [ [[S:%.*]], [[TMP0]] ], [ 42, [[IF_END]] ], [ 42, [[ENTRY:%.*]] ] 64222c66c1aSSanjay Patel; CHECK-NEXT: ret i32 [[TMP1]] 64322c66c1aSSanjay Patel; 64422c66c1aSSanjay Patelentry: 64522c66c1aSSanjay Patel br i1 %b, label %if.end, label %if.else 64622c66c1aSSanjay Patel 64722c66c1aSSanjay Patelif.else: 64822c66c1aSSanjay Patel br label %if.end 64922c66c1aSSanjay Patel 65022c66c1aSSanjay Patelif.end: 65122c66c1aSSanjay Patel %v = phi i1 [ %x, %if.else ], [ false, %entry ] 65222c66c1aSSanjay Patel %v1 = select i1 %v, i32 %s, i32 42 65322c66c1aSSanjay Patel ret i32 %v1 65422c66c1aSSanjay Patel} 655