Skip to content

Commit dd48447

Browse files
authored
[SelectionDAG] Add generic implementation for @llvm.expect.with.probability when optimizations are disabled (#117459)
Handle \@llvm.expect.with.probability in SelectionDAGBuilder, FastISel, and IntrinsicLowering in the same way \@llvm.expect is handled, where the value is passed through as-is. This can be reached if the intrinsic is used without optimizations, where it would otherwise be properly transformed out. Fixes #115411 for SelectionDAG. A similar patch is likely needed for GlobalISel.
1 parent ea58410 commit dd48447

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

llvm/lib/CodeGen/IntrinsicLowering.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,10 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
236236
report_fatal_error("Code generator does not support intrinsic function '"+
237237
Callee->getName()+"'!");
238238

239-
case Intrinsic::expect: {
240-
// Just replace __builtin_expect(exp, c) with EXP.
239+
case Intrinsic::expect:
240+
case Intrinsic::expect_with_probability: {
241+
// Just replace __builtin_expect(exp, c) and
242+
// __builtin_expect_with_probability(exp, c, p) with EXP.
241243
Value *V = CI->getArgOperand(0);
242244
CI->replaceAllUsesWith(V);
243245
break;

llvm/lib/CodeGen/SelectionDAG/FastISel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,8 @@ bool FastISel::selectIntrinsicCall(const IntrinsicInst *II) {
14561456

14571457
case Intrinsic::launder_invariant_group:
14581458
case Intrinsic::strip_invariant_group:
1459-
case Intrinsic::expect: {
1459+
case Intrinsic::expect:
1460+
case Intrinsic::expect_with_probability: {
14601461
Register ResultReg = getRegForValue(II->getArgOperand(0));
14611462
if (!ResultReg)
14621463
return false;

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7532,7 +7532,9 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
75327532
return;
75337533

75347534
case Intrinsic::expect:
7535-
// Just replace __builtin_expect(exp, c) with EXP.
7535+
case Intrinsic::expect_with_probability:
7536+
// Just replace __builtin_expect(exp, c) and
7537+
// __builtin_expect_with_probability(exp, c, p) with EXP.
75367538
setValue(&I, getValue(I.getArgOperand(0)));
75377539
return;
75387540

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; RUN: llc < %s
2+
3+
declare i32 @llvm.expect.with.probability(i32, i32, double)
4+
5+
define i32 @test1(i32 %val) nounwind {
6+
%expected = call i32 @llvm.expect.with.probability(i32 %val, i32 1, double 0.5)
7+
ret i32 %expected
8+
}

0 commit comments

Comments
 (0)