LLVM  3.7.0
Macros | Functions
DAGCombiner.cpp File Reference
#include "llvm/CodeGen/SelectionDAG.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetLowering.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/TargetSubtargetInfo.h"
#include <algorithm>
Include dependency graph for DAGCombiner.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "dagcombine"
 

Functions

 STATISTIC (NodesCombined,"Number of dag nodes combined")
 
 STATISTIC (PreIndexedNodes,"Number of pre-indexed nodes created")
 
 STATISTIC (PostIndexedNodes,"Number of post-indexed nodes created")
 
 STATISTIC (OpsNarrowed,"Number of load/op/store narrowed")
 
 STATISTIC (LdStFP2Int,"Number of fp load/store pairs transformed to int")
 
 STATISTIC (SlicedLoads,"Number of load sliced")
 
static char isNegatibleForFree (SDValue Op, bool LegalOperations, const TargetLowering &TLI, const TargetOptions *Options, unsigned Depth=0)
 Return 1 if we can compute the negated form of the specified expression for the same cost as the expression itself, or 2 if we can compute the negated form more cheaply than the expression itself. More...
 
static SDValue GetNegatedExpression (SDValue Op, SelectionDAG &DAG, bool LegalOperations, unsigned Depth=0)
 If isNegatibleForFree returns true, return the newly negated expression. More...
 
static bool isConstantSplatVector (SDNode *N, APInt &SplatValue)
 Returns true if N is a BUILD_VECTOR node whose elements are all the same constant or undefined. More...
 
static SDNodeisConstantIntBuildVectorOrConstantInt (SDValue N)
 
static SDNodeisConstantFPBuildVectorOrConstantFP (SDValue N)
 
static ConstantSDNodeisConstOrConstSplat (SDValue N)
 
static ConstantFPSDNodeisConstOrConstSplatFP (SDValue N)
 
static SDValue getInputChainForNode (SDNode *N)
 Given a node, return its input chain if it has one, otherwise return a null sd operand. More...
 
static bool isNullConstant (SDValue V)
 
static bool isNullFPConstant (SDValue V)
 
static bool isAllOnesConstant (SDValue V)
 
static bool isOneConstant (SDValue V)
 
static ConstantSDNodegetAsNonOpaqueConstant (SDValue N)
 If N is a ContantSDNode with isOpaque() == false return it casted to a ContantSDNode pointer else nullptr. More...
 
static SDValue tryFoldToZero (SDLoc DL, const TargetLowering &TLI, EVT VT, SelectionDAG &DAG, bool LegalOperations, bool LegalTypes)
 
static bool isBSwapHWordElement (SDValue N, MutableArrayRef< SDNode * > Parts)
 Return true if the specified node is an element that makes up a 32-bit packed halfword byteswap. More...
 
static bool MatchRotateHalf (SDValue Op, SDValue &Shift, SDValue &Mask)
 Match "(X shl/srl V1) & V2" where V2 may not be present. More...
 
static bool matchRotateSub (SDValue Pos, SDValue Neg, unsigned OpSize)
 
static SDValue combineMinNumMaxNum (SDLoc DL, EVT VT, SDValue LHS, SDValue RHS, SDValue True, SDValue False, ISD::CondCode CC, const TargetLowering &TLI, SelectionDAG &DAG)
 Generate Min/Max node. More...
 
static std::pair< SDValue,
SDValue
SplitVSETCC (const SDNode *N, SelectionDAG &DAG)
 
static SDValue ConvertSelectToConcatVector (SDNode *N, SelectionDAG &DAG)
 
static SDNodetryToFoldExtendOfConstant (SDNode *N, const TargetLowering &TLI, SelectionDAG &DAG, bool LegalTypes, bool LegalOperations)
 Try to fold a sext/zext/aext dag node into a ConstantSDNode or a build_vector of constants. More...
 
static bool ExtendUsesToFormExtLoad (SDNode *N, SDValue N0, unsigned ExtOpc, SmallVectorImpl< SDNode * > &ExtendNodes, const TargetLowering &TLI)
 
static bool isTruncateOf (SelectionDAG &DAG, SDValue N, SDValue &Op, APInt &KnownZero)
 
static SDNodegetBuildPairElt (SDNode *N, unsigned i)
 
static SDValue FoldIntToFPToInt (SDNode *N, SelectionDAG &DAG)
 
static bool canFoldInAddressingMode (SDNode *N, SDNode *Use, SelectionDAG &DAG, const TargetLowering &TLI)
 Return true if 'Use' is a load or a store that uses N as its base pointer and that N may be folded in the load / store addressing mode. More...
 
