[llvm] 2bf473b - [GlobalOpt] Don't query TTI on a llvm.memcpy declaration. (#127760)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 19 10:17:10 PST 2025


Author: Craig Topper
Date: 2025-02-19T10:17:07-08:00
New Revision: 2bf473bd546e65f8fc2f0d5006b8c8ef07259e24

URL: https://github.com/llvm/llvm-project/commit/2bf473bd546e65f8fc2f0d5006b8c8ef07259e24
DIFF: https://github.com/llvm/llvm-project/commit/2bf473bd546e65f8fc2f0d5006b8c8ef07259e24.diff

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

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
https://github.com/llvm/llvm-project/issues/69780#issuecomment-2665273161

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/GlobalOpt.cpp

Removed: 
    


################################################################################
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);


        


More information about the llvm-commits mailing list