Skip to content

[ValueTracking] Make the MaxAnalysisRecursionDepth overridable #137721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 74 additions & 75 deletions llvm/include/llvm/Analysis/ValueTracking.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/WithCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ template <typename Arg> class WithCache {
mutable KnownBits Known;

void calculateKnownBits(const SimplifyQuery &Q) const {
Known = computeKnownBits(Pointer.getPointer(), Q, 0);
Known = computeKnownBits(Pointer.getPointer(), Q);
Pointer.setInt(true);
}

Expand Down
11 changes: 6 additions & 5 deletions llvm/include/llvm/CodeGen/GlobalISel/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "GISelWorkList.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/CodeGen/Register.h"
#include "llvm/CodeGenTypes/LowLevelType.h"
#include "llvm/IR/DebugLoc.h"
Expand Down Expand Up @@ -599,19 +600,19 @@ LLVM_ABI bool canCreatePoison(Register Reg, const MachineRegisterInfo &MRI,
bool ConsiderFlagsAndMetadata = true);

/// Returns true if \p Reg cannot be poison and undef.
LLVM_ABI bool isGuaranteedNotToBeUndefOrPoison(Register Reg,
const MachineRegisterInfo &MRI,
unsigned Depth = 0);
LLVM_ABI bool
isGuaranteedNotToBeUndefOrPoison(Register Reg, const MachineRegisterInfo &MRI,
int Depth = MaxAnalysisRecursionDepth);

/// Returns true if \p Reg cannot be poison, but may be undef.
LLVM_ABI bool isGuaranteedNotToBePoison(Register Reg,
const MachineRegisterInfo &MRI,
unsigned Depth = 0);
int Depth = MaxAnalysisRecursionDepth);

/// Returns true if \p Reg cannot be undef, but may be poison.
LLVM_ABI bool isGuaranteedNotToBeUndef(Register Reg,
const MachineRegisterInfo &MRI,
unsigned Depth = 0);
int Depth = MaxAnalysisRecursionDepth);

/// Get the type back from LLT. It won't be 100 percent accurate but returns an
/// estimate of the type.
Expand Down
26 changes: 13 additions & 13 deletions llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
/// If the inversion will consume instructions, `DoesConsume` will be set to
/// true. Otherwise it will be false.
Value *getFreelyInvertedImpl(Value *V, bool WillInvertAllUses,
BuilderTy *Builder, bool &DoesConsume,
unsigned Depth);
BuilderTy *Builder, bool &DoesConsume,
int Depth);

Value *getFreelyInverted(Value *V, bool WillInvertAllUses,
BuilderTy *Builder, bool &DoesConsume) {
DoesConsume = false;
return getFreelyInvertedImpl(V, WillInvertAllUses, Builder, DoesConsume,
/*Depth*/ 0);
/*Depth*/ MaxAnalysisRecursionDepth);
}

Value *getFreelyInverted(Value *V, bool WillInvertAllUses,
Expand Down Expand Up @@ -431,37 +431,38 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
virtual Instruction *eraseInstFromFunction(Instruction &I) = 0;

void computeKnownBits(const Value *V, KnownBits &Known,
const Instruction *CxtI, unsigned Depth = 0) const {
const Instruction *CxtI,
int Depth = MaxAnalysisRecursionDepth) const {
llvm::computeKnownBits(V, Known, SQ.getWithInstruction(CxtI), Depth);
}

KnownBits computeKnownBits(const Value *V, const Instruction *CxtI,
unsigned Depth = 0) const {
int Depth = MaxAnalysisRecursionDepth) const {
return llvm::computeKnownBits(V, SQ.getWithInstruction(CxtI), Depth);
}

bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero = false,
const Instruction *CxtI = nullptr,
unsigned Depth = 0) {
int Depth = MaxAnalysisRecursionDepth) {
return llvm::isKnownToBeAPowerOfTwo(V, OrZero, SQ.getWithInstruction(CxtI),
Depth);
}

bool MaskedValueIsZero(const Value *V, const APInt &Mask,
const Instruction *CxtI = nullptr,
unsigned Depth = 0) const {
int Depth = MaxAnalysisRecursionDepth) const {
return llvm::MaskedValueIsZero(V, Mask, SQ.getWithInstruction(CxtI), Depth);
}

unsigned ComputeNumSignBits(const Value *Op,
const Instruction *CxtI = nullptr,
unsigned Depth = 0) const {
int Depth = MaxAnalysisRecursionDepth) const {
return llvm::ComputeNumSignBits(Op, DL, &AC, CxtI, &DT, Depth);
}

unsigned ComputeMaxSignificantBits(const Value *Op,
const Instruction *CxtI = nullptr,
unsigned Depth = 0) const {
unsigned
ComputeMaxSignificantBits(const Value *Op, const Instruction *CxtI = nullptr,
int Depth = MaxAnalysisRecursionDepth) const {
return llvm::ComputeMaxSignificantBits(Op, DL, &AC, CxtI, &DT, Depth);
}

Expand Down Expand Up @@ -511,7 +512,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
virtual bool SimplifyDemandedBits(Instruction *I, unsigned OpNo,
const APInt &DemandedMask, KnownBits &Known,
const SimplifyQuery &Q,
unsigned Depth = 0) = 0;
int Depth = MaxAnalysisRecursionDepth) = 0;

bool SimplifyDemandedBits(Instruction *I, unsigned OpNo,
const APInt &DemandedMask, KnownBits &Known) {
Expand All @@ -521,7 +522,6 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {

virtual Value *
SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, APInt &UndefElts,
unsigned Depth = 0,
bool AllowMultipleUsers = false) = 0;

bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const;
Expand Down
Loading