llvm.org GIT mirror llvm / 7ce6430
Fix builin_expect lowering bug PR33346 Skip cases when expected value is not constant int. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304933 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 2 years ago
2 changed file(s) with 25 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
9292 /// the branch probability info for the originating branch can be inferred.
9393 static void handlePhiDef(CallInst *Expect) {
9494 Value &Arg = *Expect->getArgOperand(0);
95 ConstantInt *ExpectedValue = cast(Expect->getArgOperand(1));
95 ConstantInt *ExpectedValue = dyn_cast(Expect->getArgOperand(1));
96 if (!ExpectedValue)
97 return;
9698 const APInt &ExpectedPhiValue = ExpectedValue->getValue();
9799
98100 // Walk up in backward a list of instructions that
0 ; RUN: opt -lower-expect -S < %s
1 ; RUN: opt -passes='function(lower-expect)' -S < %s
2
3 define i64 @foo(i64 %arg) #0 {
4 bb:
5 %tmp = alloca i64, align 8
6 store i64 %arg, i64* %tmp, align 8
7 %tmp1 = load i64, i64* %tmp, align 8
8 %tmp2 = load i64, i64* %tmp, align 8
9 %tmp3 = call i64 @llvm.expect.i64(i64 %tmp1, i64 %tmp2)
10 ret i64 %tmp3
11 }
12
13 ; Function Attrs: nounwind readnone
14 declare i64 @llvm.expect.i64(i64, i64)
15
16
17 !llvm.module.flags = !{!0}
18 !llvm.ident = !{!1}
19
20 !0 = !{i32 1, !"wchar_size", i32 4}
21 !1 = !{!"clang version 5.0.0 (trunk 304723)"}