[PATCH] D35431: Extend FindAllMemoryUses for target intrinsics

Nick Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 14 12:02:20 PDT 2017


npjdesres created this revision.

In order to promote instruction selection of complicated addressing
modes, CodeGenPrepaer::optimizeCallInst() determines whether an address
computation from an earlier basic-block should be sunk to its use.  It
natively comprehends InlineAsm uses and it calls the target hook
TLI.getAddrModeArguments() in order to comprehend target-specific memory
intrinsics.  Next, it checks optimizeMemoryInsts() to decide whether
sinking the address expression would be profitable.

      

Althought, optimizeMemoryInsts comprehends uses by InlineAsm, it does
*not* completely support target-specific memory intrinsics.

Specifically, optimizeMemoryInsts() calls isProfitableToFoldIntoAddressingMode(),
which calls FindAllMemoryUses().  FindAllMemoryUses does not query
the same target hook; thus it reports failure (return true)
for any call instruction which is not an InlineAsm.

      

This patch extends FindAllMemoryUses so that it will additionally check
whether the CallInst is recognized by the target hook.


https://reviews.llvm.org/D35431

Files:
  lib/CodeGen/CodeGenPrepare.cpp


Index: lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- lib/CodeGen/CodeGenPrepare.cpp
+++ lib/CodeGen/CodeGenPrepare.cpp
@@ -4073,13 +4073,25 @@
       if (!OptSize && CI->hasFnAttr(Attribute::Cold))
         continue;
 
-      InlineAsm *IA = dyn_cast<InlineAsm>(CI->getCalledValue());
-      if (!IA) return true;
+      if (InlineAsm *IA = dyn_cast<InlineAsm>(CI->getCalledValue())) {
+        // If this is a memory operand, we're cool, otherwise bail out.
+        if (!IsOperandAMemoryOperand(CI, IA, I, TLI, TRI))
+          return true;
+        continue;
+      }
 
-      // If this is a memory operand, we're cool, otherwise bail out.
-      if (!IsOperandAMemoryOperand(CI, IA, I, TLI, TRI))
-        return true;
-      continue;
+      // Perhaps this is a target-specific memory intrinsic.
+      if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(CI)) {
+        SmallVector<Value *, 1> PtrOps;
+        Type *AccessTy;
+        if (!TLI.getAddrModeArguments(II, PtrOps, AccessTy))
+          return true;
+        if (std::find(PtrOps.begin(), PtrOps.end(), I) == PtrOps.end())
+          return true;
+        continue;
+      }
+
+      return true;
     }
 
     if (FindAllMemoryUses(UserI, MemoryUses, ConsideredInsts, TLI, TRI))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35431.106684.patch
Type: text/x-patch
Size: 1304 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170714/71a57ce8/attachment.bin>


More information about the llvm-commits mailing list