LLVM 20.0.0git
Macros | Functions | Variables
CombinerHelper.cpp File Reference
#include "llvm/CodeGen/GlobalISel/CombinerHelper.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/Analysis/CmpInstAnalysis.h"
#include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
#include "llvm/CodeGen/GlobalISel/GISelKnownBits.h"
#include "llvm/CodeGen/GlobalISel/GenericMachineInstrs.h"
#include "llvm/CodeGen/GlobalISel/LegalizerHelper.h"
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
#include "llvm/CodeGen/GlobalISel/MIPatternMatch.h"
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
#include "llvm/CodeGen/GlobalISel/Utils.h"
#include "llvm/CodeGen/LowLevelTypeUtils.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineMemOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/RegisterBankInfo.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetOpcodes.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/DivisionByConstantInfo.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Target/TargetMachine.h"
#include <cmath>
#include <optional>
#include <tuple>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "gi-combiner"
 

Functions

static unsigned littleEndianByteAt (const unsigned ByteWidth, const unsigned I)
 
static Register buildLogBase2 (Register V, MachineIRBuilder &MIB)
 Determines the LogBase2 value for a non-null input value using the transform: LogBase2(V) = (EltBits - 1) - ctlz(V).
 
static unsigned bigEndianByteAt (const unsigned ByteWidth, const unsigned I)
 
static std::optional< boolisBigEndian (const SmallDenseMap< int64_t, int64_t, 8 > &MemOffset2Idx, int64_t LowestIdx)
 Given a map from byte offsets in memory to indices in a load/store, determine if that map corresponds to a little or big endian byte pattern.
 
static unsigned getExtLoadOpcForExtend (unsigned ExtOpc)
 
static bool canFoldInAddressingMode (GLoadStore *MI, const TargetLowering &TLI, MachineRegisterInfo &MRI)
 Return true if 'MI' is a load or a store that may be fold it's address operand into the load / store addressing mode.
 
static unsigned getIndexedOpc (unsigned LdStOpc)
 
static APFloat constantFoldFpUnary (const MachineInstr &MI, const MachineRegisterInfo &MRI, const APFloat &Val)
 
static Register peekThroughBitcast (Register Reg, const MachineRegisterInfo &MRI)
 
static LLT getMidVTForTruncRightShiftCombine (LLT ShiftTy, LLT TruncTy)
 
static bool isConstValidTrue (const TargetLowering &TLI, unsigned ScalarSizeBits, int64_t Cst, bool IsVector, bool IsFP)
 
static std::optional< std::pair< GZExtLoad *, int64_t > > matchLoadAndBytePosition (Register Reg, unsigned MemSizeInBits, const MachineRegisterInfo &MRI)
 Helper function for findLoadOffsetsForLoadOrCombine.
 
static bool isContractableFMul (MachineInstr &MI, bool AllowFusionGlobally)
 Checks if MI is TargetOpcode::G_FMUL and contractable either due to global flags or MachineInstr flags.
 
static bool hasMoreUses (const MachineInstr &MI0, const MachineInstr &MI1, const MachineRegisterInfo &MRI)
 

Variables

static cl::opt< boolForceLegalIndexing ("force-legal-indexing", cl::Hidden, cl::init(false), cl::desc("Force all indexed operations to be " "legal for the GlobalISel combiner"))
 
static cl::opt< unsignedPostIndexUseThreshold ("post-index-use-threshold", cl::Hidden, cl::init(32), cl::desc("Number of uses of a base pointer to check before it is no longer " "considered for post-indexing."))
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "gi-combiner"

Definition at line 44 of file CombinerHelper.cpp.

Function Documentation

◆ bigEndianByteAt()

static unsigned bigEndianByteAt ( const unsigned  ByteWidth,
const unsigned  I 
)
static
Returns
The big endian in-memory byte position of byte I in a ByteWidth bytes wide type.

E.g. Given a 4-byte type x, x[0] -> byte 3

Definition at line 104 of file CombinerHelper.cpp.

References assert(), and I.

Referenced by isBigEndian(), and llvm::CombinerHelper::matchLoadOrCombine().

◆ buildLogBase2()

static Register buildLogBase2 ( Register  V,
MachineIRBuilder MIB 
)
static

Determines the LogBase2 value for a non-null input value using the transform: LogBase2(V) = (EltBits - 1) - ctlz(V).

Definition at line 92 of file CombinerHelper.cpp.

References llvm::sampleprof::Base, llvm::MachineIRBuilder::buildConstant(), llvm::MachineIRBuilder::buildCTLZ(), llvm::MachineIRBuilder::buildSub(), llvm::MachineIRBuilder::getMRI(), llvm::MachineInstrBuilder::getReg(), llvm::LLT::getScalarSizeInBits(), and MRI.

Referenced by llvm::CombinerHelper::applyUMulHToLShr().

◆ canFoldInAddressingMode()

static bool canFoldInAddressingMode ( GLoadStore MI,
const TargetLowering TLI,
MachineRegisterInfo MRI 
)
static

Return true if 'MI' is a load or a store that may be fold it's address operand into the load / store addressing mode.

Definition at line 1117 of file CombinerHelper.cpp.

References Addr, llvm::TargetLoweringBase::AddrMode::BaseOffs, llvm::getIConstantVRegVal(), llvm::getTypeForLLT(), llvm::TargetLoweringBase::AddrMode::HasBaseReg, llvm::TargetLoweringBase::isLegalAddressingMode(), MI, MRI, and llvm::TargetLoweringBase::AddrMode::Scale.