static bool areUsedBitsDense (const APInt &UsedBits)
 Check that all bits set in UsedBits form a dense region, i.e., UsedBits looks like 0..0 1..1 0..0. More...
 
static bool areSlicesNextToEachOther (const LoadedSlice &First, const LoadedSlice &Second)
 Check whether or not First and Second are next to each other in memory. More...
 
static void adjustCostForPairing (SmallVectorImpl< LoadedSlice > &LoadedSlices, LoadedSlice::Cost &GlobalLSCost)
 Adjust the GlobalLSCost according to the target paring capabilities and the layout of the slices. More...
 
static bool isSlicingProfitable (SmallVectorImpl< LoadedSlice > &LoadedSlices, const APInt &UsedBits, bool ForCodeSize)
 Check the profitability of all involved LoadedSlice. More...
 
static std::pair< unsigned,
unsigned
CheckForMaskedLoad (SDValue V, SDValue Ptr, SDValue Chain)
 Check to see if V is (and load (ptr), imm), where the load is having specific bytes cleared out. More...
 
static SDNodeShrinkLoadReplaceStoreWithStore (const std::pair< unsigned, unsigned > &MaskInfo, SDValue IVal, StoreSDNode *St, DAGCombiner *DC)
 Check to see if IVal is something that provides a value as specified by MaskInfo. More...
 
static bool allowableAlignment (const SelectionDAG &DAG, const TargetLowering &TLI, EVT EVTTy, unsigned AS, unsigned Align)
 
static SDValue combineConcatVectorOfScalars (SDNode *N, SelectionDAG &DAG)
 
static SDValue simplifyShuffleOperandRecursively (SmallBitVector &UsedElements, SDValue V, SelectionDAG &DAG)
 
static SDValue simplifyShuffleOperands (ShuffleVectorSDNode *SVN, SDValue N0, SDValue N1, SelectionDAG &DAG)
 
static SDValue partitionShuffleOfConcats (SDNode *N, SelectionDAG &DAG)
 
static bool FindBaseOffset (SDValue Ptr, SDValue &Base, int64_t &Offset, const GlobalValue *&GV, const void *&CV)
 Return true if base is a frame index, which is known not to alias with anything but itself. More...
 

Macro Definition Documentation

#define DEBUG_TYPE   "dagcombine"

Definition at line 43 of file DAGCombiner.cpp.

Function Documentation

static void adjustCostForPairing ( SmallVectorImpl< LoadedSlice > &  LoadedSlices,
LoadedSlice::Cost &  GlobalLSCost 
)
static

Adjust the GlobalLSCost according to the target paring capabilities and the layout of the slices.

Precondition
GlobalLSCost should account for at least as many loads as there is in the slices in LoadedSlices.

Definition at line 10016 of file DAGCombiner.cpp.

