Skip to content

llvm.expect intrinsic from likely/unlikely is not emitted in release mode #96276

Closed
@Kobzol

Description

@Kobzol

When the std::intrinsics::unlikely/likely function is used, the codegen doesn't emit llvm.expect annotation in release mode. Curiously enough, in debug mode it does emit it.

A minimal example:

#![feature(core_intrinsics)]

use std::intrinsics::unlikely;

pub fn foo(x: bool) {
    if unlikely(x) {
        println!("foo: {x}");
    }
    println!("bar");
}

Playground link here. In debug mode, LLVM IR contains llvm.expect. In release mode, it doesn't.

This has been previously noted here (maybe it indeed started with LLVM 13?) and more recently here.

I can take a look into this, if you can point me into the right direction. There is a codegen test for likely/unlikely, but it uses -C no-prepopulate-passes, which does not correspond to what release (-O) does.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions