[llvm] ce44357 - Analysis: Add AssumptionCache to isSafeToSpeculativelyExecute
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 19 16:25:31 PDT 2022
Author: Matt Arsenault
Date: 2022-09-19T19:25:22-04:00
New Revision: ce44357216ecb764b9613535abb72167a53f6faa
URL: https://github.com/llvm/llvm-project/commit/ce44357216ecb764b9613535abb72167a53f6faa
DIFF: https://github.com/llvm/llvm-project/commit/ce44357216ecb764b9613535abb72167a53f6faa.diff
LOG: Analysis: Add AssumptionCache to isSafeToSpeculativelyExecute
Does not update any of the uses.
Added:
Modified:
llvm/include/llvm/Analysis/ValueTracking.h
llvm/lib/Analysis/ValueTracking.cpp
llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/lib/Transforms/Scalar/GuardWidening.cpp
llvm/lib/Transforms/Scalar/LICM.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h
index 249e3601ce17..edc7522eb900 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -452,6 +452,7 @@ bool mustSuppressSpeculation(const LoadInst &LI);
/// for such instructions, moving them may change the resulting value.
bool isSafeToSpeculativelyExecute(const Instruction *I,
const Instruction *CtxI = nullptr,
+ AssumptionCache *AC = nullptr,
const DominatorTree *DT = nullptr,
const TargetLibraryInfo *TLI = nullptr);
@@ -474,7 +475,8 @@ bool isSafeToSpeculativelyExecute(const Instruction *I,
/// intentional.
bool isSafeToSpeculativelyExecuteWithOpcode(
unsigned Opcode, const Instruction *Inst, const Instruction *CtxI = nullptr,
- const DominatorTree *DT = nullptr, const TargetLibraryInfo *TLI = nullptr);
+ AssumptionCache *AC = nullptr, const DominatorTree *DT = nullptr,
+ const TargetLibraryInfo *TLI = nullptr);
/// Returns true if the result or effects of the given instructions \p I
/// depend values not reachable through the def use graph.
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 7c0e0e641db5..3826b47b105a 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4718,15 +4718,17 @@ bool llvm::mustSuppressSpeculation(const LoadInst &LI) {
bool llvm::isSafeToSpeculativelyExecute(const Instruction *Inst,
const Instruction *CtxI,
+ AssumptionCache *AC,
const DominatorTree *DT,
const TargetLibraryInfo *TLI) {
return isSafeToSpeculativelyExecuteWithOpcode(Inst->getOpcode(), Inst, CtxI,
- DT, TLI);
+ AC, DT, TLI);
}
bool llvm::isSafeToSpeculativelyExecuteWithOpcode(
unsigned Opcode, const Instruction *Inst, const Instruction *CtxI,
- const DominatorTree *DT, const TargetLibraryInfo *TLI) {
+ AssumptionCache *AC, const DominatorTree *DT,
+ const TargetLibraryInfo *TLI) {
#ifndef NDEBUG
if (Inst->getOpcode() != Opcode) {
// Check that the operands are actually compatible with the Opcode override.
@@ -4784,10 +4786,9 @@ bool llvm::isSafeToSpeculativelyExecuteWithOpcode(
if (mustSuppressSpeculation(*LI))
return false;
const DataLayout &DL = LI->getModule()->getDataLayout();
- return isDereferenceableAndAlignedPointer(
- LI->getPointerOperand(), LI->getType(), LI->getAlign(), DL, CtxI,
- nullptr, // FIXME
- DT, TLI);
+ return isDereferenceableAndAlignedPointer(LI->getPointerOperand(),
+ LI->getType(), LI->getAlign(), DL,
+ CtxI, AC, DT, TLI);
}
case Instruction::Call: {
auto *CI = dyn_cast<const CallInst>(Inst);
diff --git a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
index 3497654bcc30..f20c1684bed3 100644
--- a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
@@ -462,7 +462,7 @@ static bool isHoistableInstructionType(Instruction *I) {
static bool isHoistable(Instruction *I, DominatorTree &DT) {
if (!isHoistableInstructionType(I))
return false;
- return isSafeToSpeculativelyExecute(I, nullptr, &DT);
+ return isSafeToSpeculativelyExecute(I, nullptr, nullptr, &DT);
}
// Recursively traverse the use-def chains of the given value and return a set
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index f1338235a44e..a8d298476abe 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -1533,10 +1533,12 @@ bool GVNPass::PerformLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
// to speculatively execute the load at that points.
if (MustEnsureSafetyOfSpeculativeExecution) {
if (CriticalEdgePred.size())
- if (!isSafeToSpeculativelyExecute(Load, LoadBB->getFirstNonPHI(), DT))
+ if (!isSafeToSpeculativelyExecute(Load, LoadBB->getFirstNonPHI(), nullptr,
+ DT))
return false;
for (auto &PL : PredLoads)
- if (!isSafeToSpeculativelyExecute(Load, PL.first->getTerminator(), DT))
+ if (!isSafeToSpeculativelyExecute(Load, PL.first->getTerminator(),
+ nullptr, DT))
return false;
}
diff --git a/llvm/lib/Transforms/Scalar/GuardWidening.cpp b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
index af6062d142f0..912f155db187 100644
--- a/llvm/lib/Transforms/Scalar/GuardWidening.cpp
+++ b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
@@ -93,7 +93,7 @@ static Value *getCondition(Instruction *I) {
}
// Set the condition for \p I to \p NewCond. \p I can either be a guard or a
-// conditional branch.
+// conditional branch.
static void setCondition(Instruction *I, Value *NewCond) {
if (IntrinsicInst *GI = dyn_cast<IntrinsicInst>(I)) {
assert(GI->getIntrinsicID() == Intrinsic::experimental_guard &&
@@ -261,7 +261,7 @@ class GuardWideningImpl {
void widenGuard(Instruction *ToWiden, Value *NewCondition,
bool InvertCondition) {
Value *Result;
-
+
widenCondCommon(getCondition(ToWiden), NewCondition, ToWiden, Result,
InvertCondition);
if (isGuardAsWidenableBranch(ToWiden)) {
@@ -468,7 +468,7 @@ bool GuardWideningImpl::isAvailableAt(
if (!Inst || DT.dominates(Inst, Loc) || Visited.count(Inst))
return true;
- if (!isSafeToSpeculativelyExecute(Inst, Loc, &DT) ||
+ if (!isSafeToSpeculativelyExecute(Inst, Loc, nullptr, &DT) ||
Inst->mayReadFromMemory())
return false;
@@ -488,7 +488,7 @@ void GuardWideningImpl::makeAvailableAt(Value *V, Instruction *Loc) const {
if (!Inst || DT.dominates(Inst, Loc))
return;
- assert(isSafeToSpeculativelyExecute(Inst, Loc, &DT) &&
+ assert(isSafeToSpeculativelyExecute(Inst, Loc, nullptr, &DT) &&
!Inst->mayReadFromMemory() && "Should've checked with isAvailableAt!");
for (Value *Op : Inst->operands())
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index cdfdfbd4ffe8..9e03bf343b3f 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -1736,7 +1736,8 @@ static bool isSafeToExecuteUnconditionally(
const Loop *CurLoop, const LoopSafetyInfo *SafetyInfo,
OptimizationRemarkEmitter *ORE, const Instruction *CtxI,
bool AllowSpeculation) {
- if (AllowSpeculation && isSafeToSpeculativelyExecute(&Inst, CtxI, DT, TLI))
+ if (AllowSpeculation &&
+ isSafeToSpeculativelyExecute(&Inst, CtxI, nullptr, DT, TLI))
return true;
bool GuaranteedToExecute =
More information about the llvm-commits
mailing list