[clang] [CIR] Add support for __builtin_expect (PR #144726)
Sirui Mu via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 24 08:29:53 PDT 2025
================
@@ -2446,4 +2446,41 @@ def AssumeOp : CIR_Op<"assume"> {
}];
}
+//===----------------------------------------------------------------------===//
+// Branch Probability Operations
+//===----------------------------------------------------------------------===//
+
+def ExpectOp : CIR_Op<"expect",
+ [Pure, AllTypesMatch<["result", "val", "expected"]>]> {
+ let summary = "Tell the optimizer that two values are likely to be equal.";
+ let description = [{
+ The `cir.expect` operation may take 2 or 3 arguments.
+
+ When the argument `prob` is missing, this operation effectively models the
+ `__builtin_expect` builtin function. It tells the optimizer that `val` and
+ `expected` are likely to be equal.
+
+ When the argumen `prob` is present, this operation effectively models the
+ `__builtin_expect_with_probability` builtin function. It tells the
+ optimizer that `val` and `expected` are equal to each other with a certain
+ probability.
+
+ `val` and `expected` must be integers and their types must match.
----------------
Lancern wrote:
The `@llvm.expect` intrinsic function accepts `i1`, `i32`, and `i64` as arguments. We may take it as a reference.
https://github.com/llvm/llvm-project/pull/144726
More information about the cfe-commits
mailing list