References areSlicesNextToEachOther(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::SmallVectorTemplateCommon< T >::end(), and llvm::SmallVectorTemplateCommon< T >::size().

Referenced by isSlicingProfitable().

static bool allowableAlignment ( const SelectionDAG DAG,
const TargetLowering TLI,
EVT  EVTTy,
unsigned  AS,
unsigned  Align 
)
static
static bool areSlicesNextToEachOther ( const LoadedSlice &  First,
const LoadedSlice &  Second 
)
static

Check whether or not First and Second are next to each other in memory.

This means that there is no hole between the bits loaded by First and the bits loaded by Second.

Definition at line 10001 of file DAGCombiner.cpp.

References areUsedBitsDense().

Referenced by adjustCostForPairing().

static bool areUsedBitsDense ( const APInt UsedBits)
static

Check that all bits set in UsedBits form a dense region, i.e., UsedBits looks like 0..0 1..1 0..0.

Definition at line 9984 of file DAGCombiner.cpp.

References llvm::APInt::countLeadingZeros(), llvm::APInt::countTrailingZeros(), llvm::APInt::getActiveBits(), llvm::APInt::isAllOnesValue(), llvm::APInt::lshr(), and llvm::APInt::trunc().

Referenced by areSlicesNextToEachOther(), and isSlicingProfitable().

static bool canFoldInAddressingMode ( SDNode N,
SDNode Use,
SelectionDAG DAG,
const TargetLowering TLI 
)
static
static std::pair<unsigned, unsigned> CheckForMaskedLoad ( SDValue  V,
SDValue  Ptr,
SDValue  Chain 
)
static
static SDValue combineConcatVectorOfScalars ( SDNode N,
SelectionDAG DAG 
)
static
static SDValue combineMinNumMaxNum ( SDLoc  DL,
EVT  VT,
SDValue  LHS,
SDValue  RHS,
SDValue  True,
SDValue  False,
ISD::CondCode  CC,
const TargetLowering TLI,
SelectionDAG DAG 
)
static
static SDValue ConvertSelectToConcatVector ( SDNode N,
SelectionDAG DAG 
)
static
static bool ExtendUsesToFormExtLoad ( SDNode N,
SDValue  N0,
unsigned  ExtOpc,
SmallVectorImpl< SDNode * > &  ExtendNodes,
const TargetLowering TLI 
)
static
static bool FindBaseOffset ( SDValue  Ptr,
SDValue Base,
int64_t &  Offset,
const GlobalValue *&  GV,
const void *&  CV 
)
static

Return true if base is a frame index, which is known not to alias with anything but itself.

Provides base object and offset as results.

Definition at line 13804 of file DAGCombiner.cpp.

References llvm::ISD::ADD, G, llvm::SDValue::getOpcode(), llvm::SDValue::getOperand(), and llvm::ConstantSDNode::getZExtValue().

static SDValue FoldIntToFPToInt ( SDNode N,
SelectionDAG DAG 
)
static
static ConstantSDNode* getAsNonOpaqueConstant ( SDValue  N)
static

If N is a ContantSDNode with isOpaque() == false return it casted to a ContantSDNode pointer else nullptr.

Definition at line 1620 of file DAGCombiner.cpp.

References llvm::dyn_cast(), llvm::ConstantSDNode::isOpaque(), and N.

static SDNode* getBuildPairElt ( SDNode N,
unsigned  i 
)
static
static SDValue getInputChainForNode ( SDNode N)
static

Given a node, return its input chain if it has one, otherwise return a null sd operand.

Definition at line 1490 of file DAGCombiner.cpp.

References llvm::SDNode::getNumOperands(), llvm::SDNode::getOperand(), llvm::SDValue::getValueType(), and llvm::MVT::Other.

static SDValue GetNegatedExpression ( SDValue  Op,
SelectionDAG DAG,
bool  LegalOperations,
unsigned  Depth = 0 
)
static
static bool isAllOnesConstant ( SDValue  V)
static

Definition at line 1608 of file DAGCombiner.cpp.

References llvm::dyn_cast(), and llvm::ConstantSDNode::isAllOnesValue().

static bool isBSwapHWordElement ( SDValue  N,
MutableArrayRef< SDNode * >  Parts 
)
static

Return true if the specified node is an element that makes up a 32-bit packed halfword byteswap.

((x & 0x000000ff) << 8) | ((x & 0x0000ff00) >> 8) | ((x & 0x00ff0000) << 8) | ((x & 0xff000000) >> 8)

Definition at line 3320 of file DAGCombiner.cpp.

References llvm::ISD::AND, llvm::C, llvm::dyn_cast(), llvm::SDValue::getNode(), llvm::SDValue::getOpcode(), llvm::SDValue::getOperand(), llvm::ConstantSDNode::getZExtValue(), llvm::SDNode::hasOneUse(), llvm::ISD::SHL, and llvm::ISD::SRL.

static SDNode* isConstantFPBuildVectorOrConstantFP ( SDValue  N)
static
static SDNode* isConstantIntBuildVectorOrConstantInt ( SDValue  N)
static
static bool isConstantSplatVector ( SDNode N,
APInt SplatValue 
)
static

Returns true if N is a BUILD_VECTOR node whose elements are all the same constant or undefined.

Definition at line 717 of file DAGCombiner.cpp.

References llvm::C, llvm::dyn_cast(), llvm::EVT::getSizeInBits(), llvm::SDNode::getValueType(), llvm::EVT::getVectorElementType(), llvm::BuildVectorSDNode::isConstantSplat(), and N.

static ConstantSDNode* isConstOrConstSplat ( SDValue  N)
static
static ConstantFPSDNode* isConstOrConstSplatFP ( SDValue  N)
static

Definition at line 774 of file DAGCombiner.cpp.

References llvm::BitVector::none().

static char isNegatibleForFree ( SDValue  Op,
bool  LegalOperations,
const TargetLowering TLI,
const TargetOptions Options,
unsigned  Depth = 0 
)
static

Return 1 if we can compute the negated form of the specified expression for the same cost as the expression itself, or 2 if we can compute the negated form more cheaply than the expression itself.

Definition at line 536 of file DAGCombiner.cpp.

References llvm::ISD::ConstantFP, llvm::ISD::FADD, llvm::ISD::FDIV, llvm::ISD::FMUL, llvm::ISD::FNEG, llvm::ISD::FP_EXTEND, llvm::ISD::FP_ROUND, llvm::ISD::FSIN, llvm::ISD::FSUB, llvm::SDValue::getOpcode(), llvm::SDValue::getOperand(), llvm::SDValue::getValueType(), llvm::SDValue::hasOneUse(), llvm::TargetLoweringBase::isOperationLegalOrCustom(), and llvm::TargetOptions::UnsafeFPMath.

Referenced by GetNegatedExpression().

static bool isNullConstant ( SDValue  V)
static

Definition at line 1598 of file DAGCombiner.cpp.

References llvm::dyn_cast(), and llvm::ConstantSDNode::isNullValue().

Referenced by isTruncateOf().

static bool isNullFPConstant ( SDValue  V)
static
static bool isOneConstant ( SDValue  V)
static

Definition at line 1613 of file DAGCombiner.cpp.

References llvm::dyn_cast(), and llvm::ConstantSDNode::isOne().

static bool isSlicingProfitable ( SmallVectorImpl< LoadedSlice > &  LoadedSlices,
const APInt UsedBits,
bool  ForCodeSize 
)
static

Check the profitability of all involved LoadedSlice.

Currently, it is considered profitable if there is exactly two involved slices (1) which are (2) next to each other in memory, and whose cost (

See Also
LoadedSlice::Cost) is smaller than the original load (3).

Note: The order of the elements in LoadedSlices may be modified, but not the elements themselves.

FIXME: When the cost model will be mature enough, we can relax constraints (1) and (2).

Definition at line 10084 of file DAGCombiner.cpp.

References adjustCostForPairing(), areUsedBitsDense(), and llvm::SmallVectorTemplateCommon< T >::size().

static bool isTruncateOf ( SelectionDAG DAG,
SDValue  N,
SDValue Op,
APInt KnownZero 
)
static
static bool MatchRotateHalf ( SDValue  Op,
SDValue Shift,
SDValue Mask 
)
static

Match "(X shl/srl V1) & V2" where V2 may not be present.

Definition at line 3711 of file DAGCombiner.cpp.

References llvm::ISD::AND, llvm::SDValue::getOpcode(), llvm::SDValue::getOperand(), llvm::ISD::SHL, and llvm::ISD::SRL.

static bool matchRotateSub ( SDValue  Pos,
SDValue  Neg,
unsigned  OpSize 
)
static
static SDValue partitionShuffleOfConcats ( SDNode N,
SelectionDAG DAG 
)
static
static SDNode* ShrinkLoadReplaceStoreWithStore ( const std::pair< unsigned, unsigned > &  MaskInfo,
SDValue  IVal,
StoreSDNode St,
DAGCombiner *  DC 
)
static
static SDValue simplifyShuffleOperandRecursively ( SmallBitVector UsedElements,
SDValue  V,
SelectionDAG DAG 
)
static
static SDValue simplifyShuffleOperands ( ShuffleVectorSDNode SVN,
SDValue  N0,
SDValue  N1,
SelectionDAG DAG 
)
static
static std::pair<SDValue, SDValue> SplitVSETCC ( const SDNode N,
SelectionDAG DAG 
)
static
STATISTIC ( NodesCombined  ,
"Number of dag nodes combined"   
)
STATISTIC ( PreIndexedNodes  ,
"Number of pre-indexed nodes created"   
)
STATISTIC ( PostIndexedNodes  ,
"Number of post-indexed nodes created"   
)
STATISTIC ( OpsNarrowed  ,
"Number of load/op/store narrowed"   
)
STATISTIC ( LdStFP2Int  ,
"Number of fp load/store pairs transformed to int  
)
STATISTIC ( SlicedLoads  ,
"Number of load sliced"   
)
static SDValue tryFoldToZero ( SDLoc  DL,
const TargetLowering TLI,
EVT  VT,
SelectionDAG DAG,
bool  LegalOperations,
bool  LegalTypes 
)
static
static SDNode* tryToFoldExtendOfConstant ( SDNode N,
const TargetLowering TLI,
SelectionDAG DAG,
bool  LegalTypes,
bool  LegalOperations 
)
static