[llvm] 66bb752 - [PreISelIntrinsicLowering] Use TLI for correct function

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 16 01:02:26 PDT 2023


Author: Nikita Popov
Date: 2023-08-16T10:02:18+02:00
New Revision: 66bb7521625826cab6fcc24662c053deee1ef90c

URL: https://github.com/llvm/llvm-project/commit/66bb7521625826cab6fcc24662c053deee1ef90c
DIFF: https://github.com/llvm/llvm-project/commit/66bb7521625826cab6fcc24662c053deee1ef90c.diff

LOG: [PreISelIntrinsicLowering] Use TLI for correct function

We should query the subtarget of the calling function, not of the
intrinsic.

This probably makes no functional difference (as libcalls are
unlikely to vary across subtargets), but fixes minor compile-time
regressions from unnecessary subtarget instantiations.

Followup to D157567.

Differential Revision: https://reviews.llvm.org/D157848

Added: 
    

Modified: 
    llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
index 098489ec9518d5..93183067797081 100644
--- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -197,15 +197,16 @@ bool PreISelIntrinsicLowering::shouldExpandMemIntrinsicWithSize(
   return SizeVal > Threshold || Threshold == 0;
 }
 
-static bool canEmitLibcall(const TargetLowering &TLI, RTLIB::Libcall LC) {
+static bool canEmitLibcall(const TargetMachine &TM, Function *F,
+                           RTLIB::Libcall LC) {
   // TODO: Should this consider the address space of the memcpy?
-  return TLI.getLibcallName(LC) != nullptr;
+  const TargetLowering *TLI = TM.getSubtargetImpl(*F)->getTargetLowering();
+  return TLI->getLibcallName(LC) != nullptr;
 }
 
 // TODO: Handle atomic memcpy and memcpy.inline
 // TODO: Pass ScalarEvolution
 bool PreISelIntrinsicLowering::expandMemIntrinsicUses(Function &F) const {
-  const TargetLowering *TLI = TM.getSubtargetImpl(F)->getTargetLowering();
   Intrinsic::ID ID = F.getIntrinsicID();
   bool Changed = false;
 
@@ -218,7 +219,8 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(Function &F) const {
       Function *ParentFunc = Memcpy->getFunction();
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memcpy->getLength(), TTI)) {
-        if (UseMemIntrinsicLibFunc && canEmitLibcall(*TLI, RTLIB::MEMCPY))
+        if (UseMemIntrinsicLibFunc &&
+            canEmitLibcall(TM, ParentFunc, RTLIB::MEMCPY))
           break;
 
         // TODO: For optsize, emit the loop into a separate function
@@ -234,7 +236,8 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(Function &F) const {
       Function *ParentFunc = Memmove->getFunction();
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memmove->getLength(), TTI)) {
-        if (UseMemIntrinsicLibFunc && canEmitLibcall(*TLI, RTLIB::MEMMOVE))
+        if (UseMemIntrinsicLibFunc &&
+            canEmitLibcall(TM, ParentFunc, RTLIB::MEMMOVE))
           break;
 
         if (expandMemMoveAsLoop(Memmove, TTI)) {
@@ -250,7 +253,8 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(Function &F) const {
       Function *ParentFunc = Memset->getFunction();
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memset->getLength(), TTI)) {
-        if (UseMemIntrinsicLibFunc && canEmitLibcall(*TLI, RTLIB::MEMSET))
+        if (UseMemIntrinsicLibFunc &&
+            canEmitLibcall(TM, ParentFunc, RTLIB::MEMSET))
           break;
 
         expandMemSetAsLoop(Memset);


        


More information about the llvm-commits mailing list