Referenced by shouldCombineToPostInc().

◆ constantFoldFpUnary()

static APFloat constantFoldFpUnary ( const MachineInstr MI,
const MachineRegisterInfo MRI,
const APFloat Val 
)
static

◆ getExtLoadOpcForExtend()

static unsigned getExtLoadOpcForExtend ( unsigned  ExtOpc)
static

◆ getIndexedOpc()

static unsigned getIndexedOpc ( unsigned  LdStOpc)
static

Definition at line 1138 of file CombinerHelper.cpp.

References llvm_unreachable.

Referenced by llvm::CombinerHelper::applyCombineIndexedLoadStore().

◆ getMidVTForTruncRightShiftCombine()

static LLT getMidVTForTruncRightShiftCombine ( LLT  ShiftTy,
LLT  TruncTy 
)
static

◆ hasMoreUses()

static bool hasMoreUses ( const MachineInstr MI0,
const MachineInstr MI1,
const MachineRegisterInfo MRI 
)
static

◆ isBigEndian()

static std::optional< bool > isBigEndian ( const SmallDenseMap< int64_t, int64_t, 8 > &  MemOffset2Idx,
int64_t  LowestIdx 
)
static

Given a map from byte offsets in memory to indices in a load/store, determine if that map corresponds to a little or big endian byte pattern.

Parameters
MemOffset2Idxmaps memory offsets to address offsets.
LowestIdxis the lowest index in MemOffset2Idx.
Returns
true if the map corresponds to a big endian byte pattern, false if it corresponds to a little endian byte pattern, and std::nullopt otherwise.

E.g. given a 32-bit type x, and x[AddrOffset], the in-memory byte patterns are as follows:

AddrOffset Little endian Big endian 0 0 3 1 1 2 2 2 1 3 3 0

Definition at line 127 of file CombinerHelper.cpp.

References assert(), bigEndianByteAt(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), Idx, littleEndianByteAt(), and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::size().

Referenced by collectInsertionElements(), createGPRPairNode(), llvm::SelectionDAG::getConstant(), llvm::CombinerHelper::matchLoadOrCombine(), PerformSTORECombine(), llvm::LegalizerHelper::reduceLoadStoreWidth(), ReplaceCMP_SWAP_64Results(), and llvm::orc::OrcMips32_Base::writeResolverCode().

◆ isConstValidTrue()

static bool isConstValidTrue ( const TargetLowering TLI,
unsigned  ScalarSizeBits,
int64_t  Cst,
bool  IsVector,
bool  IsFP 
)
static

Definition at line 3363 of file CombinerHelper.cpp.

References llvm::isConstTrueVal().

Referenced by llvm::CombinerHelper::matchNotCmp().

◆ isContractableFMul()

static bool isContractableFMul ( MachineInstr MI,
bool  AllowFusionGlobally 
)
static

◆ littleEndianByteAt()

static unsigned littleEndianByteAt ( const unsigned  ByteWidth,
const unsigned  I 
)
static
Returns
The little endian in-memory byte position of byte I in a ByteWidth bytes wide type.

E.g. Given a 4-byte type x, x[0] -> byte 0

Definition at line 85 of file CombinerHelper.cpp.

References assert(), and I.

Referenced by isBigEndian(), and llvm::CombinerHelper::matchLoadOrCombine().

◆ matchLoadAndBytePosition()

static std::optional< std::pair< GZExtLoad *, int64_t > > matchLoadAndBytePosition ( Register  Reg,
unsigned  MemSizeInBits,
const MachineRegisterInfo MRI 
)
static

Helper function for findLoadOffsetsForLoadOrCombine.

Check if Reg is the result of loading a MemSizeInBits wide value, and then moving that value into a specific byte offset.

e.g. x[i] << 24

Returns
The load instruction and the byte offset it is moved into.

Definition at line 3724 of file CombinerHelper.cpp.

References assert(), llvm::MIPatternMatch::m_GShl(), llvm::MIPatternMatch::m_ICst(), llvm::MIPatternMatch::m_OneNonDBGUse(), llvm::MIPatternMatch::m_Reg(), llvm::MIPatternMatch::mi_match(), and MRI.

◆ peekThroughBitcast()

static Register peekThroughBitcast ( Register  Reg,
const MachineRegisterInfo MRI 
)
static

Variable Documentation

◆ ForceLegalIndexing

cl::opt< bool > ForceLegalIndexing("force-legal-indexing", cl::Hidden, cl::init(false), cl::desc("Force all indexed operations to be " "legal for the GlobalISel combiner")) ( "force-legal-indexing"  ,
cl::Hidden  ,
cl::init(false)  ,
cl::desc("Force all indexed operations to be " "legal for the GlobalISel combiner")   
)
static

◆ PostIndexUseThreshold

cl::opt< unsigned > PostIndexUseThreshold("post-index-use-threshold", cl::Hidden, cl::init(32), cl::desc("Number of uses of a base pointer to check before it is no longer " "considered for post-indexing.")) ( "post-index-use-threshold"  ,
cl::Hidden  ,
cl::init(32)  ,
cl::desc("Number of uses of a base pointer to check before it is no longer " "considered for post-indexing.")   
)
static