Skip to content

[SelectionDAG] Add generic implementation for @llvm.expect.with.probability when optimizations are disabled #117459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions llvm/lib/CodeGen/IntrinsicLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,10 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
report_fatal_error("Code generator does not support intrinsic function '"+
Callee->getName()+"'!");

case Intrinsic::expect: {
// Just replace __builtin_expect(exp, c) with EXP.
case Intrinsic::expect:
case Intrinsic::expect_with_probability: {
// Just replace __builtin_expect(exp, c) and
// __builtin_expect_with_probability(exp, c, p) with EXP.
Value *V = CI->getArgOperand(0);
CI->replaceAllUsesWith(V);
break;
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,8 @@ bool FastISel::selectIntrinsicCall(const IntrinsicInst *II) {

case Intrinsic::launder_invariant_group:
case Intrinsic::strip_invariant_group:
case Intrinsic::expect: {
case Intrinsic::expect:
case Intrinsic::expect_with_probability: {
Register ResultReg = getRegForValue(II->getArgOperand(0));
if (!ResultReg)
return false;
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7532,7 +7532,9 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
return;

case Intrinsic::expect:
// Just replace __builtin_expect(exp, c) with EXP.
case Intrinsic::expect_with_probability:
// Just replace __builtin_expect(exp, c) and
// __builtin_expect_with_probability(exp, c, p) with EXP.
setValue(&I, getValue(I.getArgOperand(0)));
return;

Expand Down
8 changes: 8 additions & 0 deletions llvm/test/CodeGen/Generic/builtin-expect-with-probability.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; RUN: llc < %s

declare i32 @llvm.expect.with.probability(i32, i32, double)

define i32 @test1(i32 %val) nounwind {
%expected = call i32 @llvm.expect.with.probability(i32 %val, i32 1, double 0.5)
ret i32 %expected
}
Loading