[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 20:00:29 PST 2024


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

>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 1/2] [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)
 

>From dfcdc78b52c43f728fc85d72eb78de5e89ec9cf6 Mon Sep 17 00:00:00 2001
From: antangelo <contact at antangelo.com>
Date: Tue, 26 Nov 2024 22:59:54 -0500
Subject: [PATCH 2/2] Replace generic test case with AArch64 MIR test

---
 .../AArch64/GlobalISel/irtranslator-no-op-intrinsics.ll      | 5 ++---
 llvm/test/CodeGen/Generic/builtin-expect-with-probability.ll | 1 -
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-no-op-intrinsics.ll b/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-no-op-intrinsics.ll
index 88828950353a7e..4ab347c37f0d7a 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-no-op-intrinsics.ll
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-no-op-intrinsics.ll
@@ -20,9 +20,8 @@ define i64 @expect_with_probability_i64(i64 %arg0) {
   ; CHECK-NEXT:   liveins: $x0
   ; CHECK-NEXT: {{  $}}
   ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(s64) = COPY $x0
-  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
-  ; CHECK-NEXT:   [[INT:%[0-9]+]]:_(s64) = G_INTRINSIC intrinsic(@llvm.expect.with.probability), [[COPY]](s64), [[C]](s64), double 5.000000e-01
-  ; CHECK-NEXT:   $x0 = COPY [[INT]](s64)
+  ; CHECK-NEXT:   [[COPY1:%[0-9]+]]:_(s64) = COPY [[COPY]](s64)
+  ; CHECK-NEXT:   $x0 = COPY [[COPY1]](s64)
   ; CHECK-NEXT:   RET_ReallyLR implicit $x0
   %expval = call i64 @llvm.expect.with.probability.i64(i64 %arg0, i64 1, double 0.5)
   ret i64 %expval
diff --git a/llvm/test/CodeGen/Generic/builtin-expect-with-probability.ll b/llvm/test/CodeGen/Generic/builtin-expect-with-probability.ll
index 76e9e5e81aae0f..aef134b636d5a7 100644
--- a/llvm/test/CodeGen/Generic/builtin-expect-with-probability.ll
+++ b/llvm/test/CodeGen/Generic/builtin-expect-with-probability.ll
@@ -1,5 +1,4 @@
 ; 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