[llvm] 1167414 - [LoongArch] Enable LoopDataPrefetch pass
Xiaodong Liu via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 23 20:10:38 PDT 2023
Author: Xiaodong Liu
Date: 2023-03-24T11:09:18+08:00
New Revision: 11674147e40699202132440313032528dfbf624f
URL: https://github.com/llvm/llvm-project/commit/11674147e40699202132440313032528dfbf624f
DIFF: https://github.com/llvm/llvm-project/commit/11674147e40699202132440313032528dfbf624f.diff
LOG: [LoongArch] Enable LoopDataPrefetch pass
Keep `EnableLoopDataPrefetch` option off for now because
we need a few more TTIs and ISels.
This patch is inspired by http://reviews.llvm.org/D17943.
Reviewed By: SixWeining
Differential Revision: https://reviews.llvm.org/D146600
Added:
llvm/test/Transforms/LoopDataPrefetch/LoongArch/basic.ll
llvm/test/Transforms/LoopDataPrefetch/LoongArch/lit.local.cfg
Modified:
llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
index 933ba3b40ce40..504019c2a09e8 100644
--- a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
+++ b/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 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeLoongArchTarget() {
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 @@ LoongArchTargetMachine::createPassConfig(PassManagerBase &PM) {
}
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();
diff --git a/llvm/test/Transforms/LoopDataPrefetch/LoongArch/basic.ll b/llvm/test/Transforms/LoopDataPrefetch/LoongArch/basic.ll
new file mode 100644
index 0000000000000..55a2a2970d2d7
--- /dev/null
+++ b/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
+}
diff --git a/llvm/test/Transforms/LoopDataPrefetch/LoongArch/lit.local.cfg b/llvm/test/Transforms/LoopDataPrefetch/LoongArch/lit.local.cfg
new file mode 100644
index 0000000000000..2b5a4893e686f
--- /dev/null
+++ b/llvm/test/Transforms/LoopDataPrefetch/LoongArch/lit.local.cfg
@@ -0,0 +1,2 @@
+if not 'LoongArch' in config.root.targets:
+ config.unsupported = True
More information about the llvm-commits
mailing list