1; RUN: opt < %s -basicaa -gvn -S | FileCheck %s 2 3@a = external global i32 ; <i32*> [#uses=7] 4 5; CHECK: @test1 6define i32 @test1() nounwind { 7entry: 8 %0 = load i32* @a, align 4 9 %1 = icmp eq i32 %0, 4 10 br i1 %1, label %bb, label %bb1 11 12bb: ; preds = %entry 13 br label %bb8 14 15bb1: ; preds = %entry 16 %2 = load i32* @a, align 4 17 %3 = icmp eq i32 %2, 5 18 br i1 %3, label %bb2, label %bb3 19 20bb2: ; preds = %bb1 21 br label %bb8 22 23bb3: ; preds = %bb1 24 %4 = load i32* @a, align 4 25 %5 = icmp eq i32 %4, 4 26; CHECK: br i1 false, label %bb4, label %bb5 27 br i1 %5, label %bb4, label %bb5 28 29bb4: ; preds = %bb3 30 %6 = load i32* @a, align 4 31 %7 = add i32 %6, 5 32 br label %bb8 33 34bb5: ; preds = %bb3 35 %8 = load i32* @a, align 4 36 %9 = icmp eq i32 %8, 5 37; CHECK: br i1 false, label %bb6, label %bb7 38 br i1 %9, label %bb6, label %bb7 39 40bb6: ; preds = %bb5 41 %10 = load i32* @a, align 4 42 %11 = add i32 %10, 4 43 br label %bb8 44 45bb7: ; preds = %bb5 46 %12 = load i32* @a, align 4 47 br label %bb8 48 49bb8: ; preds = %bb7, %bb6, %bb4, %bb2, %bb 50 %.0 = phi i32 [ %12, %bb7 ], [ %11, %bb6 ], [ %7, %bb4 ], [ 4, %bb2 ], [ 5, %bb ] 51 br label %return 52 53return: ; preds = %bb8 54 ret i32 %.0 55} 56 57declare void @foo(i1) 58declare void @bar(i32) 59 60; CHECK: @test3 61define void @test3(i32 %x, i32 %y) { 62 %xz = icmp eq i32 %x, 0 63 %yz = icmp eq i32 %y, 0 64 %z = and i1 %xz, %yz 65 br i1 %z, label %both_zero, label %nope 66both_zero: 67 call void @foo(i1 %xz) 68; CHECK: call void @foo(i1 true) 69 call void @foo(i1 %yz) 70; CHECK: call void @foo(i1 true) 71 call void @bar(i32 %x) 72; CHECK: call void @bar(i32 0) 73 call void @bar(i32 %y) 74; CHECK: call void @bar(i32 0) 75 ret void 76nope: 77 call void @foo(i1 %z) 78; CHECK: call void @foo(i1 false) 79 ret void 80} 81 82; CHECK: @test4 83define void @test4(i1 %b, i32 %x) { 84 br i1 %b, label %sw, label %case3 85sw: 86 switch i32 %x, label %default [ 87 i32 0, label %case0 88 i32 1, label %case1 89 i32 2, label %case0 90 i32 3, label %case3 91 i32 4, label %default 92 ] 93default: 94; CHECK: default: 95 call void @bar(i32 %x) 96; CHECK: call void @bar(i32 %x) 97 ret void 98case0: 99; CHECK: case0: 100 call void @bar(i32 %x) 101; CHECK: call void @bar(i32 %x) 102 ret void 103case1: 104; CHECK: case1: 105 call void @bar(i32 %x) 106; CHECK: call void @bar(i32 1) 107 ret void 108case3: 109; CHECK: case3: 110 call void @bar(i32 %x) 111; CHECK: call void @bar(i32 %x) 112 ret void 113} 114 115; CHECK: @test5 116define i1 @test5(i32 %x, i32 %y) { 117 %cmp = icmp eq i32 %x, %y 118 br i1 %cmp, label %same, label %different 119 120same: 121 %cmp2 = icmp ne i32 %x, %y 122; CHECK: ret i1 false 123 ret i1 %cmp2 124 125different: 126 %cmp3 = icmp eq i32 %x, %y 127; CHECK: ret i1 false 128 ret i1 %cmp3 129} 130 131; CHECK: @test6 132define i1 @test6(i32 %x, i32 %y) { 133 %cmp2 = icmp ne i32 %x, %y 134 %cmp = icmp eq i32 %x, %y 135 %cmp3 = icmp eq i32 %x, %y 136 br i1 %cmp, label %same, label %different 137 138same: 139; CHECK: ret i1 false 140 ret i1 %cmp2 141 142different: 143; CHECK: ret i1 false 144 ret i1 %cmp3 145} 146 147; CHECK: @test7 148define i1 @test7(i32 %x, i32 %y) { 149 %cmp = icmp sgt i32 %x, %y 150 br i1 %cmp, label %same, label %different 151 152same: 153 %cmp2 = icmp sle i32 %x, %y 154; CHECK: ret i1 false 155 ret i1 %cmp2 156 157different: 158 %cmp3 = icmp sgt i32 %x, %y 159; CHECK: ret i1 false 160 ret i1 %cmp3 161} 162 163; CHECK: @test8 164define i1 @test8(i32 %x, i32 %y) { 165 %cmp2 = icmp sle i32 %x, %y 166 %cmp = icmp sgt i32 %x, %y 167 %cmp3 = icmp sgt i32 %x, %y 168 br i1 %cmp, label %same, label %different 169 170same: 171; CHECK: ret i1 false 172 ret i1 %cmp2 173 174different: 175; CHECK: ret i1 false 176 ret i1 %cmp3 177} 178 179; PR1768 180; CHECK: @test9 181define i32 @test9(i32 %i, i32 %j) { 182 %cmp = icmp eq i32 %i, %j 183 br i1 %cmp, label %cond_true, label %ret 184 185cond_true: 186 %diff = sub i32 %i, %j 187 ret i32 %diff 188; CHECK: ret i32 0 189 190ret: 191 ret i32 5 192; CHECK: ret i32 5 193} 194 195; PR1768 196; CHECK: @test10 197define i32 @test10(i32 %j, i32 %i) { 198 %cmp = icmp eq i32 %i, %j 199 br i1 %cmp, label %cond_true, label %ret 200 201cond_true: 202 %diff = sub i32 %i, %j 203 ret i32 %diff 204; CHECK: ret i32 0 205 206ret: 207 ret i32 5 208; CHECK: ret i32 5 209} 210 211declare i32 @yogibar() 212 213; CHECK: @test11 214define i32 @test11(i32 %x) { 215 %v0 = call i32 @yogibar() 216 %v1 = call i32 @yogibar() 217 %cmp = icmp eq i32 %v0, %v1 218 br i1 %cmp, label %cond_true, label %next 219 220cond_true: 221 ret i32 %v1 222; CHECK: ret i32 %v0 223 224next: 225 %cmp2 = icmp eq i32 %x, %v0 226 br i1 %cmp2, label %cond_true2, label %next2 227 228cond_true2: 229 ret i32 %v0 230; CHECK: ret i32 %x 231 232next2: 233 ret i32 0 234} 235 236; CHECK: @test12 237define i32 @test12(i32 %x) { 238 %cmp = icmp eq i32 %x, 0 239 br i1 %cmp, label %cond_true, label %cond_false 240 241cond_true: 242 br label %ret 243 244cond_false: 245 br label %ret 246 247ret: 248 %res = phi i32 [ %x, %cond_true ], [ %x, %cond_false ] 249; CHECK: %res = phi i32 [ 0, %cond_true ], [ %x, %cond_false ] 250 ret i32 %res 251} 252