[llvm] [GISel] Add generic implementation for @llvm.expect.with.probability when optimizations are disabled (PR #117835)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 26 18:52:07 PST 2024


https://github.com/antangelo created https://github.com/llvm/llvm-project/pull/117835

Handle @llvm.expect.with.probability in GlobalISel in the same way @llvm.expect is handled, passing the value through as-is. This can be encountered if the intrinsic is used without optimizations, which would otherwise transform it out.

Fixes #115411 for GlobalISel

>From 747bc8a715d7e4e0ab21a09ca1810fdeb1c1db07 Mon Sep 17 00:00:00 2001
From: antangelo <contact at antangelo.com>
Date: Tue, 26 Nov 2024 21:44:16 -0500
Subject: [PATCH] [GISel] Add generic implementation for
 @llvm.expect.with.probability when optimizations are disabled

Handle @llvm.expect.with.probability in GlobalISel in the same way
@llvm.expect is handled, passing the value through as-is. This can be
encountered if the intrinsic is used without optimizations, which would
otherwise transform it out.
---
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp                 | 1 +
 llvm/test/CodeGen/Generic/builtin-expect-with-probability.ll | 1 +
 2 files changed, 2 insertions(+)

diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 675f55d8086bc3..f668e41094bbc8 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -2431,6 +2431,7 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
   case Intrinsic::invariant_end:
     return true;
   case Intrinsic::expect:
+  case Intrinsic::expect_with_probability:
   case Intrinsic::annotation:
   case Intrinsic::ptr_annotation:
   case Intrinsic::launder_invariant_group:
diff --git a/llvm/test/CodeGen/Generic/builtin-expect-with-probability.ll b/llvm/test/CodeGen/Generic/builtin-expect-with-probability.ll
index aef134b636d5a7..76e9e5e81aae0f 100644
--- a/llvm/test/CodeGen/Generic/builtin-expect-with-probability.ll
+++ b/llvm/test/CodeGen/Generic/builtin-expect-with-probability.ll
@@ -1,4 +1,5 @@
 ; RUN: llc < %s
+; RUN: llc -global-isel < %s
 
 declare i32 @llvm.expect.with.probability(i32, i32, double)
 



More information about the llvm-commits mailing list