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

[GlobalOpt] Don't query TTI on a llvm.memcpy declaration. #127760

Merged
merged 1 commit into from
Feb 19, 2025

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Feb 19, 2025

Querying TTI creates a Subtarget object, but an llvm.memcpy declaration doesn't have target-cpu and target-feature attributes like functions with definitions. This can cause a warning to be printed on RISC-V because the target-abi in the Module requires floating point, but the subtarget features don't enable floating point. So far we've only seen this in LTO when an -mcpu is not supplied for the TargetMachine.

To fix this, get TTI for the calling function instead.

Fixes the issue reported here #69780 (comment)

Querying TTI creates a Subtarget object, but an llvm.memcpy
declaration doesn't have target-cpu and target-feature attributes
like functions with definitions. This can cause a warning to be printed
on RISC-V because the target-abi in the Module requires floating
point, but the subtarget features don't enable floating point.
So far we've only seen this in LTO when an -mcpu is not supplied
for the TargetMachine.

To fix this, get TTI for the calling function instead.
@llvmbot
Copy link
Member

llvmbot commented Feb 19, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Craig Topper (topperc)

Changes

Querying TTI creates a Subtarget object, but an llvm.memcpy declaration doesn't have target-cpu and target-feature attributes like functions with definitions. This can cause a warning to be printed on RISC-V because the target-abi in the Module requires floating point, but the subtarget features don't enable floating point. So far we've only seen this in LTO when an -mcpu is not supplied for the TargetMachine.

To fix this, get TTI for the calling function instead.

Fixes the issue reported here #69780 (comment)


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/GlobalOpt.cpp (+4-2)
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 9586fc97a39f7..1a2a27d22ae68 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2186,8 +2186,10 @@ static bool tryWidenGlobalArraysUsedByMemcpy(
     if (NumElementsToCopy != DZSize || DZSize != SZSize)
       continue;
 
-    unsigned NumBytesToPad = GetTTI(*F).getNumBytesToPadGlobalArray(
-        NumBytesToCopy, SourceDataArray->getType());
+    unsigned NumBytesToPad =
+        GetTTI(*CI->getFunction())
+            .getNumBytesToPadGlobalArray(NumBytesToCopy,
+                                         SourceDataArray->getType());
     if (NumBytesToPad) {
       return tryWidenGlobalArrayAndDests(F, GV, NumBytesToPad, NumBytesToCopy,
                                          BytesToCopyOp, SourceDataArray);

Copy link
Contributor

@asb asb left a comment

Choose a reason for hiding this comment

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

LGTM

@lenary
Copy link
Member

lenary commented Feb 19, 2025

Is it possible to write a regression test for this?

@topperc
Copy link
Collaborator Author

topperc commented Feb 19, 2025

Is it possible to write a regression test for this?

No target uses subtarget information in their implementation of getNumBytesToPadGlobalArray so I think the only thing we could test is the absence of the warning message from RISC-V.

@topperc topperc merged commit 2bf473b into llvm:main Feb 19, 2025
10 checks passed
@topperc topperc deleted the pr/globalopt-warning branch February 19, 2025 18:17
@arichardson
Copy link
Member

Could we assert that GetTTI is not used on intrinsics to prevent something like this from happening again?

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.

6 participants