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