Skip to content

Conversation

@antangelo
Copy link
Contributor

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

…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.
@llvmbot
Copy link
Member

llvmbot commented Nov 27, 2024

@llvm/pr-subscribers-backend-aarch64

@llvm/pr-subscribers-llvm-globalisel

Author: None (antangelo)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/117835.diff

2 Files Affected:

  • (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+1)
  • (modified) llvm/test/CodeGen/Generic/builtin-expect-with-probability.ll (+1)
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)
 

@@ -1,4 +1,5 @@
; RUN: llc < %s
; RUN: llc -global-isel < %s

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing test is woefully inadequate. Should fix this in a pre-commit. This needs to have checks, and should not be a "Generic" test. Those cannot exist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For generic changes like this, is it sufficient to test against one backend or does each one need its own coverage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved testing for GISel to the AArch64 IRTranslator no-op intrinsics suite, where similar tests lie, and removed the update to the generic one. I'll update the SelectionDAG tests to be specific and remove the generic one altogether separately.

@antangelo antangelo merged commit b9ac390 into llvm:main Nov 30, 2024
9 checks passed
@antangelo antangelo deleted the fix-llvm-expect-with-prob-gisel branch November 30, 2024 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clang-20 crashed with optnone attribute at -O1 and above. error in backend: Cannot select: intrinsic %llvm.expect.with.probability.

3 participants