21 #define DEBUG_TYPE "gisel-known-bits" 28 "Analysis for ComputingKnownBits",
false,
true)
33 : MF(MF),
MRI(MF.getRegInfo()), TL(*MF.getSubtarget().getTargetLowering()),
44 if (MI.
getOpcode() == TargetOpcode::G_FRAME_INDEX) {
52 const APInt &DemandedElts,
91 const APInt &DemandedElts,
125 case TargetOpcode::COPY: {
142 case TargetOpcode::G_CONSTANT: {
150 case TargetOpcode::G_FRAME_INDEX: {
154 case TargetOpcode::G_SUB: {
161 if (KnownZeroLow == 0)
169 case TargetOpcode::G_XOR: {
179 Known.
Zero = KnownZeroOut;
182 case TargetOpcode::G_PTR_ADD: {
189 case TargetOpcode::G_ADD: {
206 if (KnownZeroHigh > 1)
210 case TargetOpcode::G_AND: {
223 case TargetOpcode::G_OR: {
236 case TargetOpcode::G_MUL: {
257 case TargetOpcode::G_SELECT: {
270 case TargetOpcode::G_FCMP:
271 case TargetOpcode::G_ICMP: {
273 Opcode == TargetOpcode::G_FCMP) ==
279 case TargetOpcode::G_SEXT: {
284 Known = Known.
sext(BitWidth);
287 case TargetOpcode::G_ANYEXT: {
290 Known = Known.
zext(BitWidth,
true );
293 case TargetOpcode::G_LOAD: {
302 case TargetOpcode::G_ZEXTLOAD: {
308 case TargetOpcode::G_ASHR:
309 case TargetOpcode::G_LSHR:
310 case TargetOpcode::G_SHL: {
317 dbgs() <<
'[' << Depth <<
"] Shift not known constant: " << *RHSMI);
321 LLVM_DEBUG(
dbgs() <<
'[' << Depth <<
"] Shift is " << Shift <<
'\n');
327 case TargetOpcode::G_ASHR:
331 case TargetOpcode::G_LSHR:
336 case TargetOpcode::G_SHL:
344 case TargetOpcode::G_INTTOPTR:
345 case TargetOpcode::G_PTRTOINT:
348 case TargetOpcode::G_ZEXT:
349 case TargetOpcode::G_TRUNC: {
355 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
359 if (BitWidth > SrcBitWidth)
366 LLVM_DEBUG(
dbgs() <<
"[" << Depth <<
"] Compute known bits: " << MI <<
"[" 367 << Depth <<
"] Computed for: " << MI <<
"[" << Depth
369 << (Known.
Zero | Known.
One).toString(16,
false) <<
"\n" 370 <<
"[" << Depth <<
"] Zero: 0x" 372 <<
"[" << Depth <<
"] One: 0x" 377 const APInt &DemandedElts,
382 if (Opcode == TargetOpcode::G_CONSTANT)
401 case TargetOpcode::COPY: {
411 case TargetOpcode::G_SEXT: {
417 case TargetOpcode::G_TRUNC: {
425 if (NumSrcSignBits > (NumSrcBits - DstTyBits))
426 return NumSrcSignBits - (NumSrcBits - DstTyBits);
unsigned Log2(Align A)
Returns the log2 of the alignment.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned getIndexSizeInBits(unsigned AS) const
Size in bits of index used for address calculation in getelementptr.
bool maskedValueIsZero(Register Val, const APInt &Mask)
uint64_t getZExtValue() const
Get zero extended value.
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
void setBits(unsigned loBit, unsigned hiBit)
Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
This class represents lattice values for constants.
unsigned getScalarSizeInBits() const
bool hasConflict() const
Returns true if there is conflicting information.
Analysis for ComputingKnownBits
unsigned getSizeInBits(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
unsigned getSubReg() const
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
bool isNonIntegralAddressSpace(unsigned AddrSpace) const
block Block Frequency true
BooleanContent getBooleanContents(bool isVec, bool isFloat) const
For targets without i1 registers, this gives the nature of the high-bits of boolean values held in ty...
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
A description of a memory reference used in the backend.
static MaybeAlign inferPtrAlignment(const MachineInstr &MI)
void setHighBits(unsigned hiBits)
Set the top hiBits bits.
unsigned getMaxDepth() const
APInt shl(unsigned shiftAmt) const
Left-shift function.
const MDNode * getRanges() const
Return the range tag for the memory reference.
unsigned computeNumSignBits(Register R, const APInt &DemandedElts, unsigned Depth=0)
static void computeKnownBitsForAlignment(KnownBits &Known, MaybeAlign Alignment)
#define DEBUG_TYPE
Provides analysis for querying information about KnownBits during GISel passes.
virtual void computeKnownBitsForTargetInstr(GISelKnownBits &Analysis, Register R, KnownBits &Known, const APInt &DemandedElts, const MachineRegisterInfo &MRI, unsigned Depth=0) const
Determine which of the bits specified in Mask are known to be either zero or one and return them in t...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Align commonAlignment(Align A, Align B)
Returns the alignment that satisfies both alignments.
KnownBits zextOrTrunc(unsigned BitWidth, bool ExtendedBitsAreKnownZero) const
Extends or truncates the underlying known Zero and One bits.
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
void computeKnownBitsForFrameIndex(Register R, KnownBits &Known, const APInt &DemandedElts, unsigned Depth=0)
const APInt & getValue() const
Return the constant as an APInt value reference.
INITIALIZE_PASS_BEGIN(GISelKnownBitsAnalysis, DEBUG_TYPE, "Analysis for ComputingKnownBits", false, true) INITIALIZE_PASS_END(GISelKnownBitsAnalysis
bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
static Function * getFunction(Constant *C)
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
To use KnownBitsInfo analysis in a pass, KnownBitsInfo &Info = getAnalysis<GISelKnownBitsInfoAnalysis...
APInt getKnownZeroes(Register R)
bool signBitIsZero(Register Op)
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
unsigned const MachineRegisterInfo * MRI
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
KnownBits zext(unsigned BitWidth, bool ExtendedBitsAreKnownZero) const
Extends the underlying known Zero and One bits.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
void resetAll()
Resets the known state of all bits.
const APInt & getConstant() const
Returns the value when all bits have a known value.
KnownBits getKnownBits(Register R)
Represent the analysis usage information of a pass.
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
bool isConstant() const
Returns true if we know the value of all bits.
static Align inferAlignmentForFrameIdx(int FrameIdx, int Offset, const MachineFunction &MF)
unsigned getAddressSpace() const
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
This struct is a compact representation of a valid (non-zero power of two) alignment.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
APInt getKnownOnes(Register R)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
Align max(MaybeAlign Lhs, Align Rhs)
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
MachineOperand class - Representation of each machine instruction operand.
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
void computeKnownBitsFromRangeMetadata(const MDNode &Ranges, KnownBits &Known)
Compute known bits from the range metadata.
KnownBits sext(unsigned BitWidth) const
Sign extends the underlying known Zero and One bits.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Class for arbitrary precision integers.
void setPreservesAll()
Set by analyses that do not transform their input at all.
Optional< int64_t > getConstantVRegVal(unsigned VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT fits in int64_t returns it.
bool isUnknown() const
Returns true if we don't know any bits.
virtual void computeKnownBitsImpl(Register R, KnownBits &Known, const APInt &DemandedElts, unsigned Depth=0)
Representation of each machine instruction.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit. ...
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
static const Function * getParent(const Value *V)
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
Register getReg() const
getReg - Returns the register number.
for(unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
const MachineOperand & getOperand(unsigned i) const
const ConstantInt * getCImm() const
void toString(SmallVectorImpl< char > &Str, unsigned Radix, bool Signed, bool formatAsCLiteral=false) const
Converts an APInt to a string and append it to Str.
void setLowBits(unsigned loBits)
Set the bottom loBits bits.
Wrapper class representing virtual and physical registers.
This file describes how to lower LLVM code to machine code.