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

[X86] Don't fold non-temporal loads if we have an instruction for them #86839

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AtariDreams
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 27, 2024

@llvm/pr-subscribers-backend-x86

Author: AtariDreams (AtariDreams)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+29-2)
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 9d98d31b31df0b..a9e707cb0857cd 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -2586,6 +2586,32 @@ X86TargetLowering::createFastISel(FunctionLoweringInfo &funcInfo,
 //                           Other Lowering Hooks
 //===----------------------------------------------------------------------===//
 
+// Indicates we should prefer to use a non-temporal load for this load.
+// TODO: Should be merged with useNonTemporalLoad in X86ISelDAGToDAG.cpp
+static bool useNonTemporalLoad(LoadSDNode *N, const X86Subtarget &Subtarget) {
+  if (!N->isNonTemporal())
+    return false;
+
+  unsigned StoreSize = N->getMemoryVT().getStoreSize();
+
+  if (N->getAlign().value() < StoreSize)
+    return false;
+
+  switch (StoreSize) {
+  default:
+    llvm_unreachable("Unsupported store size");
+  case 4:
+  case 8:
+    return false;
+  case 16:
+    return Subtarget.hasSSE41();
+  case 32:
+    return Subtarget.hasAVX2();
+  case 64:
+    return Subtarget.hasAVX512();
+  }
+}
+
 bool X86::mayFoldLoad(SDValue Op, const X86Subtarget &Subtarget,
                       bool AssumeSingleUse) {
   if (!AssumeSingleUse && !Op.hasOneUse())
@@ -2599,8 +2625,9 @@ bool X86::mayFoldLoad(SDValue Op, const X86Subtarget &Subtarget,
       Ld->getValueSizeInBits(0) == 128 && Ld->getAlign() < Align(16))
     return false;
 
-  // TODO: If this is a non-temporal load and the target has an instruction
-  //       for it, it should not be folded. See "useNonTemporalLoad()".
+  // Don't fold non-temporal loads if we have an instruction for them.
+  if (useNonTemporalLoad(Ld, Subtarget))
+    return false;
 
   return true;
 }

@AtariDreams AtariDreams marked this pull request as draft March 27, 2024 18:34
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

2 participants