Skip to content
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

[llvm][AArch64] Fix Arm 32 bit build warnings #90862

Merged
merged 1 commit into from
May 2, 2024

Conversation

DavidSpickett
Copy link
Collaborator

#84173 added uses of std::labs on an int64_t which leads to this warning on Arm 32 bit:

/home/david.spickett/llvm-project/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:16655:12: warning: absolute value function 'labs' given an argument of type 'long long' but has parameter of type 'long' which may cause truncation of value [-Wabsolute-value]
    return std::labs(Imm / 4) <= 16;
           ^
/home/david.spickett/llvm-project/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:16655:12: note: use function 'std::abs' instead
    return std::labs(Imm / 4) <= 16;
           ^~~~~~~~~
           std::abs

Since int64_t is "long long" on Arm, not "long".

Use std::abs instead since it has versions for "long" and "long long", we'll pick up the right one at compile time
(https://en.cppreference.com/w/cpp/numeric/math/abs).

llvm#84173 added uses
of std::labs on an int64_t which leads to this warning on
Arm 32 bit:
/home/david.spickett/llvm-project/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:16655:12: warning: absolute value function 'labs' given an argument of type 'long long' but has parameter of type 'long' which may cause truncation of value [-Wabsolute-value]
    return std::labs(Imm / 4) <= 16;
           ^
/home/david.spickett/llvm-project/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:16655:12: note: use function 'std::abs' instead
    return std::labs(Imm / 4) <= 16;
           ^~~~~~~~~
           std::abs

Since int64_t is "long long" on Arm, not "long".

Use std::abs instead since it has versions for "long" and "long long",
we'll pick up the right one at compile time
(https://en.cppreference.com/w/cpp/numeric/math/abs).
@llvmbot
Copy link
Collaborator

llvmbot commented May 2, 2024

@llvm/pr-subscribers-backend-aarch64

Author: David Spickett (DavidSpickett)

Changes

#84173 added uses of std::labs on an int64_t which leads to this warning on Arm 32 bit:

/home/david.spickett/llvm-project/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:16655:12: warning: absolute value function 'labs' given an argument of type 'long long' but has parameter of type 'long' which may cause truncation of value [-Wabsolute-value]
    return std::labs(Imm / 4) &lt;= 16;
           ^
/home/david.spickett/llvm-project/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:16655:12: note: use function 'std::abs' instead
    return std::labs(Imm / 4) &lt;= 16;
           ^~~~~~~~~
           std::abs

Since int64_t is "long long" on Arm, not "long".

Use std::abs instead since it has versions for "long" and "long long", we'll pick up the right one at compile time
(https://en.cppreference.com/w/cpp/numeric/math/abs).


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

1 Files Affected:

  • (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+3-3)
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 2af679e0755b54..b4f7a7812b881a 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -16649,13 +16649,13 @@ bool AArch64TargetLowering::isLegalAddScalableImmediate(int64_t Imm) const {
 
   // inch|dech
   if (Imm % 8 == 0)
-    return std::labs(Imm / 8) <= 16;
+    return std::abs(Imm / 8) <= 16;
   // incw|decw
   if (Imm % 4 == 0)
-    return std::labs(Imm / 4) <= 16;
+    return std::abs(Imm / 4) <= 16;
   // incd|decd
   if (Imm % 2 == 0)
-    return std::labs(Imm / 2) <= 16;
+    return std::abs(Imm / 2) <= 16;
 
   return false;
 }

@DavidSpickett
Copy link
Collaborator Author

I expect the immediate was never going to be large enough for this to be a problem, but it'll reduce some noise on the build bot.

Copy link
Collaborator

@huntergr-arm huntergr-arm left a comment

Choose a reason for hiding this comment

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

LGTM

@DavidSpickett DavidSpickett merged commit f5b4e20 into llvm:main May 2, 2024
5 of 6 checks passed
@DavidSpickett DavidSpickett deleted the arm32 branch May 2, 2024 15: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.

None yet

3 participants