[llvm] 08536b0 - [LAA] refactor tryToCreateDiffCheck (NFC) (#92110)
via llvm-commits
llvm-commits at lists.llvm.org
Tue May 14 08:19:59 PDT 2024
Author: Ramkumar Ramachandra
Date: 2024-05-14T16:19:55+01:00
New Revision: 08536b0f9ccc208ea170b9451026eb1fe1fbb780
URL: https://github.com/llvm/llvm-project/commit/08536b0f9ccc208ea170b9451026eb1fe1fbb780
DIFF: https://github.com/llvm/llvm-project/commit/08536b0f9ccc208ea170b9451026eb1fe1fbb780.diff
LOG: [LAA] refactor tryToCreateDiffCheck (NFC) (#92110)
tryToCreateDiffCheck has one caller, and exits early if CanUseDiffCheck
is false. Hence, we can get/set CanUseDiffCheck in the caller to avoid
wastefully calling tryToCreateDiffCheck. This patch is an NFC
simplification of program logic.
Added:
Modified:
llvm/include/llvm/Analysis/LoopAccessAnalysis.h
llvm/lib/Analysis/LoopAccessAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
index 6ebd0fb8477a0..c22e1d470f380 100644
--- a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
+++ b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h
@@ -540,7 +540,7 @@ class RuntimePointerChecking {
/// Try to create add a new (pointer-
diff erence, access size) pair to
/// DiffCheck for checking groups \p CGI and \p CGJ. If pointer-
diff erence
/// checks cannot be used for the groups, set CanUseDiffCheck to false.
- void tryToCreateDiffCheck(const RuntimeCheckingPtrGroup &CGI,
+ bool tryToCreateDiffCheck(const RuntimeCheckingPtrGroup &CGI,
const RuntimeCheckingPtrGroup &CGJ);
MemoryDepChecker &DC;
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index d071e53324408..e92aa0265a1f2 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -250,18 +250,13 @@ void RuntimePointerChecking::insert(Loop *Lp, Value *Ptr, const SCEV *PtrExpr,
NeedsFreeze);
}
-void RuntimePointerChecking::tryToCreateDiffCheck(
+bool RuntimePointerChecking::tryToCreateDiffCheck(
const RuntimeCheckingPtrGroup &CGI, const RuntimeCheckingPtrGroup &CGJ) {
- if (!CanUseDiffCheck)
- return;
-
// If either group contains multiple
diff erent pointers, bail out.
// TODO: Support multiple pointers by using the minimum or maximum pointer,
// depending on src & sink.
- if (CGI.Members.size() != 1 || CGJ.Members.size() != 1) {
- CanUseDiffCheck = false;
- return;
- }
+ if (CGI.Members.size() != 1 || CGJ.Members.size() != 1)
+ return false;
PointerInfo *Src = &Pointers[CGI.Members[0]];
PointerInfo *Sink = &Pointers[CGJ.Members[0]];
@@ -269,10 +264,8 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
// If either pointer is read and written, multiple checks may be needed. Bail
// out.
if (!DC.getOrderForAccess(Src->PointerValue, !Src->IsWritePtr).empty() ||
- !DC.getOrderForAccess(Sink->PointerValue, !Sink->IsWritePtr).empty()) {
- CanUseDiffCheck = false;
- return;
- }
+ !DC.getOrderForAccess(Sink->PointerValue, !Sink->IsWritePtr).empty())
+ return false;
ArrayRef<unsigned> AccSrc =
DC.getOrderForAccess(Src->PointerValue, Src->IsWritePtr);
@@ -280,10 +273,9 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
DC.getOrderForAccess(Sink->PointerValue, Sink->IsWritePtr);
// If either pointer is accessed multiple times, there may not be a clear
// src/sink relation. Bail out for now.
- if (AccSrc.size() != 1 || AccSink.size() != 1) {
- CanUseDiffCheck = false;
- return;
- }
+ if (AccSrc.size() != 1 || AccSink.size() != 1)
+ return false;
+
// If the sink is accessed before src, swap src/sink.
if (AccSink[0] < AccSrc[0])
std::swap(Src, Sink);
@@ -291,10 +283,8 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
auto *SrcAR = dyn_cast<SCEVAddRecExpr>(Src->Expr);
auto *SinkAR = dyn_cast<SCEVAddRecExpr>(Sink->Expr);
if (!SrcAR || !SinkAR || SrcAR->getLoop() != DC.getInnermostLoop() ||
- SinkAR->getLoop() != DC.getInnermostLoop()) {
- CanUseDiffCheck = false;
- return;
- }
+ SinkAR->getLoop() != DC.getInnermostLoop())
+ return false;
SmallVector<Instruction *, 4> SrcInsts =
DC.getInstructionsForAccess(Src->PointerValue, Src->IsWritePtr);
@@ -302,10 +292,9 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
DC.getInstructionsForAccess(Sink->PointerValue, Sink->IsWritePtr);
Type *SrcTy = getLoadStoreType(SrcInsts[0]);
Type *DstTy = getLoadStoreType(SinkInsts[0]);
- if (isa<ScalableVectorType>(SrcTy) || isa<ScalableVectorType>(DstTy)) {
- CanUseDiffCheck = false;
- return;
- }
+ if (isa<ScalableVectorType>(SrcTy) || isa<ScalableVectorType>(DstTy))
+ return false;
+
const DataLayout &DL =
SinkAR->getLoop()->getHeader()->getModule()->getDataLayout();
unsigned AllocSize =
@@ -316,10 +305,8 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
// future.
auto *Step = dyn_cast<SCEVConstant>(SinkAR->getStepRecurrence(*SE));
if (!Step || Step != SrcAR->getStepRecurrence(*SE) ||
- Step->getAPInt().abs() != AllocSize) {
- CanUseDiffCheck = false;
- return;
- }
+ Step->getAPInt().abs() != AllocSize)
+ return false;
IntegerType *IntTy =
IntegerType::get(Src->PointerValue->getContext(),
@@ -332,10 +319,8 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
const SCEV *SinkStartInt = SE->getPtrToIntExpr(SinkAR->getStart(), IntTy);
const SCEV *SrcStartInt = SE->getPtrToIntExpr(SrcAR->getStart(), IntTy);
if (isa<SCEVCouldNotCompute>(SinkStartInt) ||
- isa<SCEVCouldNotCompute>(SrcStartInt)) {
- CanUseDiffCheck = false;
- return;
- }
+ isa<SCEVCouldNotCompute>(SrcStartInt))
+ return false;
const Loop *InnerLoop = SrcAR->getLoop();
// If the start values for both Src and Sink also vary according to an outer
@@ -356,8 +341,7 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
SinkStartAR->getStepRecurrence(*SE)) {
LLVM_DEBUG(dbgs() << "LAA: Not creating
diff runtime check, since these "
"cannot be hoisted out of the outer loop\n");
- CanUseDiffCheck = false;
- return;
+ return false;
}
}
@@ -366,6 +350,7 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
<< "SinkStartInt: " << *SinkStartInt << '\n');
DiffChecks.emplace_back(SrcStartInt, SinkStartInt, AllocSize,
Src->NeedsFreeze || Sink->NeedsFreeze);
+ return true;
}
SmallVector<RuntimePointerCheck, 4> RuntimePointerChecking::generateChecks() {
@@ -377,7 +362,7 @@ SmallVector<RuntimePointerCheck, 4> RuntimePointerChecking::generateChecks() {
const RuntimeCheckingPtrGroup &CGJ = CheckingGroups[J];
if (needsChecking(CGI, CGJ)) {
- tryToCreateDiffCheck(CGI, CGJ);
+ CanUseDiffCheck = CanUseDiffCheck && tryToCreateDiffCheck(CGI, CGJ);
Checks.push_back(std::make_pair(&CGI, &CGJ));
}
}
More information about the llvm-commits
mailing list