From 18645d6f239a8d2e04f695df7f966f22991af35c Mon Sep 17 00:00:00 2001 From: Yangguang Li Date: Mon, 18 Aug 2025 17:37:10 +0800 Subject: [PATCH] [LoopDataPrefetch] Add unified option to control crc hash prefetch --- llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp b/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp index dde7de406c58..a8ff70d9fd64 100644 --- a/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp @@ -105,6 +105,11 @@ static cl::opt cl::desc("Least loop depth to insert prefetch"), cl::Hidden, cl::init(1)); +static cl::opt + EnableCrcHashPrefetch("enable-crc-hash-prefetch", cl::Hidden, + cl::init(false), + cl::desc("Enable crc hash load prefetch")); + STATISTIC(NumPrefetches, "Number of prefetches inserted"); STATISTIC(NumIndPrefetches, "Number of indirect prefetches inserted"); STATISTIC(NumOuterLoopPrefetches, "Number of outer loop prefetches inserted"); @@ -551,7 +556,7 @@ bool LoopDataPrefetch::insertPrefetcherForIndirectLoad( Module *M = TargetIndirectLoad->getModule(); Type *I32Ty = Type::getInt32Ty(TargetIndirectLoad->getParent()->getContext()); - if (RandomAccessPrefetchOnly) { + if (RandomAccessPrefetchOnly || EnableCrcHashPrefetch) { bool isRandomAccess = false; for (auto *I : DependentInsts) { if (isCrcHashDataAccess(I, TargetIndirectLoad)) { @@ -813,7 +818,7 @@ bool LoopDataPrefetch::findCandidateMemoryLoads( break; } case Instruction::Call: { - if (PrefetchInOuterLoop || RandomAccessPrefetchOnly) { + if (PrefetchInOuterLoop || RandomAccessPrefetchOnly || EnableCrcHashPrefetch) { if (OperandInst->mayReadOrWriteMemory()) return false; CallInst *Call = dyn_cast(OperandInst); @@ -1538,7 +1543,7 @@ bool LoopDataPrefetch::runOnLoop(Loop *L) { bool IsInnerMost = true; // Prefetch outer loop if needed. if (!L->isInnermost()) { - if (OuterLoopPrefetch) + if (OuterLoopPrefetch || EnableCrcHashPrefetch) IsInnerMost = false; else return MadeChange; @@ -1666,7 +1671,7 @@ bool LoopDataPrefetch::runOnLoop(Loop *L) { } } } - if (!DupPref && !DisableDirectLoadPrefetch) + if (!DupPref && !(DisableDirectLoadPrefetch || EnableCrcHashPrefetch)) Prefetches.push_back(Prefetch(LSCEVAddRec, MemI)); } } @@ -1727,7 +1732,7 @@ bool LoopDataPrefetch::runOnLoop(Loop *L) { MadeChange = true; } - if (!IndirectLoadPrefetch) + if (!IndirectLoadPrefetch && !EnableCrcHashPrefetch) return MadeChange; // List of valid phi nodes that indirect loads can depend on. @@ -1758,7 +1763,7 @@ bool LoopDataPrefetch::runOnLoop(Loop *L) { return MadeChange; } - if (!RandomAccessPrefetchOnly && !PrefetchInOuterLoop && + if (!EnableCrcHashPrefetch && !RandomAccessPrefetchOnly && !PrefetchInOuterLoop && !canDoIndirectPrefetch(L)) { cleanLoopIterationNumber(NumIterations); return MadeChange; -- Gitee