1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2 ; RUN: opt < %s -simplifycfg -phi-node-folding-threshold=2 -S | FileCheck %s 3 4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" 5 target triple = "x86_64-unknown-linux-gnu" 6 7 define i32 @test1(i32 %a, i32 %b, i32 %c) nounwind { 8 ; CHECK-LABEL: @test1( 9 ; CHECK-NEXT: entry: 10 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[B:%.*]], 0 11 ; CHECK-NEXT: br i1 [[TMP1]], label [[BB1:%.*]], label [[BB3:%.*]] 12 ; CHECK: bb1: 13 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[C:%.*]], 1 14 ; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[A:%.*]], 1 15 ; CHECK-NEXT: [[TMP3_A:%.*]] = select i1 [[TMP2]], i32 [[TMP3]], i32 [[A]] 16 ; CHECK-NEXT: br label [[BB3]] 17 ; CHECK: bb3: 18 ; CHECK-NEXT: [[TMP4:%.*]] = phi i32 [ [[B]], [[ENTRY:%.*]] ], [ [[TMP3_A]], [[BB1]] ] 19 ; CHECK-NEXT: [[TMP5:%.*]] = sub i32 [[TMP4]], 1 20 ; CHECK-NEXT: ret i32 [[TMP5]] 21 ; 22 entry: 23 %tmp1 = icmp eq i32 %b, 0 24 br i1 %tmp1, label %bb1, label %bb3 25 26 bb1: ; preds = %entry 27 %tmp2 = icmp sgt i32 %c, 1 28 br i1 %tmp2, label %bb2, label %bb3 29 30 bb2: ; preds = bb1 31 %tmp3 = add i32 %a, 1 32 br label %bb3 33 34 bb3: ; preds = %bb2, %entry 35 %tmp4 = phi i32 [ %b, %entry ], [ %a, %bb1 ], [ %tmp3, %bb2 ] 36 %tmp5 = sub i32 %tmp4, 1 37 ret i32 %tmp5 38 } 39 40 define i8* @test4(i1* %dummy, i8* %a, i8* %b) { 41 ; Test that we don't speculate an arbitrarily large number of unfolded constant 42 ; expressions. 43 ; CHECK-LABEL: @test4( 44 ; CHECK-NEXT: entry: 45 ; CHECK-NEXT: [[COND1:%.*]] = load volatile i1, i1* [[DUMMY:%.*]] 46 ; CHECK-NEXT: br i1 [[COND1]], label [[IF:%.*]], label [[END:%.*]] 47 ; CHECK: if: 48 ; CHECK-NEXT: [[COND2:%.*]] = load volatile i1, i1* [[DUMMY]] 49 ; CHECK-NEXT: br i1 [[COND2]], label [[THEN:%.*]], label [[END]] 50 ; CHECK: then: 51 ; CHECK-NEXT: br label [[END]] 52 ; CHECK: end: 53 ; CHECK-NEXT: [[X1:%.*]] = phi i8* [ [[A:%.*]], [[ENTRY:%.*]] ], [ [[B:%.*]], [[IF]] ], [ inttoptr (i64 1 to i8*), [[THEN]] ] 54 ; CHECK-NEXT: [[X2:%.*]] = phi i8* [ [[A]], [[ENTRY]] ], [ [[B]], [[IF]] ], [ inttoptr (i64 2 to i8*), [[THEN]] ] 55 ; CHECK-NEXT: [[X3:%.*]] = phi i8* [ [[A]], [[ENTRY]] ], [ [[B]], [[IF]] ], [ inttoptr (i64 3 to i8*), [[THEN]] ] 56 ; CHECK-NEXT: [[X4:%.*]] = phi i8* [ [[A]], [[ENTRY]] ], [ [[B]], [[IF]] ], [ inttoptr (i64 4 to i8*), [[THEN]] ] 57 ; CHECK-NEXT: [[X5:%.*]] = phi i8* [ [[A]], [[ENTRY]] ], [ [[B]], [[IF]] ], [ inttoptr (i64 5 to i8*), [[THEN]] ] 58 ; CHECK-NEXT: [[X6:%.*]] = phi i8* [ [[A]], [[ENTRY]] ], [ [[B]], [[IF]] ], [ inttoptr (i64 6 to i8*), [[THEN]] ] 59 ; CHECK-NEXT: [[X7:%.*]] = phi i8* [ [[A]], [[ENTRY]] ], [ [[B]], [[IF]] ], [ inttoptr (i64 7 to i8*), [[THEN]] ] 60 ; CHECK-NEXT: [[X8:%.*]] = phi i8* [ [[A]], [[ENTRY]] ], [ [[B]], [[IF]] ], [ inttoptr (i64 8 to i8*), [[THEN]] ] 61 ; CHECK-NEXT: [[X9:%.*]] = phi i8* [ [[A]], [[ENTRY]] ], [ [[B]], [[IF]] ], [ inttoptr (i64 9 to i8*), [[THEN]] ] 62 ; CHECK-NEXT: [[X10:%.*]] = phi i8* [ [[A]], [[ENTRY]] ], [ [[B]], [[IF]] ], [ inttoptr (i64 10 to i8*), [[THEN]] ] 63 ; CHECK-NEXT: ret i8* [[X10]] 64 ; 65 66 entry: 67 %cond1 = load volatile i1, i1* %dummy 68 br i1 %cond1, label %if, label %end 69 70 if: 71 %cond2 = load volatile i1, i1* %dummy 72 br i1 %cond2, label %then, label %end 73 74 then: 75 br label %end 76 77 end: 78 %x1 = phi i8* [ %a, %entry ], [ %b, %if ], [ inttoptr (i64 1 to i8*), %then ] 79 %x2 = phi i8* [ %a, %entry ], [ %b, %if ], [ inttoptr (i64 2 to i8*), %then ] 80 %x3 = phi i8* [ %a, %entry ], [ %b, %if ], [ inttoptr (i64 3 to i8*), %then ] 81 %x4 = phi i8* [ %a, %entry ], [ %b, %if ], [ inttoptr (i64 4 to i8*), %then ] 82 %x5 = phi i8* [ %a, %entry ], [ %b, %if ], [ inttoptr (i64 5 to i8*), %then ] 83 %x6 = phi i8* [ %a, %entry ], [ %b, %if ], [ inttoptr (i64 6 to i8*), %then ] 84 %x7 = phi i8* [ %a, %entry ], [ %b, %if ], [ inttoptr (i64 7 to i8*), %then ] 85 %x8 = phi i8* [ %a, %entry ], [ %b, %if ], [ inttoptr (i64 8 to i8*), %then ] 86 %x9 = phi i8* [ %a, %entry ], [ %b, %if ], [ inttoptr (i64 9 to i8*), %then ] 87 %x10 = phi i8* [ %a, %entry ], [ %b, %if ], [ inttoptr (i64 10 to i8*), %then ] 88 89 ret i8* %x10 90 } 91 92 define i32* @test5(i32 %a, i32 %b, i32 %c, i32* dereferenceable(10) %ptr1, 93 ; CHECK-LABEL: @test5( 94 ; CHECK-NEXT: entry: 95 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[B:%.*]], 0 96 ; CHECK-NEXT: br i1 [[TMP1]], label [[BB1:%.*]], label [[BB3:%.*]] 97 ; CHECK: bb1: 98 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[C:%.*]], 1 99 ; CHECK-NEXT: [[TMP3:%.*]] = load i32*, i32** [[PTR3:%.*]] 100 ; CHECK-NEXT: [[TMP3_PTR2:%.*]] = select i1 [[TMP2]], i32* [[TMP3]], i32* [[PTR2:%.*]] 101 ; CHECK-NEXT: ret i32* [[TMP3_PTR2]] 102 ; CHECK: bb3: 103 ; CHECK-NEXT: ret i32* [[PTR1:%.*]] 104 ; 105 i32* dereferenceable(10) %ptr2, i32** dereferenceable(10) %ptr3) nounwind { 106 entry: 107 %tmp1 = icmp eq i32 %b, 0 108 br i1 %tmp1, label %bb1, label %bb3 109 110 bb1: ; preds = %entry 111 %tmp2 = icmp sgt i32 %c, 1 112 br i1 %tmp2, label %bb2, label %bb3 113 114 bb2: ; preds = bb1 115 %tmp3 = load i32*, i32** %ptr3, !dereferenceable !{i64 10} 116 br label %bb3 117 118 bb3: ; preds = %bb2, %entry 119 %tmp4 = phi i32* [ %ptr1, %entry ], [ %ptr2, %bb1 ], [ %tmp3, %bb2 ] 120 ret i32* %tmp4 121 } 122