[PATCH] D146600: [LoongArch] Enable LoopDataPrefetch pass

Xiaodong Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 23 20:10:53 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG11674147e406: [LoongArch] Enable LoopDataPrefetch pass (authored by XiaodongLoong).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146600/new/

https://reviews.llvm.org/D146600

Files:
  llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
  llvm/test/Transforms/LoopDataPrefetch/LoongArch/basic.ll
  llvm/test/Transforms/LoopDataPrefetch/LoongArch/lit.local.cfg


Index: llvm/test/Transforms/LoopDataPrefetch/LoongArch/lit.local.cfg
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopDataPrefetch/LoongArch/lit.local.cfg
@@ -0,0 +1,2 @@
+if not 'LoongArch' in config.root.targets:
+    config.unsupported = True
Index: llvm/test/Transforms/LoopDataPrefetch/LoongArch/basic.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopDataPrefetch/LoongArch/basic.ll
@@ -0,0 +1,25 @@
+;; Tag this 'XFAIL' because we need a few more TTIs and ISels.
+; XFAIL: *
+; RUN: opt --mtriple=loongarch64 --passes=loop-data-prefetch -loongarch-enable-loop-data-prefetch -S < %s | FileCheck %s
+
+define void @foo(ptr %a, ptr %b) {
+entry:
+  br label %for.body
+
+; CHECK: for.body:
+for.body:                                         ; preds = %for.body, %entry
+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
+  %arrayidx = getelementptr inbounds double, ptr %b, i64 %indvars.iv
+; CHECK: call void @llvm.prefetch
+  %0 = load double, ptr %arrayidx, align 8
+  %add = fadd double %0, 1.000000e+00
+  %arrayidx2 = getelementptr inbounds double, ptr %a, i64 %indvars.iv
+  store double %add, ptr %arrayidx2, align 8
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond = icmp eq i64 %indvars.iv.next, 1600
+  br i1 %exitcond, label %for.end, label %for.body
+
+; CHECK: for.end:
+for.end:                                          ; preds = %for.body
+  ret void
+}
Index: llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
===================================================================
--- llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
+++ llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
@@ -19,6 +19,7 @@
 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/MC/TargetRegistry.h"
+#include "llvm/Transforms/Scalar.h"
 #include <optional>
 
 using namespace llvm;
@@ -34,6 +35,11 @@
   initializeLoongArchDAGToDAGISelPass(*PR);
 }
 
+static cl::opt<bool>
+    EnableLoopDataPrefetch("loongarch-enable-loop-data-prefetch", cl::Hidden,
+                           cl::desc("Enable the loop data prefetch pass"),
+                           cl::init(false));
+
 static std::string computeDataLayout(const Triple &TT) {
   if (TT.isArch64Bit())
     return "e-m:e-p:64:64-i64:64-i128:128-n64-S128";
@@ -126,6 +132,12 @@
 }
 
 void LoongArchPassConfig::addIRPasses() {
+  // Run LoopDataPrefetch
+  //
+  // Run this before LSR to remove the multiplies involved in computing the
+  // pointer values N iterations ahead.
+  if (TM->getOptLevel() != CodeGenOpt::None && EnableLoopDataPrefetch)
+    addPass(createLoopDataPrefetchPass());
   addPass(createAtomicExpandPass());
 
   TargetPassConfig::addIRPasses();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146600.507953.patch
Type: text/x-patch
Size: 2861 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230324/fcebf74a/attachment.bin>


More information about the llvm-commits mailing list