brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.3 KiB · 8e06cd5 Raw
291 lines · plain
1; RUN: opt -S -passes='function(lower-expect),strip-dead-prototypes' < %s | FileCheck %s2 3; CHECK-LABEL: @test1(4define i32 @test1(i32 %x) nounwind uwtable ssp {5entry:6  %retval = alloca i32, align 47  %x.addr = alloca i32, align 48  store i32 %x, ptr %x.addr, align 49  %tmp = load i32, ptr %x.addr, align 410  %cmp = icmp sgt i32 %tmp, 111  %conv = zext i1 %cmp to i3212  %conv1 = sext i32 %conv to i6413  %expval = call i64 @llvm.expect.i64(i64 %conv1, i64 1)14  %tobool = icmp ne i64 %expval, 015; CHECK: !prof !016; CHECK-NOT: @llvm.expect17  br i1 %tobool, label %if.then, label %if.end18 19if.then:                                          ; preds = %entry20  %call = call i32 (...) @f()21  store i32 %call, ptr %retval22  br label %return23 24if.end:                                           ; preds = %entry25  store i32 1, ptr %retval26  br label %return27 28return:                                           ; preds = %if.end, %if.then29  %0 = load i32, ptr %retval30  ret i32 %031}32 33declare i64 @llvm.expect.i64(i64, i64) nounwind readnone34 35declare i32 @f(...)36 37; CHECK-LABEL: @test2(38define i32 @test2(i32 %x) nounwind uwtable ssp {39entry:40  %retval = alloca i32, align 441  %x.addr = alloca i32, align 442  store i32 %x, ptr %x.addr, align 443  %tmp = load i32, ptr %x.addr, align 444  %conv = sext i32 %tmp to i6445  %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)46  %tobool = icmp ne i64 %expval, 047; CHECK: !prof !048; CHECK-NOT: @llvm.expect49  br i1 %tobool, label %if.then, label %if.end50 51if.then:                                          ; preds = %entry52  %call = call i32 (...) @f()53  store i32 %call, ptr %retval54  br label %return55 56if.end:                                           ; preds = %entry57  store i32 1, ptr %retval58  br label %return59 60return:                                           ; preds = %if.end, %if.then61  %0 = load i32, ptr %retval62  ret i32 %063}64 65; CHECK-LABEL: @test3(66define i32 @test3(i32 %x) nounwind uwtable ssp {67entry:68  %retval = alloca i32, align 469  %x.addr = alloca i32, align 470  store i32 %x, ptr %x.addr, align 471  %tmp = load i32, ptr %x.addr, align 472  %tobool = icmp ne i32 %tmp, 073  %lnot = xor i1 %tobool, true74  %lnot.ext = zext i1 %lnot to i3275  %conv = sext i32 %lnot.ext to i6476  %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)77  %tobool1 = icmp ne i64 %expval, 078; CHECK: !prof !079; CHECK-NOT: @llvm.expect80  br i1 %tobool1, label %if.then, label %if.end81 82if.then:                                          ; preds = %entry83  %call = call i32 (...) @f()84  store i32 %call, ptr %retval85  br label %return86 87if.end:                                           ; preds = %entry88  store i32 1, ptr %retval89  br label %return90 91return:                                           ; preds = %if.end, %if.then92  %0 = load i32, ptr %retval93  ret i32 %094}95 96; CHECK-LABEL: @test4(97define i32 @test4(i32 %x) nounwind uwtable ssp {98entry:99  %retval = alloca i32, align 4100  %x.addr = alloca i32, align 4101  store i32 %x, ptr %x.addr, align 4102  %tmp = load i32, ptr %x.addr, align 4103  %tobool = icmp ne i32 %tmp, 0104  %lnot = xor i1 %tobool, true105  %lnot1 = xor i1 %lnot, true106  %lnot.ext = zext i1 %lnot1 to i32107  %conv = sext i32 %lnot.ext to i64108  %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)109  %tobool2 = icmp ne i64 %expval, 0110; CHECK: !prof !0111; CHECK-NOT: @llvm.expect112  br i1 %tobool2, label %if.then, label %if.end113 114if.then:                                          ; preds = %entry115  %call = call i32 (...) @f()116  store i32 %call, ptr %retval117  br label %return118 119if.end:                                           ; preds = %entry120  store i32 1, ptr %retval121  br label %return122 123return:                                           ; preds = %if.end, %if.then124  %0 = load i32, ptr %retval125  ret i32 %0126}127 128; CHECK-LABEL: @test5(129define i32 @test5(i32 %x) nounwind uwtable ssp {130entry:131  %retval = alloca i32, align 4132  %x.addr = alloca i32, align 4133  store i32 %x, ptr %x.addr, align 4134  %tmp = load i32, ptr %x.addr, align 4135  %cmp = icmp slt i32 %tmp, 0136  %conv = zext i1 %cmp to i32137  %conv1 = sext i32 %conv to i64138  %expval = call i64 @llvm.expect.i64(i64 %conv1, i64 0)139  %tobool = icmp ne i64 %expval, 0140; CHECK: !prof !1141; CHECK-NOT: @llvm.expect142  br i1 %tobool, label %if.then, label %if.end143 144if.then:                                          ; preds = %entry145  %call = call i32 (...) @f()146  store i32 %call, ptr %retval147  br label %return148 149if.end:                                           ; preds = %entry150  store i32 1, ptr %retval151  br label %return152 153return:                                           ; preds = %if.end, %if.then154  %0 = load i32, ptr %retval155  ret i32 %0156}157 158; CHECK-LABEL: @test6(159define i32 @test6(i32 %x) nounwind uwtable ssp {160entry:161  %retval = alloca i32, align 4162  %x.addr = alloca i32, align 4163  store i32 %x, ptr %x.addr, align 4164  %tmp = load i32, ptr %x.addr, align 4165  %conv = sext i32 %tmp to i64166  %expval = call i64 @llvm.expect.i64(i64 %conv, i64 2)167; CHECK: !prof !2168; CHECK-NOT: @llvm.expect169  switch i64 %expval, label %sw.epilog [170    i64 1, label %sw.bb171    i64 2, label %sw.bb172  ]173 174sw.bb:                                            ; preds = %entry, %entry175  store i32 0, ptr %retval176  br label %return177 178sw.epilog:                                        ; preds = %entry179  store i32 1, ptr %retval180  br label %return181 182return:                                           ; preds = %sw.epilog, %sw.bb183  %0 = load i32, ptr %retval184  ret i32 %0185}186 187; CHECK-LABEL: @test7(188define i32 @test7(i32 %x) nounwind uwtable ssp {189entry:190  %retval = alloca i32, align 4191  %x.addr = alloca i32, align 4192  store i32 %x, ptr %x.addr, align 4193  %tmp = load i32, ptr %x.addr, align 4194  %conv = sext i32 %tmp to i64195  %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)196; CHECK: !prof !3197; CHECK-NOT: @llvm.expect198  switch i64 %expval, label %sw.epilog [199    i64 2, label %sw.bb200    i64 3, label %sw.bb201  ]202 203sw.bb:                                            ; preds = %entry, %entry204  %tmp1 = load i32, ptr %x.addr, align 4205  store i32 %tmp1, ptr %retval206  br label %return207 208sw.epilog:                                        ; preds = %entry209  store i32 0, ptr %retval210  br label %return211 212return:                                           ; preds = %sw.epilog, %sw.bb213  %0 = load i32, ptr %retval214  ret i32 %0215}216 217; CHECK-LABEL: @test8(218define i32 @test8(i32 %x) nounwind uwtable ssp {219entry:220  %retval = alloca i32, align 4221  %x.addr = alloca i32, align 4222  store i32 %x, ptr %x.addr, align 4223  %tmp = load i32, ptr %x.addr, align 4224  %cmp = icmp sgt i32 %tmp, 1225  %conv = zext i1 %cmp to i32226  %expval = call i32 @llvm.expect.i32(i32 %conv, i32 1)227  %tobool = icmp ne i32 %expval, 0228; CHECK: !prof !0229; CHECK-NOT: @llvm.expect230  br i1 %tobool, label %if.then, label %if.end231 232if.then:                                          ; preds = %entry233  %call = call i32 (...) @f()234  store i32 %call, ptr %retval235  br label %return236 237if.end:                                           ; preds = %entry238  store i32 1, ptr %retval239  br label %return240 241return:                                           ; preds = %if.end, %if.then242  %0 = load i32, ptr %retval243  ret i32 %0244}245 246declare i32 @llvm.expect.i32(i32, i32) nounwind readnone247 248; CHECK-LABEL: @test9(249define i32 @test9(i32 %x) nounwind uwtable ssp {250entry:251  %retval = alloca i32, align 4252  %x.addr = alloca i32, align 4253  store i32 %x, ptr %x.addr, align 4254  %tmp = load i32, ptr %x.addr, align 4255  %cmp = icmp sgt i32 %tmp, 1256  %expval = call i1 @llvm.expect.i1(i1 %cmp, i1 1)257; CHECK: !prof !0258; CHECK-NOT: @llvm.expect259  br i1 %expval, label %if.then, label %if.end260 261if.then:                                          ; preds = %entry262  %call = call i32 (...) @f()263  store i32 %call, ptr %retval264  br label %return265 266if.end:                                           ; preds = %entry267  store i32 1, ptr %retval268  br label %return269 270return:                                           ; preds = %if.end, %if.then271  %0 = load i32, ptr %retval272  ret i32 %0273}274 275; CHECK-LABEL: @test10(276define i32 @test10(i64 %t6) {277  %t7 = call i64 @llvm.expect.i64(i64 %t6, i64 0)278  %t8 = icmp ne i64 %t7, 0279  %t9 = select i1 %t8, i32 1, i32 2280; CHECK: select{{.*}}, !prof !1281  ret i32 %t9282}283 284 285declare i1 @llvm.expect.i1(i1, i1) nounwind readnone286 287; CHECK: !0 = !{!"branch_weights", !"expected", i32 2000, i32 1}288; CHECK: !1 = !{!"branch_weights", !"expected", i32 1, i32 2000}289; CHECK: !2 = !{!"branch_weights", !"expected", i32 1, i32 1, i32 2000}290; CHECK: !3 = !{!"branch_weights", !"expected", i32 2000, i32 1, i32 1}291