Skip to content

Commit

Permalink
[LVI] Remove unnecessary TLI dependency
Browse files Browse the repository at this point in the history
Only used in ConstantFoldCompareInstOperands(), which does not
actually use TLI.
  • Loading branch information
nikic committed Dec 19, 2023
1 parent 9519e3e commit 0d3d445
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
9 changes: 3 additions & 6 deletions llvm/include/llvm/Analysis/LazyValueInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace llvm {
friend class LazyValueInfoWrapperPass;
AssumptionCache *AC = nullptr;
const DataLayout *DL = nullptr;
class TargetLibraryInfo *TLI = nullptr;
LazyValueInfoImpl *PImpl = nullptr;
LazyValueInfo(const LazyValueInfo &) = delete;
void operator=(const LazyValueInfo &) = delete;
Expand All @@ -43,18 +42,16 @@ namespace llvm {
public:
~LazyValueInfo();
LazyValueInfo() = default;
LazyValueInfo(AssumptionCache *AC_, const DataLayout *DL_,
TargetLibraryInfo *TLI_)
: AC(AC_), DL(DL_), TLI(TLI_) {}
LazyValueInfo(AssumptionCache *AC_, const DataLayout *DL_)
: AC(AC_), DL(DL_) {}
LazyValueInfo(LazyValueInfo &&Arg)
: AC(Arg.AC), DL(Arg.DL), TLI(Arg.TLI), PImpl(Arg.PImpl) {
: AC(Arg.AC), DL(Arg.DL), PImpl(Arg.PImpl) {
Arg.PImpl = nullptr;
}
LazyValueInfo &operator=(LazyValueInfo &&Arg) {
releaseMemory();
AC = Arg.AC;
DL = Arg.DL;
TLI = Arg.TLI;
PImpl = Arg.PImpl;
Arg.PImpl = nullptr;
return *this;
Expand Down
18 changes: 7 additions & 11 deletions llvm/lib/Analysis/LazyValueInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,6 @@ void LazyValueInfoImpl::threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc,

bool LazyValueInfoWrapperPass::runOnFunction(Function &F) {
Info.AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
Info.TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);

if (auto *Impl = Info.getImpl())
Impl->clear();
Expand Down Expand Up @@ -1627,9 +1626,8 @@ void LazyValueInfoWrapperPass::releaseMemory() { Info.releaseMemory(); }
LazyValueInfo LazyValueAnalysis::run(Function &F,
FunctionAnalysisManager &FAM) {
auto &AC = FAM.getResult<AssumptionAnalysis>(F);
auto &TLI = FAM.getResult<TargetLibraryAnalysis>(F);

return LazyValueInfo(&AC, &F.getParent()->getDataLayout(), &TLI);
return LazyValueInfo(&AC, &F.getParent()->getDataLayout());
}

/// Returns true if we can statically tell that this value will never be a
Expand Down Expand Up @@ -1714,11 +1712,11 @@ ConstantRange LazyValueInfo::getConstantRangeOnEdge(Value *V,

static LazyValueInfo::Tristate
getPredicateResult(unsigned Pred, Constant *C, const ValueLatticeElement &Val,
const DataLayout &DL, TargetLibraryInfo *TLI) {
const DataLayout &DL) {
// If we know the value is a constant, evaluate the conditional.
Constant *Res = nullptr;
if (Val.isConstant()) {
Res = ConstantFoldCompareInstOperands(Pred, Val.getConstant(), C, DL, TLI);
Res = ConstantFoldCompareInstOperands(Pred, Val.getConstant(), C, DL);
if (ConstantInt *ResCI = dyn_cast_or_null<ConstantInt>(Res))
return ResCI->isZero() ? LazyValueInfo::False : LazyValueInfo::True;
return LazyValueInfo::Unknown;
Expand Down Expand Up @@ -1759,15 +1757,13 @@ getPredicateResult(unsigned Pred, Constant *C, const ValueLatticeElement &Val,
if (Pred == ICmpInst::ICMP_EQ) {
// !C1 == C -> false iff C1 == C.
Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE,
Val.getNotConstant(), C, DL,
TLI);
Val.getNotConstant(), C, DL);
if (Res && Res->isNullValue())
return LazyValueInfo::False;
} else if (Pred == ICmpInst::ICMP_NE) {
// !C1 != C -> true iff C1 == C.
Res = ConstantFoldCompareInstOperands(ICmpInst::ICMP_NE,
Val.getNotConstant(), C, DL,
TLI);
Val.getNotConstant(), C, DL);
if (Res && Res->isNullValue())
return LazyValueInfo::True;
}
Expand All @@ -1787,7 +1783,7 @@ LazyValueInfo::getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
ValueLatticeElement Result =
getOrCreateImpl(M).getValueOnEdge(V, FromBB, ToBB, CxtI);

return getPredicateResult(Pred, C, Result, M->getDataLayout(), TLI);
return getPredicateResult(Pred, C, Result, M->getDataLayout());
}

LazyValueInfo::Tristate
Expand All @@ -1811,7 +1807,7 @@ LazyValueInfo::getPredicateAt(unsigned Pred, Value *V, Constant *C,
ValueLatticeElement Result =
UseBlockValue ? Impl.getValueInBlock(V, CxtI->getParent(), CxtI)
: Impl.getValueAt(V, CxtI);
Tristate Ret = getPredicateResult(Pred, C, Result, DL, TLI);
Tristate Ret = getPredicateResult(Pred, C, Result, DL);
if (Ret != Unknown)
return Ret;

Expand Down

0 comments on commit 0d3d445

Please sign in to comment.