Skip to content

[flang][runtime] Correct SELECTED_LOGICAL_KIND() #93108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2024

Conversation

klausler
Copy link
Contributor

The implementation of the runtime version of this intrinsic function in #89691 was incorrect. Fix it to interpret its argument as a bit count.

The implementation of the runtime version of this intrinsic
function in llvm#89691 was
incorrect.  Fix it to interpret its argument as a bit count.
@klausler klausler requested a review from vzakhari May 22, 2024 23:25
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels May 22, 2024
@llvmbot
Copy link
Member

llvmbot commented May 22, 2024

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

Changes

The implementation of the runtime version of this intrinsic function in #89691 was incorrect. Fix it to interpret its argument as a bit count.


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

1 Files Affected:

  • (modified) flang/runtime/numeric.cpp (+4-4)
diff --git a/flang/runtime/numeric.cpp b/flang/runtime/numeric.cpp
index 52b5a56894d88..2225473c4690e 100644
--- a/flang/runtime/numeric.cpp
+++ b/flang/runtime/numeric.cpp
@@ -117,13 +117,13 @@ inline RT_API_ATTRS CppTypeFor<TypeCategory::Integer, 4> SelectedIntKind(T x) {
 template <typename T>
 inline RT_API_ATTRS CppTypeFor<TypeCategory::Integer, 4> SelectedLogicalKind(
     T x) {
-  if (x <= 2) {
+  if (x <= 8) {
     return 1;
-  } else if (x <= 4) {
+  } else if (x <= 16) {
     return 2;
-  } else if (x <= 9) {
+  } else if (x <= 32) {
     return 4;
-  } else if (x <= 18) {
+  } else if (x <= 64) {
     return 8;
   }
   return -1;

Copy link
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

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

Thank you!

@clementval
Copy link
Contributor

@klausler Does this impact the way we lower selected_logical_kind as of #93091 ?

@vzakhari
Copy link
Contributor

@klausler Does this impact the way we lower selected_logical_kind as of #93091 ?

It should not. You just pass through the bits argument to the runtime, right? Actually, your change made me look at the runtime implementation again, and realize that it is not doing what it is supposed to do.

@klausler klausler merged commit 79c2a1e into llvm:main May 23, 2024
6 of 7 checks passed
@klausler klausler deleted the fix-selected-logical branch May 23, 2024 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants