Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
Classes |Namespaces |Macros |Enumerations |Functions |Variables
SimplifyCFG.cpp File Reference
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/SetOperations.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/CaptureTracking.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/DomTreeUpdater.h"
#include "llvm/Analysis/GuardUtils.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/MemorySSA.h"
#include "llvm/Analysis/MemorySSAUpdater.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/MemoryModelRelaxationAnnotations.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/NoFolder.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/ProfDataUtils.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Use.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <map>
#include <optional>
#include <set>
#include <tuple>
#include <utility>
#include <vector>

Go to the source code of this file.

Classes

struct  SwitchSuccWrapper
 Checking whether two cases of SI are equal depends on the contents of the BasicBlock and the incoming values of their successor PHINodes.More...
 
struct  llvm::DenseMapInfo< const SwitchSuccWrapper * >
 

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.
 

Macros

#define DEBUG_TYPE   "simplifycfg"
 

Enumerations

enum  SkipFlags {SkipReadMem = 1,SkipSideEffect = 2,SkipImplicitControlFlow = 4 }
 

Functions

 STATISTIC (NumBitMaps, "Number of switchinstructions turned into bitmaps")
 
 STATISTIC (NumLinearMaps, "Number of switchinstructions turned into linear mapping")
 
 STATISTIC (NumLookupTables, "Number of switchinstructions turned intolookup tables")
 
 STATISTIC (NumLookupTablesHoles, "Number of switchinstructions turned intolookup tables (holes checked)")
 
 STATISTIC (NumTableCmpReuses, "Number of reused switch tablelookup compares")
 
 STATISTIC (NumFoldValueComparisonIntoPredecessors, "Number ofvalue comparisons folded into predecessor basic blocks")
 
 STATISTIC (NumFoldBranchToCommonDest, "Number ofbranches folded into predecessor basic block")
 
 STATISTIC (NumHoistCommonCode, "Number of common instruction 'blocks' hoisted up to the begin block")
 
 STATISTIC (NumHoistCommonInstrs, "Number of commoninstructions hoisted up to the begin block")
 
 STATISTIC (NumSinkCommonCode, "Number of common instruction 'blocks' sunk down to the end block")
 
 STATISTIC (NumSinkCommonInstrs, "Number of commoninstructions sunk down to the end block")
 
 STATISTIC (NumSpeculations, "Number of speculative executed instructions")
 
 STATISTIC (NumInvokes, "Number of invokes with empty resumeblocks simplified into calls")
 
 STATISTIC (NumInvokesMerged, "Number of invokes that were merged together")
 
 STATISTIC (NumInvokeSetsFormed, "Number of invoke sets that were formed")
 
staticbool incomingValuesAreCompatible (BasicBlock *BB,ArrayRef<BasicBlock * > IncomingBlocks,SmallPtrSetImpl<Value * > *EquivalenceSet=nullptr)
 Return true if all the PHI nodes in the basic blockBB receive compatible (identical) incoming values when coming from all of the predecessor blocks that are specified inIncomingBlocks.
 
staticbool safeToMergeTerminators (Instruction *SI1,Instruction *SI2,SmallSetVector<BasicBlock *, 4 > *FailBlocks=nullptr)
 Return true if it is safe to merge these two terminator instructions together.
 
static void addPredecessorToBlock (BasicBlock *Succ,BasicBlock *NewPred,BasicBlock *ExistPred,MemorySSAUpdater *MSSAU=nullptr)
 Update PHI nodes in Succ to indicate that there will now be entries in it from the 'NewPred' block.
 
staticInstructionCost computeSpeculationCost (constUser *I,constTargetTransformInfo &TTI)
 Compute an abstract "cost" of speculating the given instruction, which is assumed to be safe to speculate.
 
staticbool dominatesMergePoint (Value *V,BasicBlock *BB,Instruction *InsertPt,SmallPtrSetImpl<Instruction * > &AggressiveInsts,InstructionCost &Cost,InstructionCost Budget,constTargetTransformInfo &TTI,AssumptionCache *AC,unsigned Depth=0)
 If we have a merge point of an "if condition" as accepted above, return true if the specified value dominates the block.
 
staticConstantIntgetConstantInt (Value *V,constDataLayout &DL)
 Extract ConstantInt from value, looking through IntToPtr and PointerNullValue.
 
static void eraseTerminatorAndDCECond (Instruction *TI,MemorySSAUpdater *MSSAU=nullptr)
 
static void eliminateBlockCases (BasicBlock *BB, std::vector< ValueEqualityComparisonCase > &Cases)
 Given a vector of bb/value pairs, remove any entries in the list that match the specified block.
 
staticbool valuesOverlap (std::vector< ValueEqualityComparisonCase > &C1, std::vector< ValueEqualityComparisonCase > &C2)
 Return true if there are any keys in C1 that exist in C2 as well.
 
static void setBranchWeights (SwitchInst *SI,ArrayRef<uint32_t > Weights,bool IsExpected)
 
static void setBranchWeights (Instruction *I,uint32_t TrueWeight,uint32_t FalseWeight,bool IsExpected)
 
static int constantIntSortPredicate (ConstantInt *const *P1,ConstantInt *const *P2)
 
static void getBranchWeights (Instruction *TI,SmallVectorImpl<uint64_t > &Weights)
 Get Weights of a given terminator, the default weight is at the front of the vector.
 
static void fitWeights (MutableArrayRef<uint64_t > Weights)
 Keep halving the weights until all can fit in uint32_t.
 
static void cloneInstructionsIntoPredecessorBlockAndUpdateSSAUses (BasicBlock *BB,BasicBlock *PredBlock,ValueToValueMapTy &VMap)
 
staticbool isSafeToHoistInvoke (BasicBlock *BB1,BasicBlock *BB2,Instruction *I1,Instruction *I2)
 
staticunsigned skippedInstrFlags (Instruction *I)
 
staticbool isSafeToHoistInstr (Instruction *I,unsigned Flags)
 
staticbool passingValueIsAlwaysUndefined (Value *V,Instruction *I,bool PtrValueMayBeModified)
 Check if passing a value to an instruction will cause undefined behavior.
 
staticbool shouldHoistCommonInstructions (Instruction *I1,Instruction *I2,constTargetTransformInfo &TTI)
 Helper function for hoistCommonCodeFromSuccessors.
 
static void hoistLockstepIdenticalDbgVariableRecords (Instruction *TI,Instruction *I1,SmallVectorImpl<Instruction * > &OtherInsts)
 Hoists DbgVariableRecords fromI1 andOtherInstrs that are identical in lock-step toTI.
 
staticbool areIdenticalUpToCommutativity (constInstruction *I1,constInstruction *I2)
 
static void hoistConditionalLoadsStores (BranchInst *BI,SmallVectorImpl<Instruction * > &SpeculatedConditionalLoadsStores, std::optional<bool > Invert)
 If the target supports conditional faulting, we look for the following pattern:
 
staticbool isSafeCheapLoadStore (constInstruction *I,constTargetTransformInfo &TTI)
 
staticbool isLifeTimeMarker (constInstruction *I)
 
staticbool replacingOperandWithVariableIsCheap (constInstruction *I, int OpIdx)
 
staticbool canSinkInstructions (ArrayRef<Instruction * > Insts,DenseMap<constUse *,SmallVector<Value *, 4 > > &PHIOperands)
 
static void sinkLastInstruction (ArrayRef<BasicBlock * >Blocks)
 
staticbool sinkCommonCodeFromPredecessors (BasicBlock *BB,DomTreeUpdater *DTU)
 Check whether BB's predecessors end with unconditional branches.
 
static void mergeCompatibleInvokesImpl (ArrayRef<InvokeInst * > Invokes,DomTreeUpdater *DTU)
 
staticbool mergeCompatibleInvokes (BasicBlock *BB,DomTreeUpdater *DTU)
 If this block is alandingpad exception handling block, categorize all the predecessorinvokes into sets, with allinvokes in each set being "mergeable" together, and then merge invokes in each set together.
 
staticValueisSafeToSpeculateStore (Instruction *I,BasicBlock *BrBB,BasicBlock *StoreBB,BasicBlock *EndBB)
 Determine if we can hoist sink a sole store instruction out of a conditional block.
 
staticbool validateAndCostRequiredSelects (BasicBlock *BB,BasicBlock *ThenBB,BasicBlock *EndBB,unsigned &SpeculatedInstructions,InstructionCost &Cost,constTargetTransformInfo &TTI)
 Estimate the cost of the insertion(s) and check that the PHI nodes can be converted to selects.
 
staticbool isProfitableToSpeculate (constBranchInst *BI, std::optional<bool > Invert,constTargetTransformInfo &TTI)
 
staticbool blockIsSimpleEnoughToThreadThrough (BasicBlock *BB)
 Return true if we can thread a branch across this block.
 
staticConstantIntgetKnownValueOnEdge (Value *V,BasicBlock *From,BasicBlock *To)
 
static std::optional<boolfoldCondBranchOnValueKnownInPredecessorImpl (BranchInst *BI,DomTreeUpdater *DTU,constDataLayout &DL,AssumptionCache *AC)
 If we have a conditional branch on something for which we know the constant value in predecessors (e.g.
 
staticbool foldCondBranchOnValueKnownInPredecessor (BranchInst *BI,DomTreeUpdater *DTU,constDataLayout &DL,AssumptionCache *AC)
 
staticbool foldTwoEntryPHINode (PHINode *PN,constTargetTransformInfo &TTI,DomTreeUpdater *DTU,AssumptionCache *AC,constDataLayout &DL,bool SpeculateUnpredictables)
 Given a BB that starts with the specified two-entry PHI node, see if we can eliminate it.
 
staticValuecreateLogicalOp (IRBuilderBase &Builder,Instruction::BinaryOps Opc,Value *LHS,Value *RHS,constTwine &Name="")
 
staticbool extractPredSuccWeights (BranchInst *PBI,BranchInst *BI,uint64_t &PredTrueWeight,uint64_t &PredFalseWeight,uint64_t &SuccTrueWeight,uint64_t &SuccFalseWeight)
 Return true if either PBI or BI has branch weight available, and store the weights in {Pred|Succ}{True|False}Weight.
 
static std::optional< std::tuple<BasicBlock *,Instruction::BinaryOps,bool > > shouldFoldCondBranchesToCommonDestination (BranchInst *BI,BranchInst *PBI,constTargetTransformInfo *TTI)
 Determine if the two branches share a common destination and deduce a glue that joins the branches' conditions to arrive at the common destination if that would be profitable.
 
staticbool performBranchToCommonDestFolding (BranchInst *BI,BranchInst *PBI,DomTreeUpdater *DTU,MemorySSAUpdater *MSSAU,constTargetTransformInfo *TTI)
 
staticbool isVectorOp (Instruction &I)
 Return if an instruction's type or any of its operands' types are a vector type.
 
staticStoreInstfindUniqueStoreInBlocks (BasicBlock *BB1,BasicBlock *BB2)
 
staticValueensureValueAvailableInSuccessor (Value *V,BasicBlock *BB,Value *AlternativeV=nullptr)
 
staticbool mergeConditionalStoreToAddress (BasicBlock *PTB,BasicBlock *PFB,BasicBlock *QTB,BasicBlock *QFB,BasicBlock *PostBB,Value *Address,bool InvertPCond,bool InvertQCond,DomTreeUpdater *DTU,constDataLayout &DL,constTargetTransformInfo &TTI)
 
staticbool mergeConditionalStores (BranchInst *PBI,BranchInst *QBI,DomTreeUpdater *DTU,constDataLayout &DL,constTargetTransformInfo &TTI)
 
staticbool tryWidenCondBranchToCondBranch (BranchInst *PBI,BranchInst *BI,DomTreeUpdater *DTU)
 If the previous block ended with a widenable branch, determine if reusing the target block is profitable and legal.
 
staticbool SimplifyCondBranchToCondBranch (BranchInst *PBI,BranchInst *BI,DomTreeUpdater *DTU,constDataLayout &DL,constTargetTransformInfo &TTI)
 If we have a conditional branch as a predecessor of another block, this function tries to simplify it.
 
staticbool isCleanupBlockEmpty (iterator_range<BasicBlock::iterator > R)
 
staticbool removeEmptyCleanup (CleanupReturnInst *RI,DomTreeUpdater *DTU)
 
staticbool mergeCleanupPad (CleanupReturnInst *RI)
 
staticbool casesAreContiguous (SmallVectorImpl<ConstantInt * > &Cases)
 
static void createUnreachableSwitchDefault (SwitchInst *Switch,DomTreeUpdater *DTU,bool RemoveOrigDefaultBlock=true)
 
staticbool eliminateDeadSwitchCases (SwitchInst *SI,DomTreeUpdater *DTU,AssumptionCache *AC,constDataLayout &DL)
 Compute masked bits for the condition of a switch and use it to remove dead cases.
 
staticPHINodefindPHIForConditionForwarding (ConstantInt *CaseValue,BasicBlock *BB, int *PhiIndex)
 If BB would be eligible for simplification by TryToSimplifyUncondBranchFromEmptyBlock (i.e.
 
staticbool forwardSwitchConditionToPHI (SwitchInst *SI)
 Try to forward the condition of a switch instruction to a phi node dominated by the switch, if that would mean that some of the destination blocks of the switch can be folded away.
 
staticbool validLookupTableConstant (Constant *C,constTargetTransformInfo &TTI)
 Return true if the backend will be able to handle initializing an array of constants like C.
 
staticConstantlookupConstant (Value *V,constSmallDenseMap<Value *,Constant * > &ConstantPool)
 If V is a Constant, return it.
 
staticConstantconstantFold (Instruction *I,constDataLayout &DL,constSmallDenseMap<Value *,Constant * > &ConstantPool)
 Try to fold instruction I into a constant.
 
staticbool getCaseResults (SwitchInst *SI,ConstantInt *CaseVal,BasicBlock *CaseDest,BasicBlock **CommonDest,SmallVectorImpl< std::pair<PHINode *,Constant * > > &Res,constDataLayout &DL,constTargetTransformInfo &TTI)
 Try to determine the resulting constant values in phi nodes at the common destination basic block, *CommonDest, for one of the case destionations CaseDest corresponding to value CaseVal (0 for the default case), of a switch instruction SI.
 
static size_t mapCaseToResult (ConstantInt *CaseVal, SwitchCaseResultVectorTy &UniqueResults,Constant *Result)
 
staticbool initializeUniqueCases (SwitchInst *SI,PHINode *&PHI,BasicBlock *&CommonDest, SwitchCaseResultVectorTy &UniqueResults,Constant *&DefaultResult,constDataLayout &DL,constTargetTransformInfo &TTI, uintptr_t MaxUniqueResults)
 
staticValuefoldSwitchToSelect (const SwitchCaseResultVectorTy &ResultVector,Constant *DefaultResult,Value *Condition,IRBuilder<> &Builder)
 
static void removeSwitchAfterSelectFold (SwitchInst *SI,PHINode *PHI,Value *SelectValue,IRBuilder<> &Builder,DomTreeUpdater *DTU)
 
staticbool trySwitchToSelect (SwitchInst *SI,IRBuilder<> &Builder,DomTreeUpdater *DTU,constDataLayout &DL,constTargetTransformInfo &TTI)
 If a switch is only used to initialize one or more phi nodes in a common successor block with only two different constant values, try to replace the switch with a select.
 
staticbool isTypeLegalForLookupTable (Type *Ty,constTargetTransformInfo &TTI,constDataLayout &DL)
 
staticbool isSwitchDense (uint64_t NumCases,uint64_t CaseRange)
 
staticbool isSwitchDense (ArrayRef< int64_t > Values)
 
staticbool shouldBuildLookupTable (SwitchInst *SI,uint64_t TableSize,constTargetTransformInfo &TTI,constDataLayout &DL,constSmallDenseMap<PHINode *,Type * > &ResultTypes)
 Determine whether a lookup table should be built for this switch, based on the number of cases, size of the table, and the types of the results.
 
staticbool shouldUseSwitchConditionAsTableIndex (ConstantInt &MinCaseVal,constConstantInt &MaxCaseVal,bool HasDefaultResults,constSmallDenseMap<PHINode *,Type * > &ResultTypes,constDataLayout &DL,constTargetTransformInfo &TTI)
 
static void reuseTableCompare (User *PhiUser,BasicBlock *PhiBlock,BranchInst *RangeCheckBranch,Constant *DefaultValue,constSmallVectorImpl< std::pair<ConstantInt *,Constant * > > &Values)
 Try to reuse the switch table index compare.
 
staticbool switchToLookupTable (SwitchInst *SI,IRBuilder<> &Builder,DomTreeUpdater *DTU,constDataLayout &DL,constTargetTransformInfo &TTI)
 If the switch is only used to initialize one or more phi nodes in a common successor block with different constant values, replace the switch with lookup tables.
 
staticbool reduceSwitchRange (SwitchInst *SI,IRBuilder<> &Builder,constDataLayout &DL,constTargetTransformInfo &TTI)
 Try to transform a switch that has "holes" in it to a contiguous sequence of cases.
 
staticbool simplifySwitchOfPowersOfTwo (SwitchInst *SI,IRBuilder<> &Builder,constDataLayout &DL,constTargetTransformInfo &TTI)
 Tries to transform switch of powers of two to reduce switch range.
 
staticbool simplifySwitchOfCmpIntrinsic (SwitchInst *SI,IRBuilderBase &Builder,DomTreeUpdater *DTU)
 Fold switch over ucmp/scmp intrinsic to br if two of the switch arms have the same destination.
 
staticbool tryToMergeLandingPad (LandingPadInst *LPad,BranchInst *BI,BasicBlock *BB,DomTreeUpdater *DTU)
 Given an block with only a single landing pad and a unconditional branch try to find another basic block which this one can be merged with.
 
staticBasicBlockallPredecessorsComeFromSameSource (BasicBlock *BB)
 
staticbool mergeNestedCondBranch (BranchInst *BI,DomTreeUpdater *DTU)
 Fold the following pattern: bb0: br i1 cond1, label bb1, label bb2 bb1: br i1 cond2, label bb3, label bb4 bb2: br i1 cond2, label bb4, label bb3 bb3: ... bb4: ... into bb0: cond = xor i1 cond1, cond2 br i1 cond, label bb4, label bb3 bb3: ... bb4: ... NOTE: cond2 always dominates the terminator of bb0.
 
staticbool removeUndefIntroducingPredecessor (BasicBlock *BB,DomTreeUpdater *DTU,AssumptionCache *AC)
 If BB has an incoming value that will always trigger undefined behavior (eg.
 

Variables

staticcl::opt<unsignedPHINodeFoldingThreshold ("phi-node-folding-threshold", cl::Hidden, cl::init(2),cl::desc("Control the amount of phi node folding to perform (default = 2)"))
 
staticcl::opt<unsignedTwoEntryPHINodeFoldingThreshold ("two-entry-phi-node-folding-threshold", cl::Hidden, cl::init(4),cl::desc("Control the maximal total instruction cost that we are willing " "to speculatively execute tofold a 2-entryPHI node into a " "select (default = 4)"))
 
staticcl::opt<boolHoistCommon ("simplifycfg-hoist-common", cl::Hidden, cl::init(true),cl::desc("Hoist commoninstructions up to the parent block"))
 
staticcl::opt<boolHoistLoadsStoresWithCondFaulting ("simplifycfg-hoist-loads-stores-with-cond-faulting", cl::Hidden, cl::init(true),cl::desc("Hoistloads/storesif the target supports " "conditional faulting"))
 
staticcl::opt<unsignedHoistLoadsStoresWithCondFaultingThreshold ("hoist-loads-stores-with-cond-faulting-threshold", cl::Hidden, cl::init(6),cl::desc("Control the maximal conditionalload/store that we are willing " "to speculatively execute to eliminate conditional branch " "(default = 6)"))
 
staticcl::opt<unsignedHoistCommonSkipLimit ("simplifycfg-hoist-common-skip-limit", cl::Hidden, cl::init(20),cl::desc("Allow reordering across at most this many " "instructions when hoisting"))
 
staticcl::opt<boolSinkCommon ("simplifycfg-sink-common", cl::Hidden, cl::init(true),cl::desc("Sink commoninstructions down to the end block"))
 
staticcl::opt<boolHoistCondStores ("simplifycfg-hoist-cond-stores", cl::Hidden, cl::init(true),cl::desc("Hoist conditionalstoresif an unconditional store precedes"))
 
staticcl::opt<boolMergeCondStores ("simplifycfg-merge-cond-stores", cl::Hidden, cl::init(true),cl::desc("Hoist conditionalstores evenif an unconditional store does not " "precede -hoist multiple conditionalstores into a single " "predicated store"))
 
staticcl::opt<boolMergeCondStoresAggressively ("simplifycfg-merge-cond-stores-aggressively", cl::Hidden, cl::init(false),cl::desc("When merging conditionalstores, do so evenif the resultant " "basicblocks are unlikely to beif-converted as a result"))
 
staticcl::opt<boolSpeculateOneExpensiveInst ("speculate-one-expensive-inst", cl::Hidden, cl::init(true),cl::desc("Allow exactly one expensive instruction to be speculatively " "executed"))
 
staticcl::opt<unsignedMaxSpeculationDepth ("max-speculation-depth", cl::Hidden, cl::init(10),cl::desc("Limit maximumrecursion depth when calculating costs of " "speculatively executed instructions"))
 
staticcl::opt< int > MaxSmallBlockSize ("simplifycfg-max-small-block-size", cl::Hidden, cl::init(10),cl::desc("Max size of ablock which is still considered " "small enough tothread through"))
 
staticcl::opt<unsignedBranchFoldThreshold ("simplifycfg-branch-fold-threshold", cl::Hidden, cl::init(2),cl::desc("Maximum cost of combining conditions when " "folding branches"))
 
staticcl::opt<unsignedBranchFoldToCommonDestVectorMultiplier ("simplifycfg-branch-fold-common-dest-vector-multiplier", cl::Hidden, cl::init(2),cl::desc("Multiplier to apply to threshold when determining whether or not " "tofold branch to common destination whenvectoroperations are " "present"))
 
staticcl::opt<boolEnableMergeCompatibleInvokes ("simplifycfg-merge-compatible-invokes", cl::Hidden, cl::init(true),cl::desc("Allow SimplifyCFG tomerge invokes together when appropriate"))
 
staticcl::opt<unsignedMaxSwitchCasesPerResult ("max-switch-cases-per-result", cl::Hidden, cl::init(16),cl::desc("Limit cases to analyze when converting a switch to select"))
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "simplifycfg"

Definition at line94 of fileSimplifyCFG.cpp.

Enumeration Type Documentation

◆ SkipFlags

enumSkipFlags
Enumerator
SkipReadMem 
SkipSideEffect 
SkipImplicitControlFlow 

Definition at line1452 of fileSimplifyCFG.cpp.

Function Documentation

◆ addPredecessorToBlock()

static void addPredecessorToBlock(BasicBlockSucc,
BasicBlockNewPred,
BasicBlockExistPred,
MemorySSAUpdaterMSSAU =nullptr 
)
static

Update PHI nodes in Succ to indicate that there will now be entries in it from the 'NewPred' block.

The values that will be flowing into the PHI nodes will be the same as those coming in from ExistPred, an existing predecessor of Succ.

Definition at line388 of fileSimplifyCFG.cpp.

Referencesllvm::BasicBlock::phis().

Referenced byfoldCondBranchOnValueKnownInPredecessorImpl(),performBranchToCommonDestFolding(),SimplifyCondBranchToCondBranch(), andswitchToLookupTable().

◆ allPredecessorsComeFromSameSource()

staticBasicBlock * allPredecessorsComeFromSameSource(BasicBlockBB)
static

Definition at line7923 of fileSimplifyCFG.cpp.

ReferencesP, andllvm::predecessors().

◆ areIdenticalUpToCommutativity()

staticbool areIdenticalUpToCommutativity(constInstructionI1,
constInstructionI2 
)
static

Definition at line1597 of fileSimplifyCFG.cpp.

Referencesllvm::drop_begin(),llvm::equal(),llvm::User::getOperand(), andllvm::User::operands().

◆ blockIsSimpleEnoughToThreadThrough()

staticbool blockIsSimpleEnoughToThreadThrough(BasicBlockBB)
static

Return true if we can thread a branch across this block.

Definition at line3508 of fileSimplifyCFG.cpp.

Referencesllvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),I,llvm::BasicBlock::instructionsWithoutDebug(),MaxSmallBlockSize,llvm::reverse(), andSize.

Referenced byfoldCondBranchOnValueKnownInPredecessorImpl().

◆ canSinkInstructions()

staticbool canSinkInstructions(ArrayRef<Instruction * > Insts,
DenseMap<constUse *,SmallVector<Value *, 4 > > & PHIOperands 
)
static

Definition at line2219 of fileSimplifyCFG.cpp.

Referencesllvm::all_of(),llvm::any_of(),assert(),llvm::CallingConv::C,llvm::canReplaceOperandWithVariable(),llvm::Instruction::CompareUsingIntersectedAttrs,llvm::equal(),llvm::ArrayRef< T >::front(),llvm::User::getNumOperands(),llvm::User::getOperand(),llvm::User::getOperandUse(),I,isLifeTimeMarker(),replacingOperandWithVariableIsCheap(), andllvm::Value::uses().

Referenced bysinkCommonCodeFromPredecessors().

◆ casesAreContiguous()

staticbool casesAreContiguous(SmallVectorImpl<ConstantInt * > & Cases)
static

Definition at line5736 of fileSimplifyCFG.cpp.

Referencesllvm::array_pod_sort(),assert(),llvm::SmallVectorTemplateCommon< T, typename >::begin(),constantIntSortPredicate(),llvm::SmallVectorTemplateCommon< T, typename >::end(),I, andllvm::SmallVectorBase< Size_T >::size().

◆ cloneInstructionsIntoPredecessorBlockAndUpdateSSAUses()

static void cloneInstructionsIntoPredecessorBlockAndUpdateSSAUses(BasicBlockBB,
BasicBlockPredBlock,
ValueToValueMapTyVMap 
)
static

Definition at line1106 of fileSimplifyCFG.cpp.

Referencesassert(),llvm::Instruction::clone(),llvm::Instruction::cloneDebugInfoFrom(),llvm::Instruction::dropUBImplyingAttrsAndMetadata(),llvm::Instruction::getDebugLoc(),llvm::ilist_node_impl< OptionsT >::getIterator(),llvm::Instruction::getModule(),llvm::Value::getName(),llvm::BasicBlock::getTerminator(),llvm::Instruction::insertInto(),llvm::make_early_inc_range(),Range,llvm::RemapDbgRecordRange(),llvm::RemapInstruction(),llvm::RF_IgnoreMissingLocals,llvm::RF_NoModuleLevelChanges,llvm::Instruction::setDebugLoc(), andllvm::Value::takeName().

Referenced byperformBranchToCommonDestFolding().

◆ computeSpeculationCost()

staticInstructionCost computeSpeculationCost(constUserI,
constTargetTransformInfoTTI 
)
static

Compute an abstract "cost" of speculating the given instruction, which is assumed to be safe to speculate.

TCC_Free means cheap, TCC_Basic means less cheap, and TCC_Expensive means prohibitively expensive.

Definition at line402 of fileSimplifyCFG.cpp.

Referencesllvm::TargetTransformInfo::getInstructionCost(),I, andllvm::TargetTransformInfo::TCK_SizeAndLatency.

Referenced bydominatesMergePoint(), andvalidateAndCostRequiredSelects().

◆ constantFold()

staticConstant * constantFold(InstructionI,
constDataLayoutDL,
constSmallDenseMap<Value *,Constant * > & ConstantPool 
)
static

Try to fold instruction I into a constant.

This works for simple instructions such as binary operations where both operands are constant or can be replaced by constants from the ConstantPool. Returns the resulting constant on success, 0 otherwise.

Definition at line6133 of fileSimplifyCFG.cpp.

ReferencesA,llvm::ConstantFoldInstOperands(),DL,I,lookupConstant(),N,llvm::SmallVectorTemplateBase< T, bool >::push_back(), andSelect.

Referenced bygetCaseResults().

◆ constantIntSortPredicate()

static int constantIntSortPredicate(ConstantInt *constP1,
ConstantInt *constP2 
)
static

Definition at line1067 of fileSimplifyCFG.cpp.

ReferencesLHS, andRHS.

Referenced bycasesAreContiguous().

◆ createLogicalOp()

staticValue * createLogicalOp(IRBuilderBaseBuilder,
Instruction::BinaryOps Opc,
ValueLHS,
ValueRHS,
constTwineName ="" 
)
static

Definition at line3931 of fileSimplifyCFG.cpp.

Referencesllvm::IRBuilderBase::CreateBinOp(),llvm::IRBuilderBase::CreateLogicalAnd(),llvm::IRBuilderBase::CreateLogicalOr(),llvm::impliesPoison(),LHS,llvm_unreachable,Name, andRHS.

Referenced byperformBranchToCommonDestFolding(), andSimplifyCondBranchToCondBranch().

◆ createUnreachableSwitchDefault()

static void createUnreachableSwitchDefault(SwitchInstSwitch,
DomTreeUpdaterDTU,
bool RemoveOrigDefaultBlock =true 
)
static

Definition at line5747 of fileSimplifyCFG.cpp.

Referencesllvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(),llvm::BasicBlock::Create(),llvm::dbgs(),llvm::BasicBlock::getContext(),llvm::Value::getName(),llvm::BasicBlock::getParent(),llvm::is_contained(),LLVM_DEBUG,llvm::SmallVectorTemplateBase< T, bool >::push_back(), andllvm::successors().

Referenced byeliminateDeadSwitchCases().

◆ dominatesMergePoint()

staticbool dominatesMergePoint(ValueV,
BasicBlockBB,
InstructionInsertPt,
SmallPtrSetImpl<Instruction * > & AggressiveInsts,
InstructionCostCost,
InstructionCost Budget,
constTargetTransformInfoTTI,
AssumptionCacheAC,
unsigned Depth =0 
)
static

If we have a merge point of an "if condition" as accepted above, return true if the specified value dominates the block.

We don't handle the true generality of domination here, just a special case which works well enough for us.

If AggressiveInsts is non-null, and if V does not dominate BB, we check to see if V (which must be an instruction) and its recursive operands that do not dominate BB have a combined cost lower than Budget and are non-trapping. If both are true, the instruction is inserted into the set and true is returned.

The cost for most non-trapping instructions is defined as 1 except for Select whose cost is 2.

After this function returns, Cost is increased by the cost of V plus its non-dominating operands. If that cost is greater than Budget, false is returned and Cost is undefined.

Definition at line424 of fileSimplifyCFG.cpp.

ReferencescomputeSpeculationCost(),llvm::SmallPtrSetImpl< PtrType >::count(),llvm::Depth,dominatesMergePoint(),llvm::SmallPtrSetImplBase::empty(),llvm::BranchInst::getSuccessor(),llvm::BasicBlock::getTerminator(),I,llvm::SmallPtrSetImpl< PtrType >::insert(),llvm::BranchInst::isConditional(),llvm::isSafeToSpeculativelyExecute(),llvm::InstructionCost::isValid(),MaxSpeculationDepth, andSpeculateOneExpensiveInst.

Referenced bydominatesMergePoint(), andfoldTwoEntryPHINode().

◆ eliminateBlockCases()

static void eliminateBlockCases(BasicBlockBB,
std::vector< ValueEqualityComparisonCase > & Cases 
)
static

Given a vector of bb/value pairs, remove any entries in the list that match the specified block.

Definition at line834 of fileSimplifyCFG.cpp.

Referencesllvm::erase().

◆ eliminateDeadSwitchCases()

staticbool eliminateDeadSwitchCases(SwitchInstSI,
DomTreeUpdaterDTU,
AssumptionCacheAC,
constDataLayoutDL 
)
static

Compute masked bits for the condition of a switch and use it to remove dead cases.

Definition at line5902 of fileSimplifyCFG.cpp.

Referencesllvm::SwitchInstProfUpdateWrapper::addCase(),llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(),assert(),llvm::computeKnownBits(),llvm::ComputeMaxSignificantBits(),Cond,llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::count(),createUnreachableSwitchDefault(),llvm::dbgs(),DL,llvm::SmallVectorBase< Size_T >::empty(),llvm::KnownBits::getBitWidth(),llvm::Type::getIntegerBitWidth(),llvm::APInt::getSignificantBits(),llvm::SwitchInstProfUpdateWrapper::getSuccessorWeight(),llvm::APInt::intersects(),llvm::APInt::isSubsetOf(),LLVM_DEBUG,llvm::KnownBits::One,llvm::popcount(),llvm::SmallVectorTemplateBase< T, bool >::push_back(),llvm::SwitchInstProfUpdateWrapper::removeCase(),llvm::SwitchInstProfUpdateWrapper::setSuccessorWeight(),llvm::Successor, andllvm::KnownBits::Zero.

◆ ensureValueAvailableInSuccessor()

staticValue * ensureValueAvailableInSuccessor(ValueV,
BasicBlockBB,
ValueAlternativeV =nullptr 
)
static

Definition at line4277 of fileSimplifyCFG.cpp.

Referencesassert(),llvm::BasicBlock::begin(),llvm::PHINode::Create(),llvm::PoisonValue::get(),getParent(),llvm::BasicBlock::getSingleSuccessor(),llvm::BasicBlock::hasNPredecessors(),I,PHI,llvm::pred_begin(), andllvm::predecessors().

Referenced bymergeConditionalStoreToAddress().

◆ eraseTerminatorAndDCECond()

static void eraseTerminatorAndDCECond(InstructionTI,
MemorySSAUpdaterMSSAU =nullptr 
)
static

Definition at line767 of fileSimplifyCFG.cpp.

ReferencesCond,llvm::Instruction::eraseFromParent(), andllvm::RecursivelyDeleteTriviallyDeadInstructions().

◆ extractPredSuccWeights()

staticbool extractPredSuccWeights(BranchInstPBI,
BranchInstBI,
uint64_tPredTrueWeight,
uint64_tPredFalseWeight,
uint64_tSuccTrueWeight,
uint64_tSuccFalseWeight 
)
static

Return true if either PBI or BI has branch weight available, and store the weights in {Pred|Succ}{True|False}Weight.

If one of PBI and BI does not have branch weight, use 1:1 as its weight.

Definition at line3947 of fileSimplifyCFG.cpp.

Referencesllvm::extractBranchWeights().

Referenced byperformBranchToCommonDestFolding(), andSimplifyCondBranchToCondBranch().

◆ findPHIForConditionForwarding()

staticPHINode * findPHIForConditionForwarding(ConstantIntCaseValue,
BasicBlockBB,
int * PhiIndex 
)
static

If BB would be eligible for simplification by TryToSimplifyUncondBranchFromEmptyBlock (i.e.

it is empty and terminated by an unconditional branch), look at the phi node for BB in the successor block and see if the incoming value is equal to CaseValue. If so, return the phi node, and set PhiIndex to BB's index in the phi node.

Definition at line6004 of fileSimplifyCFG.cpp.

Referencesassert(),llvm::BasicBlock::getFirstNonPHIIt(),llvm::BasicBlock::getSinglePredecessor(),llvm::BasicBlock::getTerminator(),Idx,PHI, andllvm::BasicBlock::phis().

Referenced byforwardSwitchConditionToPHI().

◆ findUniqueStoreInBlocks()

staticStoreInst * findUniqueStoreInBlocks(BasicBlockBB1,
BasicBlockBB2 
)
static

Definition at line4260 of fileSimplifyCFG.cpp.

ReferencesI.

Referenced bymergeConditionalStoreToAddress().

◆ fitWeights()

static void fitWeights(MutableArrayRef<uint64_tWeights)
static

Keep halving the weights until all can fit in uint32_t.

Definition at line1097 of fileSimplifyCFG.cpp.

Referencesllvm::countl_zero(),I,llvm::max_element(), andllvm::Offset.

Referenced bymergeNestedCondBranch(),performBranchToCommonDestFolding(), andSimplifyCondBranchToCondBranch().

◆ foldCondBranchOnValueKnownInPredecessor()

staticbool foldCondBranchOnValueKnownInPredecessor(BranchInstBI,
DomTreeUpdaterDTU,
constDataLayoutDL,
AssumptionCacheAC 
)
static

Definition at line3721 of fileSimplifyCFG.cpp.

ReferencesDL, andfoldCondBranchOnValueKnownInPredecessorImpl().

◆ foldCondBranchOnValueKnownInPredecessorImpl()

static std::optional<bool > foldCondBranchOnValueKnownInPredecessorImpl(BranchInstBI,
DomTreeUpdaterDTU,
constDataLayoutDL,
AssumptionCacheAC 
)
static

If we have a conditional branch on something for which we know the constant value in predecessors (e.g.

a phi node in the current block), thread edges from the predecessor to their ultimate destination.

Definition at line3564 of fileSimplifyCFG.cpp.

ReferencesaddPredecessorToBlock(),llvm::any_of(),llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(),llvm::BasicBlock::begin(),blockIsSimpleEnoughToThreadThrough(),Cond,llvm::dbgs(),DL,llvm::MapVector< KeyT, ValueT, MapType, VectorType >::empty(),llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(),llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(),llvm::FoldSingleEntryPHINodes(),llvm::BranchInst::getCondition(),llvm::Instruction::getDebugLoc(),llvm::PHINode::getIncomingBlock(),llvm::PHINode::getIncomingValueForBlock(),getKnownValueOnEdge(),llvm::Value::getName(),llvm::PHINode::getNumIncomingValues(),llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),llvm::BranchInst::getSuccessor(),llvm::BasicBlock::getTerminator(),llvm::ConstantInt::getZExtValue(),llvm::PHINode::incoming_values(),llvm::MapVector< KeyT, ValueT, MapType, VectorType >::insert(),LLVM_DEBUG,llvm::MergeBlockIntoPredecessor(),N,llvm::predecessors(),llvm::SmallVectorTemplateBase< T, bool >::push_back(),llvm::AssumptionCache::registerAssumption(),llvm::BasicBlock::removePredecessor(),llvm::Instruction::setDebugLoc(),llvm::BranchInst::setSuccessor(),llvm::simplifyInstruction(), andllvm::SplitBlockPredecessors().

Referenced byfoldCondBranchOnValueKnownInPredecessor().

◆ foldSwitchToSelect()

staticValue * foldSwitchToSelect(const SwitchCaseResultVectorTy & ResultVector,
ConstantDefaultResult,
ValueCondition,
IRBuilder<> & Builder 
)
static

Definition at line6308 of fileSimplifyCFG.cpp.

Referencesllvm::And,llvm::IRBuilderBase::CreateAnd(),llvm::IRBuilderBase::CreateICmpEQ(),llvm::IRBuilderBase::CreateOr(),llvm::IRBuilderBase::CreateSelect(),llvm::IRBuilderBase::CreateSub(),llvm::ConstantInt::getBitWidth(),llvm::Constant::getNullValue(),llvm::ConstantInt::getValue(),llvm::APInt::getZero(),llvm::Constant::isNullValue(),llvm::isPowerOf2_32(),llvm::Log2_32(),llvm::APInt::popcount(), andllvm::ArrayRef< T >::size().

Referenced bytrySwitchToSelect().

◆ foldTwoEntryPHINode()

staticbool foldTwoEntryPHINode(PHINodePN,
constTargetTransformInfoTTI,
DomTreeUpdaterDTU,
AssumptionCacheAC,
constDataLayoutDL,
bool SpeculateUnpredictables 
)
static

Given a BB that starts with the specified two-entry PHI node, see if we can eliminate it.

Definition at line3737 of fileSimplifyCFG.cpp.

Referencesllvm::any_of(),llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(),assert(),llvm::BasicBlock::begin(),llvm::PHINode::blocks(),llvm::copy_if(),llvm::SmallPtrSetImpl< PtrType >::count(),llvm::IRBuilderBase::CreateBr(),llvm::IRBuilderBase::CreateSelectFMF(),llvm::dbgs(),DL,dominatesMergePoint(),llvm::Instruction::eraseFromParent(),llvm::extractBranchWeights(),llvm::TargetTransformInfo::getBranchMispredictPenalty(),llvm::BranchProbability::getBranchProbability(),llvm::BranchProbability::getCompl(),llvm::BranchInst::getCondition(),llvm::GetIfCondition(),llvm::PHINode::getIncomingValue(),llvm::PHINode::getIncomingValueForBlock(),llvm::Instruction::getMetadata(),llvm::Value::getName(),llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),llvm::TargetTransformInfo::getPredictableBranchThreshold(),llvm::BranchInst::getSuccessor(),llvm::Value::getType(),llvm::BasicBlock::hasAddressTaken(),llvm::hoistAllInstructionsInto(),I,II,llvm::Type::isIntegerTy(),LLVM_DEBUG,llvm::PatternMatch::m_AnyIntegralConstant(),llvm::PatternMatch::m_BinOp(),llvm::PatternMatch::m_c_Select(),llvm::PatternMatch::m_CombineOr(),llvm::PatternMatch::m_ImmConstant(),llvm::PatternMatch::m_Not(),llvm::PatternMatch::m_Value(),llvm::PatternMatch::match(),llvm::SmallVectorTemplateBase< T, bool >::push_back(),llvm::Value::replaceAllUsesWith(),llvm::simplifyInstruction(),llvm::SmallVectorBase< Size_T >::size(),llvm::Successor,llvm::successors(),std::swap(),llvm::Value::takeName(),llvm::TargetTransformInfo::TCC_Basic, andTwoEntryPHINodeFoldingThreshold.

◆ forwardSwitchConditionToPHI()

staticbool forwardSwitchConditionToPHI(SwitchInstSI)
static

Try to forward the condition of a switch instruction to a phi node dominated by the switch, if that would mean that some of the destination blocks of the switch can be folded away.

Return true if a change is made.

Definition at line6035 of fileSimplifyCFG.cpp.

Referencesllvm::count(),findPHIForConditionForwarding(),llvm::is_contained(),llvm::BasicBlock::phis(), andllvm::SmallVectorBase< Size_T >::size().

◆ getBranchWeights()

static void getBranchWeights(InstructionTI,
SmallVectorImpl<uint64_t > & Weights 
)
static

Get Weights of a given terminator, the default weight is at the front of the vector.

If TI is a conditional eq, we need to swap the branch-weight metadata.

Definition at line1079 of fileSimplifyCFG.cpp.

Referencesassert(),llvm::SmallVectorTemplateCommon< T, typename >::back(),llvm::extractFromBranchWeightMD64(),llvm::SmallVectorTemplateCommon< T, typename >::front(),llvm::BranchInst::getCondition(),llvm::Instruction::getMetadata(),llvm::CmpInst::getPredicate(),llvm::SmallVectorBase< Size_T >::size(), andstd::swap().

◆ getCaseResults()

staticbool getCaseResults(SwitchInstSI,
ConstantIntCaseVal,
BasicBlockCaseDest,
BasicBlock ** CommonDest,
SmallVectorImpl< std::pair<PHINode *,Constant * > > & Res,
constDataLayoutDL,
constTargetTransformInfoTTI 
)
static

Try to determine the resulting constant values in phi nodes at the common destination basic block, *CommonDest, for one of the case destionations CaseDest corresponding to value CaseVal (0 for the default case), of a switch instruction SI.

Definition at line6162 of fileSimplifyCFG.cpp.

Referencesllvm::CallingConv::C,constantFold(),DL,llvm::Use::getUser(),I,Idx,llvm::BasicBlock::instructionsWithoutDebug(),lookupConstant(),PHI, andvalidLookupTableConstant().

Referenced byinitializeUniqueCases(), andswitchToLookupTable().

◆ getConstantInt()

staticConstantInt * getConstantInt(ValueV,
constDataLayoutDL 
)
static

Extract ConstantInt from value, looking through IntToPtr and PointerNullValue.

Return NULL if value is not a constant int.

Definition at line492 of fileSimplifyCFG.cpp.

Referencesllvm::ConstantFoldIntegerCast(),DL, andllvm::Value::getType().

◆ getKnownValueOnEdge()

staticConstantInt * getKnownValueOnEdge(ValueV,
BasicBlockFrom,
BasicBlockTo 
)
static

Definition at line3542 of fileSimplifyCFG.cpp.

ReferencesFrom,llvm::BranchInst::getCondition(),llvm::Value::getContext(),llvm::ConstantInt::getFalse(),llvm::BranchInst::getSuccessor(),llvm::ConstantInt::getTrue(),I, andllvm::BranchInst::isConditional().

Referenced byfoldCondBranchOnValueKnownInPredecessorImpl().

◆ hoistConditionalLoadsStores()

static void hoistConditionalLoadsStores(BranchInstBI,
SmallVectorImpl<Instruction * > & SpeculatedConditionalLoadsStores,
std::optional<boolInvert 
)
static

If the target supports conditional faulting, we look for the following pattern:

BB:
...
%cond = icmp ult %x, %y
br i1 %cond, label %TrueBB, label %FalseBB
FalseBB:
store i32 1, ptr %q, align 4
...
TrueBB:
%maskedloadstore =load i32, ptr %b, align 4
store i32 %maskedloadstore, ptr %p, align 4
...
AMDGPU Mark last scratch load

and transform it into:

BB:
...
%cond = icmp ult %x, %y
%maskedloadstore = cload i32, ptr %b, %cond
cstore i32 %maskedloadstore, ptr %p, %cond
cstore i32 1, ptr %q, ~%cond
br i1 %cond, label %TrueBB, label %FalseBB
FalseBB:
...
TrueBB:
...

where cload/cstore are represented by llvm.masked.load/store intrinsics, e.g.

%vcond = bitcast i1 %cond to <1 x i1>
%v0 = call <1 x i32> @llvm.masked.load.v1i32.p0
(ptr %b, i32 4, <1 x i1> %vcond, <1 x i32> poison)
%maskedloadstore = bitcast <1 x i32> %v0 to i32
callvoid @llvm.masked.store.v1i32.p0
(<1 x i32> %v0, ptr %p, i32 4, <1 x i1> %vcond)
%cond.not = xor i1 %cond,true
%vcond.not = bitcast i1 %cond.not to <1 x i>
callvoid @llvm.masked.store.v1i32.p0
(<1 x i32> <i32 1>, ptr %q, i32 4, <1x i1> %vcond.not)
This is an optimization pass for GlobalISel generic memory operations.

So we need to turn hoisted load/store into cload/cstore.

Parameters
BIThe branch instruction.
SpeculatedConditionalLoadsStoresThe load/store instructions that will be speculated.
Invertindicates if speculates FalseBB. Only used in triangle CFG.

Definition at line1671 of fileSimplifyCFG.cpp.

Referencesllvm::CallBase::addRangeRetAttr(),assert(),llvm::SmallVectorTemplateCommon< T, typename >::back(),Cond,llvm::Instruction::copyMetadata(),llvm::IRBuilderBase::CreateBitCast(),llvm::IRBuilderBase::CreateMaskedLoad(),llvm::IRBuilderBase::CreateMaskedStore(),llvm::IRBuilderBase::CreateXor(),llvm::at::deleteAssignmentMarkers(),llvm::FixedVectorType::get(),llvm::PHINode::getBasicBlockIndex(),llvm::getConstantRangeFromMetadata(),llvm::PHINode::getIncomingValueForBlock(),llvm::Type::getInt1Ty(),llvm::getLoadStoreType(),llvm::User::getOperand(),llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),llvm::ConstantInt::getTrue(),llvm::Value::getType(),I, andllvm::PHINode::setIncomingValue().

◆ hoistLockstepIdenticalDbgVariableRecords()

static void hoistLockstepIdenticalDbgVariableRecords(InstructionTI,
InstructionI1,
SmallVectorImpl<Instruction * > & OtherInsts 
)
static

Hoists DbgVariableRecords fromI1 andOtherInstrs that are identical in lock-step toTI.

This matches how dbg.* intrinsics are hoisting in hoistCommonCodeFromSuccessors. e.g. The input: I1 DVRs: { x, z }, OtherInsts: { I2 DVRs: { x, y, z } } would result in hoisting only DbgVariableRecord x.

Definition at line1546 of fileSimplifyCFG.cpp.

Referencesllvm::all_of(),llvm::ilist_node_impl< OptionsT >::getIterator(),llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),I,llvm::make_first_range(),llvm::none_of(),Other,llvm::SmallVectorTemplateBase< T, bool >::push_back(),llvm::DbgRecord::removeFromParent(),llvm::SmallVectorImpl< T >::reserve(), andllvm::SmallVectorBase< Size_T >::size().

◆ incomingValuesAreCompatible()

staticbool incomingValuesAreCompatible(BasicBlockBB,
ArrayRef<BasicBlock * > IncomingBlocks,
SmallPtrSetImpl<Value * > * EquivalenceSet =nullptr 
)
static

Return true if all the PHI nodes in the basic blockBB receive compatible (identical) incoming values when coming from all of the predecessor blocks that are specified inIncomingBlocks.

Note that if the values aren't exactly identical, butEquivalenceSet is provided, andboth of the values are present in the set, then they are considered equal.

Definition at line332 of fileSimplifyCFG.cpp.

Referencesllvm::all_of(),assert(),llvm::BasicBlock::phis(), andllvm::ArrayRef< T >::size().

Referenced bysafeToMergeTerminators().

◆ initializeUniqueCases()

staticbool initializeUniqueCases(SwitchInstSI,
PHINode *& PHI,
BasicBlock *& CommonDest,
SwitchCaseResultVectorTy & UniqueResults,
Constant *& DefaultResult,
constDataLayoutDL,
constTargetTransformInfoTTI,
uintptr_t MaxUniqueResults 
)
static

Definition at line6251 of fileSimplifyCFG.cpp.

Referencesllvm::SmallVectorTemplateCommon< T, typename >::begin(),llvm::Function::begin(),DL,getCaseResults(),llvm::BasicBlock::getFirstNonPHIOrDbg(),I,mapCaseToResult(),MaxSwitchCasesPerResult,PHI,Results,llvm::SmallVectorBase< Size_T >::size(), andllvm::Function::size().

Referenced bytrySwitchToSelect().

◆ isCleanupBlockEmpty()

staticbool isCleanupBlockEmpty(iterator_range<BasicBlock::iteratorR)
static

Definition at line5274 of fileSimplifyCFG.cpp.

ReferencesI, andII.

Referenced byremoveEmptyCleanup().

◆ isLifeTimeMarker()

staticbool isLifeTimeMarker(constInstructionI)
static

Definition at line2191 of fileSimplifyCFG.cpp.

ReferencesI, andII.

Referenced bycanSinkInstructions().

◆ isProfitableToSpeculate()

staticbool isProfitableToSpeculate(constBranchInstBI,
std::optional<boolInvert,
constTargetTransformInfoTTI 
)
static

Definition at line3194 of fileSimplifyCFG.cpp.

Referencesllvm::extractBranchWeights(),llvm::BranchProbability::getBranchProbability(),llvm::Instruction::getMetadata(), andllvm::TargetTransformInfo::getPredictableBranchThreshold().

◆ isSafeCheapLoadStore()

staticbool isSafeCheapLoadStore(constInstructionI,
constTargetTransformInfoTTI 
)
static

Definition at line1757 of fileSimplifyCFG.cpp.

Referencesllvm::getLoadStoreAlignment(),llvm::getLoadStoreType(),llvm::TargetTransformInfo::hasConditionalLoadStoreForType(),I, andllvm::Value::MaximumAlignment.

◆ isSafeToHoistInstr()

staticbool isSafeToHoistInstr(InstructionI,
unsigned Flags 
)
static

Definition at line1473 of fileSimplifyCFG.cpp.

ReferencesI,llvm::isSafeToSpeculativelyExecute(),SkipImplicitControlFlow,SkipReadMem, andSkipSideEffect.

◆ isSafeToHoistInvoke()

staticbool isSafeToHoistInvoke(BasicBlockBB1,
BasicBlockBB2,
InstructionI1,
InstructionI2 
)
static

Definition at line1435 of fileSimplifyCFG.cpp.

Referencesllvm::BasicBlock::phis(), andllvm::successors().

◆ isSafeToSpeculateStore()

staticValue * isSafeToSpeculateStore(InstructionI,
BasicBlockBrBB,
BasicBlockStoreBB,
BasicBlockEndBB 
)
static

Determine if we can hoist sink a sole store instruction out of a conditional block.

We are looking for code like the following: BrBB: store i32 add, i32* arrayidx2 ... // No other stores or function calls (we could be calling a memory ... // function). cmp = icmp ult x, y br i1 cmp, label EndBB, label ThenBB ThenBB: store i32 add5, i32* arrayidx2 br label EndBB EndBB: ... We are going to transform this into: BrBB: store i32 add, i32* arrayidx2 ... // cmp = icmp ult x, y add.add5 = select i1 cmp, i32 add, add5 store i32 add.add5, i32* arrayidx2 ...

Returns
The pointer to the value of the previous store if the store can be hoisted into the predecessor block. 0 otherwise.

Definition at line3079 of fileSimplifyCFG.cpp.

Referencesllvm::StoreInst::getAlign(),llvm::StoreInst::getPointerOperand(),llvm::Value::getType(),llvm::getUnderlyingObject(),llvm::StoreInst::getValueOperand(),I,llvm::BasicBlock::instructionsWithoutDebug(),llvm::isDereferenceablePointer(),llvm::StoreInst::isSimple(),llvm::isWritableObject(),llvm::PointerMayBeCaptured(), andllvm::reverse().

◆ isSwitchDense()[1/2]

staticbool isSwitchDense(ArrayRef< int64_t > Values)
static

Definition at line6757 of fileSimplifyCFG.cpp.

Referencesllvm::ArrayRef< T >::back(),llvm::ArrayRef< T >::front(),isSwitchDense(),Range, andllvm::ArrayRef< T >::size().

◆ isSwitchDense()[2/2]

staticbool isSwitchDense(uint64_t NumCases,
uint64_t CaseRange 
)
static

Definition at line6745 of fileSimplifyCFG.cpp.

ReferencesUINT64_MAX.

Referenced byisSwitchDense(),reduceSwitchRange(),shouldBuildLookupTable(), andsimplifySwitchOfPowersOfTwo().

◆ isTypeLegalForLookupTable()

staticbool isTypeLegalForLookupTable(TypeTy,
constTargetTransformInfoTTI,
constDataLayoutDL 
)
static

Definition at line6724 of fileSimplifyCFG.cpp.

Referencesllvm::BitWidth,DL,llvm::isPowerOf2_32(),llvm::TargetTransformInfo::isTypeLegal(), andIT.

Referenced byshouldBuildLookupTable().

◆ isVectorOp()

staticbool isVectorOp(InstructionI)
static

Return if an instruction's type or any of its operands' types are a vector type.

Definition at line4124 of fileSimplifyCFG.cpp.

Referencesllvm::any_of(), andI.

Referenced byllvm::foldBranchToCommonDest().

◆ lookupConstant()

staticConstant * lookupConstant(ValueV,
constSmallDenseMap<Value *,Constant * > & ConstantPool 
)
static

If V is a Constant, return it.

Otherwise, try to look up its constant value in ConstantPool, returning 0 if it's not there.

Definition at line6121 of fileSimplifyCFG.cpp.

Referencesllvm::CallingConv::C.

Referenced byconstantFold(), andgetCaseResults().

◆ mapCaseToResult()

static size_t mapCaseToResult(ConstantIntCaseVal,
SwitchCaseResultVectorTy & UniqueResults,
ConstantResult 
)
static

Definition at line6233 of fileSimplifyCFG.cpp.

ReferencesI.

Referenced byinitializeUniqueCases().

◆ mergeCleanupPad()

staticbool mergeCleanupPad(CleanupReturnInstRI)
static

Definition at line5504 of fileSimplifyCFG.cpp.

Referencesllvm::BranchInst::Create(),llvm::Instruction::eraseFromParent(),llvm::BasicBlock::front(),llvm::CleanupReturnInst::getCleanupPad(),llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),llvm::BasicBlock::getSinglePredecessor(),llvm::CleanupReturnInst::getUnwindDest(), andllvm::Value::replaceAllUsesWith().

◆ mergeCompatibleInvokes()

staticbool mergeCompatibleInvokes(BasicBlockBB,
DomTreeUpdaterDTU 
)
static

If this block is alandingpad exception handling block, categorize all the predecessorinvokes into sets, with allinvokes in each set being "mergeable" together, and then merge invokes in each set together.

This is a weird mix of hoisting and sinking. Visually, it goes from: [...] [...] | | [invoke0] [invoke1] / \ / \ [cont0] [landingpad] [cont1] to: [...] [...] \ / [invoke] / \ [cont] [landingpad]

But of course we can only do that if the invokes share thelandingpad, edges invoke0->cont0 and invoke1->cont1 are "compatible", and the invoked functions are "compatible".

Definition at line2996 of fileSimplifyCFG.cpp.

ReferencesEnableMergeCompatibleInvokes,llvm::BasicBlock::isLandingPad(),mergeCompatibleInvokesImpl(),llvm::predecessors(), andllvm::ArrayRef< T >::size().

◆ mergeCompatibleInvokesImpl()

static void mergeCompatibleInvokesImpl(ArrayRef<InvokeInst * > Invokes,
DomTreeUpdaterDTU 
)
static

Definition at line2844 of fileSimplifyCFG.cpp.

Referencesassert(),llvm::Instruction::clone(),llvm::BasicBlock::Create(),llvm::BasicBlock::end(),llvm::ArrayRef< T >::front(),llvm::Value::getContext(),llvm::Value::getName(),llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),llvm::BasicBlock::getParent(),II,llvm::Instruction::insertInto(),llvm::SmallVectorTemplateBase< T, bool >::push_back(),llvm::SmallVectorImpl< T >::reserve(),llvm::InvokeInst::setNormalDest(),llvm::ArrayRef< T >::size(), andllvm::successors().

Referenced bymergeCompatibleInvokes().

◆ mergeConditionalStores()

staticbool mergeConditionalStores(BranchInstPBI,
BranchInstQBI,
DomTreeUpdaterDTU,
constDataLayoutDL,
constTargetTransformInfoTTI 
)
static

Definition at line4475 of fileSimplifyCFG.cpp.

ReferencesAddress,DL,llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),llvm::BasicBlock::getSinglePredecessor(),llvm::BasicBlock::getSingleSuccessor(),llvm::BranchInst::getSuccessor(),I,llvm::SmallPtrSetImpl< PtrType >::insert(),mergeConditionalStoreToAddress(),P,llvm::set_intersect(), andstd::swap().

Referenced bySimplifyCondBranchToCondBranch().

◆ mergeConditionalStoreToAddress()

staticbool mergeConditionalStoreToAddress(BasicBlockPTB,
BasicBlockPFB,
BasicBlockQTB,
BasicBlockQFB,
BasicBlockPostBB,
ValueAddress,
bool InvertPCond,
bool InvertQCond,
DomTreeUpdaterDTU,
constDataLayoutDL,
constTargetTransformInfoTTI 
)
static

Definition at line4327 of fileSimplifyCFG.cpp.

ReferencesAddress,assert(),llvm::IRBuilderBase::CreateNot(),llvm::IRBuilderBase::CreateOr(),llvm::IRBuilderBase::CreateStore(),ensureValueAvailableInSuccessor(),llvm::Instruction::eraseFromParent(),llvm::find(),findUniqueStoreInBlocks(),llvm::Instruction::getAAMetadata(),llvm::StoreInst::getAlign(),llvm::BasicBlock::getFirstInsertionPt(),llvm::IRBuilderBase::GetInsertPoint(),llvm::TargetTransformInfo::getInstructionCost(),llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),llvm::BasicBlock::getSinglePredecessor(),llvm::BasicBlock::getTerminator(),llvm::Value::getType(),llvm::StoreInst::getValueOperand(),I,llvm::BasicBlock::instructionsWithoutDebug(),llvm::StoreInst::isUnordered(),llvm::AAMDNodes::merge(),MergeCondStoresAggressively,PHINodeFoldingThreshold,llvm::pred_begin(),llvm::pred_end(),llvm::IRBuilderBase::SetCurrentDebugLocation(),llvm::IRBuilderBase::SetInsertPoint(),llvm::SplitBlockAndInsertIfThen(),llvm::SplitBlockPredecessors(),llvm::TargetTransformInfo::TCC_Basic, andllvm::TargetTransformInfo::TCK_SizeAndLatency.

Referenced bymergeConditionalStores().

◆ mergeNestedCondBranch()

staticbool mergeNestedCondBranch(BranchInstBI,
DomTreeUpdaterDTU 
)
static

Fold the following pattern: bb0: br i1 cond1, label bb1, label bb2 bb1: br i1 cond2, label bb3, label bb4 bb2: br i1 cond2, label bb4, label bb3 bb3: ... bb4: ... into bb0: cond = xor i1 cond1, cond2 br i1 cond, label bb4, label bb3 bb3: ... bb4: ... NOTE: cond2 always dominates the terminator of bb0.

Definition at line7954 of fileSimplifyCFG.cpp.

Referencesllvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(),llvm::IRBuilderBase::CreateXor(),llvm::DominatorTreeBase< BasicBlock, false >::Delete,llvm::extractBranchWeights(),fitWeights(),llvm::BasicBlock::front(),llvm::BranchInst::getCondition(),llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),llvm::BranchInst::getSuccessor(),llvm::BasicBlock::getTerminator(),llvm::DominatorTreeBase< BasicBlock, false >::Insert,llvm::SmallVectorTemplateBase< T, bool >::push_back(),llvm::BasicBlock::removePredecessor(),setBranchWeights(),llvm::BranchInst::setCondition(), andllvm::BranchInst::setSuccessor().

◆ passingValueIsAlwaysUndefined()

staticbool passingValueIsAlwaysUndefined(ValueV,
InstructionI,
bool PtrValueMayBeModified =false 
)
static

Check if passing a value to an instruction will cause undefined behavior.

Definition at line8167 of fileSimplifyCFG.cpp.

Referencesllvm::any_of(),llvm::CallingConv::C,llvm::find_if(),GEP,I,llvm::isGuaranteedToTransferExecutionToSuccessor(),llvm::PatternMatch::m_BinOp(),llvm::PatternMatch::m_Specific(),llvm::PatternMatch::m_Value(),llvm::make_range(),llvm::PatternMatch::match(),llvm::NullPointerIsDefined(), andpassingValueIsAlwaysUndefined().

Referenced bypassingValueIsAlwaysUndefined(),removeUndefIntroducingPredecessor(), andvalidateAndCostRequiredSelects().

◆ performBranchToCommonDestFolding()

staticbool performBranchToCommonDestFolding(BranchInstBI,
BranchInstPBI,
DomTreeUpdaterDTU,
MemorySSAUpdaterMSSAU,
constTargetTransformInfoTTI 
)
static

Definition at line4010 of fileSimplifyCFG.cpp.

ReferencesaddPredecessorToBlock(),llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(),llvm::SmallVectorTemplateCommon< T, typename >::begin(),llvm::Instruction::cloneDebugInfoFrom(),cloneInstructionsIntoPredecessorBlockAndUpdateSSAUses(),llvm::IRBuilderBase::CollectMetadataToCopy(),createLogicalOp(),llvm::dbgs(),llvm::SmallVectorTemplateCommon< T, typename >::end(),extractPredSuccWeights(),llvm::filterDbgVars(),fitWeights(),llvm::BranchInst::getCondition(),llvm::Instruction::getDbgRecordRange(),llvm::Instruction::getMetadata(),llvm::BasicBlock::getModule(),llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),llvm::BranchInst::getSuccessor(),llvm::BasicBlock::getTerminator(),llvm::InvertBranch(),llvm::BasicBlock::IsNewDbgInfoFormat,LLVM_DEBUG,llvm::SmallVectorTemplateBase< T, bool >::push_back(),llvm::RemapDbgRecord(),llvm::RF_IgnoreMissingLocals,llvm::RF_NoModuleLevelChanges,setBranchWeights(),llvm::BranchInst::setCondition(),llvm::Instruction::setMetadata(),llvm::BranchInst::setSuccessor(), andshouldFoldCondBranchesToCommonDestination().

Referenced byllvm::foldBranchToCommonDest().

◆ reduceSwitchRange()

staticbool reduceSwitchRange(SwitchInstSI,
IRBuilder<> & Builder,
constDataLayoutDL,
constTargetTransformInfoTTI 
)
static

Try to transform a switch that has "holes" in it to a contiguous sequence of cases.

A switch such as: switch(i) {case 5: case 9: case 13: case 17:} can be range-reduced to: switch ((i-5) / 4) {case 0: case 1: case 2: case 3:}.

This converts a sparse switch into a dense switch which allows better lowering and could also allow transforming into a lookup table.

Definition at line7226 of fileSimplifyCFG.cpp.

Referencesassert(),llvm::sampleprof::Base,llvm::CallingConv::C,llvm::countr_zero(),llvm::IRBuilderBase::CreateIntrinsic(),llvm::IRBuilderBase::CreateSub(),DL,isSwitchDense(),llvm::SmallVectorTemplateBase< T, bool >::push_back(),llvm::IRBuilderBase::SetInsertPoint(), andllvm::sort().

◆ removeEmptyCleanup()

staticbool removeEmptyCleanup(CleanupReturnInstRI,
DomTreeUpdaterDTU 
)
static

Definition at line5387 of fileSimplifyCFG.cpp.

Referencesllvm::PHINode::addIncoming(),llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(),assert(),llvm::DeleteDeadBlock(),llvm::PoisonValue::get(),llvm::CleanupReturnInst::getCleanupPad(),llvm::BasicBlock::getFirstNonPHIIt(),llvm::PHINode::getIncomingValueForBlock(),llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(),llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),llvm::Value::getType(),llvm::CleanupReturnInst::getUnwindDest(),llvm::Value::hasOneUse(),Idx,isCleanupBlockEmpty(),llvm::Instruction::isUsedOutsideOfBlock(),llvm::make_early_inc_range(),llvm::Instruction::moveBefore(),llvm::BasicBlock::phis(),pred,llvm::predecessors(),llvm::BasicBlock::removePredecessor(),llvm::removeUnwindEdge(),llvm::User::replaceUsesOfWith(), andllvm::Value::use_empty().

◆ removeSwitchAfterSelectFold()

static void removeSwitchAfterSelectFold(SwitchInstSI,
PHINodePHI,
ValueSelectValue,
IRBuilder<> & Builder,
DomTreeUpdaterDTU 
)
static

Definition at line6384 of fileSimplifyCFG.cpp.

Referencesllvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(),llvm::IRBuilderBase::CreateBr(),Idx,llvm::SmallPtrSetImpl< PtrType >::insert(),llvm::is_contained(),PHI,llvm::predecessors(), andllvm::BasicBlock::removePredecessor().

Referenced bytrySwitchToSelect().

◆ removeUndefIntroducingPredecessor()

staticbool removeUndefIntroducingPredecessor(BasicBlockBB,
DomTreeUpdaterDTU,
AssumptionCacheAC 
)
static

If BB has an incoming value that will always trigger undefined behavior (eg.

null pointer dereference), remove the branch leading here.

Definition at line8309 of fileSimplifyCFG.cpp.

Referencesllvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(),Cond,llvm::BasicBlock::Create(),llvm::IRBuilderBase::CreateAssumption(),llvm::IRBuilderBase::CreateBr(),llvm::IRBuilderBase::CreateNot(),llvm::IRBuilderBase::CreateUnreachable(),llvm::DominatorTreeBase< BasicBlock, false >::Delete,llvm::Instruction::eraseFromParent(),llvm::BranchInst::getCondition(),llvm::BasicBlock::getContext(),llvm::BasicBlock::getParent(),llvm::BranchInst::getSuccessor(),llvm::BasicBlock::getTerminator(),llvm::DominatorTreeBase< BasicBlock, false >::Insert,llvm::BranchInst::isUnconditional(),passingValueIsAlwaysUndefined(),PHI,llvm::BasicBlock::phis(),llvm::AssumptionCache::registerAssumption(),llvm::BasicBlock::removePredecessor(), andllvm::IRBuilderBase::SetInsertPoint().

◆ replacingOperandWithVariableIsCheap()

staticbool replacingOperandWithVariableIsCheap(constInstructionI,
int OpIdx 
)
static

Definition at line2206 of fileSimplifyCFG.cpp.

ReferencesI.

Referenced bycanSinkInstructions().

◆ reuseTableCompare()

static void reuseTableCompare(UserPhiUser,
BasicBlockPhiBlock,
BranchInstRangeCheckBranch,
ConstantDefaultValue,
constSmallVectorImpl< std::pair<ConstantInt *,Constant * > > & Values 
)
static

Try to reuse the switch table index compare.

Following pattern:

if (idx < tablesize)
r = table[idx];// table does not contain default_value
else
r = default_value;
if (r != default_value)
...

Is optimized to:

cond = idx < tablesize;
if (cond)
r = table[idx];
else
r = default_value;
if (cond)
...

Jump threading will then eliminate the second if(cond).

Definition at line6846 of fileSimplifyCFG.cpp.

Referencesllvm::ConstantFoldCompareInstOperands(),DL,llvm::BranchInst::getCondition(),llvm::BasicBlock::getDataLayout(),llvm::ConstantInt::getFalse(),llvm::ilist_node_impl< OptionsT >::getIterator(),llvm::User::getOperand(),llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),llvm::CmpInst::getPredicate(),llvm::ConstantInt::getTrue(),llvm::Value::getType(),llvm::BasicBlock::getUniquePredecessor(),llvm::predecessors(), andllvm::Value::replaceAllUsesWith().

Referenced byswitchToLookupTable().

◆ safeToMergeTerminators()

staticbool safeToMergeTerminators(InstructionSI1,
InstructionSI2,
SmallSetVector<BasicBlock *, 4 > * FailBlocks =nullptr 
)
static

Return true if it is safe to merge these two terminator instructions together.

Definition at line356 of fileSimplifyCFG.cpp.

Referencesllvm::SmallPtrSetImpl< PtrType >::count(),Fail,llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),incomingValuesAreCompatible(),llvm::succ_begin(),llvm::succ_end(), andllvm::successors().

Referenced byllvm::foldBranchToCommonDest().

◆ setBranchWeights()[1/2]

static void setBranchWeights(InstructionI,
uint32_t TrueWeight,
uint32_t FalseWeight,
bool IsExpected 
)
static

Definition at line888 of fileSimplifyCFG.cpp.

Referencesassert(),llvm::MDBuilder::createBranchWeights(),I, andN.

◆ setBranchWeights()[2/2]

static void setBranchWeights(SwitchInstSI,
ArrayRef<uint32_tWeights,
bool IsExpected 
)
static

Definition at line875 of fileSimplifyCFG.cpp.

Referencesllvm::any_of(),llvm::MDBuilder::createBranchWeights(), andN.

Referenced bymergeNestedCondBranch(),performBranchToCommonDestFolding(), andSimplifyCondBranchToCondBranch().

◆ shouldBuildLookupTable()

staticbool shouldBuildLookupTable(SwitchInstSI,
uint64_t TableSize,
constTargetTransformInfoTTI,
constDataLayoutDL,
constSmallDenseMap<PHINode *,Type * > & ResultTypes 
)
static

Determine whether a lookup table should be built for this switch, based on the number of cases, size of the table, and the types of the results.

Definition at line6772 of fileSimplifyCFG.cpp.

ReferencesDL,I,isSwitchDense(), andisTypeLegalForLookupTable().

Referenced byswitchToLookupTable().

◆ shouldFoldCondBranchesToCommonDestination()

static std::optional< std::tuple<BasicBlock *,Instruction::BinaryOps,bool > > shouldFoldCondBranchesToCommonDestination(BranchInstBI,
BranchInstPBI,
constTargetTransformInfoTTI 
)
static

Determine if the two branches share a common destination and deduce a glue that joins the branches' conditions to arrive at the common destination if that would be profitable.

Definition at line3971 of fileSimplifyCFG.cpp.

Referencesassert(),llvm::extractBranchWeights(),llvm::BranchProbability::getBranchProbability(),llvm::BranchProbability::getCompl(),llvm::Instruction::getMetadata(),llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),llvm::TargetTransformInfo::getPredictableBranchThreshold(),llvm::BranchInst::getSuccessor(),llvm::is_contained(),llvm::BranchInst::isConditional(),llvm::BranchProbability::isUnknown(), andllvm::predecessors().

Referenced byllvm::foldBranchToCommonDest(), andperformBranchToCommonDestFolding().

◆ shouldHoistCommonInstructions()

staticbool shouldHoistCommonInstructions(InstructionI1,
InstructionI2,
constTargetTransformInfoTTI 
)
static

Helper function for hoistCommonCodeFromSuccessors.

Return true if identical instructionsI1 andI2 can and should be hoisted.

Definition at line1511 of fileSimplifyCFG.cpp.

Referencesllvm::TargetTransformInfo::isProfitableToHoist().

◆ shouldUseSwitchConditionAsTableIndex()

staticbool shouldUseSwitchConditionAsTableIndex(ConstantIntMinCaseVal,
constConstantIntMaxCaseVal,
bool HasDefaultResults,
constSmallDenseMap<PHINode *,Type * > & ResultTypes,
constDataLayoutDL,
constTargetTransformInfoTTI 
)
static

Definition at line6809 of fileSimplifyCFG.cpp.

Referencesllvm::all_of(),DL,llvm::ConstantInt::getLimitedValue(),llvm::ConstantInt::isNegative(), andllvm::Constant::isNullValue().

Referenced byswitchToLookupTable().

◆ SimplifyCondBranchToCondBranch()

staticbool SimplifyCondBranchToCondBranch(BranchInstPBI,
BranchInstBI,
DomTreeUpdaterDTU,
constDataLayoutDL,
constTargetTransformInfoTTI 
)
static

If we have a conditional branch as a predecessor of another block, this function tries to simplify it.

We know that PBI and BI are both conditional branches, and BI is in one of the successor blocks of PBI - PBI branches to BI.

Definition at line4644 of fileSimplifyCFG.cpp.

ReferencesaddPredecessorToBlock(),llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(),assert(),llvm::BasicBlock::begin(),Cond,llvm::BranchInst::Create(),llvm::BasicBlock::Create(),createLogicalOp(),llvm::IRBuilderBase::CreateNot(),llvm::IRBuilderBase::CreateSelect(),llvm::dbgs(),DL,llvm::extractBranchWeights(),extractPredSuccWeights(),fitWeights(),llvm::PHINode::getBasicBlockIndex(),llvm::BranchProbability::getBranchProbability(),llvm::BranchInst::getCondition(),llvm::BasicBlock::getContext(),llvm::PHINode::getIncomingValue(),llvm::PHINode::getIncomingValueForBlock(),llvm::Type::getInt1Ty(),llvm::Instruction::getMetadata(),llvm::Value::getName(),llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),llvm::BasicBlock::getParent(),llvm::TargetTransformInfo::getPredictableBranchThreshold(),llvm::BasicBlock::getSinglePredecessor(),llvm::BranchInst::getSuccessor(),II,llvm::BasicBlock::instructionsWithoutDebug(),llvm::BranchInst::isConditional(),LLVM_DEBUG,mergeConditionalStores(),MergeCondStores,llvm::BasicBlock::phis(),llvm::SmallVectorTemplateBase< T, bool >::push_back(),setBranchWeights(),llvm::BranchInst::setCondition(),llvm::PHINode::setIncomingValue(),llvm::BranchInst::setSuccessor(), andtryWidenCondBranchToCondBranch().

◆ simplifySwitchOfCmpIntrinsic()

staticbool simplifySwitchOfCmpIntrinsic(SwitchInstSI,
IRBuilderBaseBuilder,
DomTreeUpdaterDTU 
)
static

Fold switch over ucmp/scmp intrinsic to br if two of the switch arms have the same destination.

Definition at line7381 of fileSimplifyCFG.cpp.

Referencesllvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(),assert(),llvm::MDBuilder::createBranchWeights(),llvm::IRBuilderBase::CreateCondBr(),llvm::IRBuilderBase::CreateICmp(),llvm::extractBranchWeights(),llvm::getBranchWeightMDNode(),llvm::ICmpInst::getSignedPredicate(),OtherSucc(),llvm::BasicBlock::removePredecessor(),llvm::SmallVectorImpl< T >::resize(),llvm::IRBuilderBase::SetInsertPoint(),std::swap(), andllvm::APInt::trySExtValue().

◆ simplifySwitchOfPowersOfTwo()

staticbool simplifySwitchOfPowersOfTwo(SwitchInstSI,
IRBuilder<> & Builder,
constDataLayoutDL,
constTargetTransformInfoTTI 
)
static

Tries to transform switch of powers of two to reduce switch range.

For example, switch like: switch (C) { case 1: case 2: case 64: case 128: } will be transformed to: switch (count_trailing_zeros(C)) { case 0: case 1: case 6: case 7: }

This transformation allows better lowering and could allow transforming into a lookup table.

Definition at line7313 of fileSimplifyCFG.cpp.

Referencesllvm::SmallVectorTemplateCommon< T, typename >::back(),llvm::countr_zero(),llvm::IRBuilderBase::CreateIntrinsic(),DL,llvm::SmallVectorTemplateCommon< T, typename >::front(),llvm::TargetTransformInfo::getIntrinsicInstrCost(),llvm::ConstantInt::getTrue(),llvm::Value::getType(),llvm::has_single_bit(),isSwitchDense(),llvm::SmallVectorTemplateBase< T, bool >::push_back(),llvm::IRBuilderBase::SetInsertPoint(),llvm::SmallVectorBase< Size_T >::size(),llvm::sort(),llvm::TargetTransformInfo::TCC_Basic, andllvm::TargetTransformInfo::TCK_SizeAndLatency.

◆ sinkCommonCodeFromPredecessors()

staticbool sinkCommonCodeFromPredecessors(BasicBlockBB,
DomTreeUpdaterDTU 
)
static

Check whether BB's predecessors end with unconditional branches.

If it is true, sink any common code from the predecessors to BB.

Definition at line2442 of fileSimplifyCFG.cpp.

Referencesllvm::all_of(),llvm::any_of(),assert(),canSinkInstructions(),llvm::dbgs(),llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(),llvm::SmallPtrSetImpl< PtrType >::erase(),llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(),llvm::LoadInst::getPointerOperandIndex(),llvm::StoreInst::getPointerOperandIndex(),I,Idx,llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(),llvm::SmallPtrSetImpl< PtrType >::insert(),llvm::IsBlockFollowedByDeoptOrUnreachable(),llvm::isSafeToSpeculativelyExecute(),LLVM_DEBUG,llvm::BasicBlock::phis(),llvm::predecessors(),llvm::SmallVectorTemplateBase< T, bool >::push_back(),sinkLastInstruction(),llvm::SmallVectorBase< Size_T >::size(), andllvm::SplitBlockPredecessors().

◆ sinkLastInstruction()

static void sinkLastInstruction(ArrayRef<BasicBlock * > Blocks)
static

Definition at line2345 of fileSimplifyCFG.cpp.

Referencesllvm::Instruction::andIRFlags(),llvm::any_of(),llvm::Instruction::applyMergedLocation(),assert(),Blocks,llvm::combineMetadataForCSE(),llvm::PHINode::Create(),llvm::SmallVectorTemplateCommon< T, typename >::front(),llvm::BasicBlock::front(),llvm::Instruction::getDebugLoc(),llvm::User::getNumOperands(),llvm::User::getOperand(),llvm::User::getOperandUse(),llvm::BasicBlock::getTerminator(),I,llvm::make_early_inc_range(),llvm::Instruction::moveBefore(),llvm::SmallVectorTemplateBase< T, bool >::push_back(),llvm::Use::set(),llvm::SmallVectorBase< Size_T >::size(),Success, andllvm::Value::users().

Referenced bysinkCommonCodeFromPredecessors().

◆ skippedInstrFlags()

staticunsigned skippedInstrFlags(InstructionI)
static

Definition at line1458 of fileSimplifyCFG.cpp.

ReferencesI,llvm::isGuaranteedToTransferExecutionToSuccessor(),SkipImplicitControlFlow,SkipReadMem, andSkipSideEffect.

◆ STATISTIC()[1/15]

STATISTIC(NumBitMaps ,
"Number of switchinstructions turned into bitmaps"  
)

◆ STATISTIC()[2/15]

STATISTIC(NumFoldBranchToCommonDest ,
"Number ofbranches folded into predecessor basic block"  
)

◆ STATISTIC()[3/15]

STATISTIC(NumFoldValueComparisonIntoPredecessors ,
"Number ofvalue comparisons folded into predecessor basic blocks"  
)

◆ STATISTIC()[4/15]

STATISTIC(NumHoistCommonCode ,
"Number of common instruction 'blocks' hoisted up to the begin block"  
)

◆ STATISTIC()[5/15]

STATISTIC(NumHoistCommonInstrs ,
"Number of commoninstructions hoisted up to the begin block"  
)

◆ STATISTIC()[6/15]

STATISTIC(NumInvokes ,
"Number of invokes with empty resumeblocks simplified into calls"  
)

◆ STATISTIC()[7/15]

STATISTIC(NumInvokeSetsFormed ,
"Number of invoke sets that were formed"  
)

◆ STATISTIC()[8/15]

STATISTIC(NumInvokesMerged ,
"Number of invokes that were merged together"  
)

◆ STATISTIC()[9/15]

STATISTIC(NumLinearMaps ,
"Number of switchinstructions turned into linear mapping"  
)

◆ STATISTIC()[10/15]

STATISTIC(NumLookupTables ,
"Number of switchinstructions turned intolookup tables"  
)

◆ STATISTIC()[11/15]

STATISTIC(NumLookupTablesHoles ,
"Number of switchinstructions turned intolookup tables (holes checked)"  
)

◆ STATISTIC()[12/15]

STATISTIC(NumSinkCommonCode ,
"Number of common instruction 'blocks' sunk down to the end block"  
)

◆ STATISTIC()[13/15]

STATISTIC(NumSinkCommonInstrs ,
"Number of commoninstructions sunk down to the end block"  
)

◆ STATISTIC()[14/15]

STATISTIC(NumSpeculations ,
"Number of speculative executed instructions"  
)

◆ STATISTIC()[15/15]

STATISTIC(NumTableCmpReuses ,
"Number of reused switch tablelookup compares"  
)

◆ switchToLookupTable()

staticbool switchToLookupTable(SwitchInstSI,
IRBuilder<> & Builder,
DomTreeUpdaterDTU,
constDataLayoutDL,
constTargetTransformInfoTTI 
)
static

If the switch is only used to initialize one or more phi nodes in a common successor block with different constant values, replace the switch with lookup tables.

Definition at line6911 of fileSimplifyCFG.cpp.

ReferencesaddPredecessorToBlock(),llvm::all_of(),llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(),assert(),llvm::computeConstantRange(),llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::count(),llvm::BasicBlock::Create(),llvm::IRBuilderBase::CreateBr(),llvm::IRBuilderBase::CreateCondBr(),llvm::IRBuilderBase::CreateICmpULT(),llvm::IRBuilderBase::CreateLShr(),llvm::IRBuilderBase::CreateSub(),llvm::IRBuilderBase::CreateTrunc(),llvm::IRBuilderBase::CreateZExtOrTrunc(),DL,llvm::PoisonValue::get(),getCaseResults(),llvm::Function::getFnAttribute(),llvm::Type::getInt1Ty(),llvm::ConstantInt::getIntegerType(),llvm::APInt::getLimitedValue(),llvm::ConstantInt::getLimitedValue(),llvm::Value::getName(),llvm::GlobalValue::getParent(),llvm::BasicBlock::getParent(),llvm::Type::getPrimitiveSizeInBits(),llvm::Value::getType(),llvm::ConstantRange::getUpper(),llvm::ConstantInt::getValue(),llvm::Attribute::getValueAsBool(),I,Idx,llvm::SmallPtrSetImpl< PtrType >::insert(),llvm::ConstantRange::isUpperWrapped(),Mod,llvm::NextPowerOf2(),PHI,llvm::SmallVectorTemplateBase< T, bool >::push_back(),llvm::BasicBlock::removePredecessor(),Results,reuseTableCompare(),llvm::IRBuilderBase::SetInsertPoint(),llvm::Value::setName(),llvm::APInt::sgt(),shouldBuildLookupTable(),llvm::TargetTransformInfo::shouldBuildLookupTables(),shouldUseSwitchConditionAsTableIndex(),llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::size(),llvm::APInt::slt(),llvm::APInt::ssub_ov(), andUINT64_MAX.

◆ trySwitchToSelect()

staticbool trySwitchToSelect(SwitchInstSI,
IRBuilder<> & Builder,
DomTreeUpdaterDTU,
constDataLayoutDL,
constTargetTransformInfoTTI 
)
static

If a switch is only used to initialize one or more phi nodes in a common successor block with only two different constant values, try to replace the switch with a select.

Returns true if the fold was made.

Definition at line6421 of fileSimplifyCFG.cpp.

Referencesassert(),Cond,DL,foldSwitchToSelect(),initializeUniqueCases(),PHI,removeSwitchAfterSelectFold(), andllvm::IRBuilderBase::SetInsertPoint().

◆ tryToMergeLandingPad()

staticbool tryToMergeLandingPad(LandingPadInstLPad,
BranchInstBI,
BasicBlockBB,
DomTreeUpdaterDTU 
)
static

Given an block with only a single landing pad and a unconditional branch try to find another basic block which this one can be merged with.

This handles cases where we have multiple invokes with unique landing pads, but a shared handler.

We specifically choose to not worry about merging non-empty blocks here. That is a PRE/scheduling problem and is best solved elsewhere. In practice, the optimizer produces empty landing pad blocks quite frequently when dealing with exception dense code. (see: instcombine, gvn, if-else sinking in this file)

This is primarily a code size optimization. We need to avoid performing any transform which might inhibit optimization (such as our ability to specialize a particular handler via tail commoning). We do this by not merging any blocks which require us to introduce a phi. Since the same values are flowing through both blocks, we don't lose any ability to specialize. If anything, we make such specialization more likely.

TODO - This transformation could remove entries from a phi in the target block when the inputs in the phi are the same for the two blocks being merged. In some cases, this could result in removal of the PHI entirely.

Definition at line7805 of fileSimplifyCFG.cpp.

Referencesllvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(),assert(),llvm::BasicBlock::begin(),llvm::IRBuilderBase::CreateUnreachable(),llvm::DominatorTreeBase< BasicBlock, false >::Delete,llvm::Instruction::eraseFromParent(),llvm::BasicBlock::getTerminator(),llvm::BasicBlock::getUniqueSuccessor(),I,II,llvm::DominatorTreeBase< BasicBlock, false >::Insert,llvm::Instruction::isIdenticalTo(),llvm::make_early_inc_range(),llvm::pred_begin(),llvm::pred_end(),llvm::predecessors(),llvm::BasicBlock::removePredecessor(),llvm::succ_begin(), andllvm::succ_end().

◆ tryWidenCondBranchToCondBranch()

staticbool tryWidenCondBranchToCondBranch(BranchInstPBI,
BranchInstBI,
DomTreeUpdaterDTU 
)
static

If the previous block ended with a widenable branch, determine if reusing the target block is profitable and legal.

This will have the effect of "widening" PBI, but doesn't require us to reason about hosting safety.

Definition at line4587 of fileSimplifyCFG.cpp.

Referencesllvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(),llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(),llvm::BranchInst::getSuccessor(),llvm::BasicBlock::getTerminatingDeoptimizeCall(),I,llvm::isWidenableBranch(),llvm::none_of(),llvm::BasicBlock::phis(),llvm::BasicBlock::removePredecessor(),llvm::BranchInst::setSuccessor(), andllvm::succ_empty().

Referenced bySimplifyCondBranchToCondBranch().

◆ validateAndCostRequiredSelects()

staticbool validateAndCostRequiredSelects(BasicBlockBB,
BasicBlockThenBB,
BasicBlockEndBB,
unsignedSpeculatedInstructions,
InstructionCostCost,
constTargetTransformInfoTTI 
)
static

Estimate the cost of the insertion(s) and check that the PHI nodes can be converted to selects.

Definition at line3141 of fileSimplifyCFG.cpp.

Referencesllvm::CmpInst::BAD_ICMP_PREDICATE,computeSpeculationCost(),CostKind,llvm::TargetTransformInfo::getCmpSelInstrCost(),llvm::PHINode::getIncomingValueForBlock(),llvm::BasicBlock::getParent(),llvm::Value::getType(),llvm::Function::hasMinSize(),passingValueIsAlwaysUndefined(),PHINodeFoldingThreshold,llvm::BasicBlock::phis(),llvm::TargetTransformInfo::TCC_Basic,llvm::TargetTransformInfo::TCK_CodeSize, andllvm::TargetTransformInfo::TCK_SizeAndLatency.

◆ validLookupTableConstant()

staticbool validLookupTableConstant(ConstantC,
constTargetTransformInfoTTI 
)
static

Return true if the backend will be able to handle initializing an array of constants like C.

Definition at line6093 of fileSimplifyCFG.cpp.

Referencesllvm::CallingConv::C,llvm::TargetTransformInfo::shouldBuildLookupTablesForConstant(), andvalidLookupTableConstant().

Referenced bygetCaseResults(), andvalidLookupTableConstant().

◆ valuesOverlap()

staticbool valuesOverlap(std::vector< ValueEqualityComparisonCase > & C1,
std::vector< ValueEqualityComparisonCase > & C2 
)
static

Return true if there are any keys in C1 that exist in C2 as well.

Definition at line840 of fileSimplifyCFG.cpp.

Referencesllvm::array_pod_sort(),std::swap(), andllvm::Value::Value().

Variable Documentation

◆ BranchFoldThreshold

cl::opt<unsigned > BranchFoldThreshold("simplifycfg-branch-fold-threshold", cl::Hidden, cl::init(2),cl::desc("Maximum cost of combining conditions when " "folding branches"))("simplifycfg-branch-fold-threshold" ,
cl::Hidden ,
cl::init(2) ,
cl::desc("Maximum cost of combining conditions when " "folding branches")  
)
static

Referenced byllvm::foldBranchToCommonDest().

◆ BranchFoldToCommonDestVectorMultiplier

cl::opt<unsigned > BranchFoldToCommonDestVectorMultiplier("simplifycfg-branch-fold-common-dest-vector-multiplier", cl::Hidden, cl::init(2),cl::desc("Multiplier to apply to threshold when determining whether or not " "tofold branch to common destination whenvectoroperations are " "present"))("simplifycfg-branch-fold-common-dest-vector-multiplier" ,
cl::Hidden ,
cl::init(2) ,
cl::desc("Multiplier to apply to threshold when determining whether or not " "tofold branch to common destination whenvectoroperations are " "present")  
)
static

Referenced byllvm::foldBranchToCommonDest().

◆ EnableMergeCompatibleInvokes

cl::opt<bool > EnableMergeCompatibleInvokes("simplifycfg-merge-compatible-invokes", cl::Hidden, cl::init(true),cl::desc("Allow SimplifyCFG tomerge invokes together when appropriate"))("simplifycfg-merge-compatible-invokes" ,
cl::Hidden ,
cl::init(true,
cl::desc("Allow SimplifyCFG tomerge invokes together when appropriate")  
)
static

Referenced bymergeCompatibleInvokes().

◆ HoistCommon

cl::opt<bool > HoistCommon("simplifycfg-hoist-common", cl::Hidden, cl::init(true),cl::desc("Hoist commoninstructions up to the parent block"))("simplifycfg-hoist-common" ,
cl::Hidden ,
cl::init(true,
cl::desc("Hoist commoninstructions up to the parent block")  
)
static

◆ HoistCommonSkipLimit

cl::opt<unsigned > HoistCommonSkipLimit("simplifycfg-hoist-common-skip-limit", cl::Hidden, cl::init(20),cl::desc("Allow reordering across at most this many " "instructions when hoisting"))("simplifycfg-hoist-common-skip-limit" ,
cl::Hidden ,
cl::init(20) ,
cl::desc("Allow reordering across at most this many " "instructions when hoisting")  
)
static

◆ HoistCondStores

cl::opt<bool > HoistCondStores("simplifycfg-hoist-cond-stores", cl::Hidden, cl::init(true),cl::desc("Hoist conditionalstoresif an unconditional store precedes"))("simplifycfg-hoist-cond-stores" ,
cl::Hidden ,
cl::init(true,
cl::desc("Hoist conditionalstoresif an unconditional store precedes")  
)
static

◆ HoistLoadsStoresWithCondFaulting

cl::opt<bool > HoistLoadsStoresWithCondFaulting("simplifycfg-hoist-loads-stores-with-cond-faulting", cl::Hidden, cl::init(true),cl::desc("Hoistloads/storesif the target supports " "conditional faulting"))("simplifycfg-hoist-loads-stores-with-cond-faulting" ,
cl::Hidden ,
cl::init(true,
cl::desc("Hoistloads/storesif the target supports " "conditional faulting")  
)
static

◆ HoistLoadsStoresWithCondFaultingThreshold

cl::opt<unsigned > HoistLoadsStoresWithCondFaultingThreshold("hoist-loads-stores-with-cond-faulting-threshold", cl::Hidden, cl::init(6),cl::desc("Control the maximal conditionalload/store that we are willing " "to speculatively execute to eliminate conditional branch " "(default = 6)"))("hoist-loads-stores-with-cond-faulting-threshold" ,
cl::Hidden ,
cl::init(6) ,
cl::desc("Control the maximal conditionalload/store that we are willing " "to speculatively execute to eliminate conditional branch " "(default = 6)")  
)
static

◆ MaxSmallBlockSize

cl::opt< int > MaxSmallBlockSize("simplifycfg-max-small-block-size", cl::Hidden, cl::init(10),cl::desc("Max size of ablock which is still considered " "small enough tothread through"))("simplifycfg-max-small-block-size" ,
cl::Hidden ,
cl::init(10) ,
cl::desc("Max size of ablock which is still considered " "small enough tothread through")  
)
static

Referenced byblockIsSimpleEnoughToThreadThrough().

◆ MaxSpeculationDepth

cl::opt<unsigned > MaxSpeculationDepth("max-speculation-depth", cl::Hidden, cl::init(10),cl::desc("Limit maximumrecursion depth when calculating costs of " "speculatively executed instructions"))("max-speculation-depth" ,
cl::Hidden ,
cl::init(10) ,
cl::desc("Limit maximumrecursion depth when calculating costs of " "speculatively executed instructions")  
)
static

Referenced bydominatesMergePoint().

◆ MaxSwitchCasesPerResult

cl::opt<unsigned > MaxSwitchCasesPerResult("max-switch-cases-per-result", cl::Hidden, cl::init(16),cl::desc("Limit cases to analyze when converting a switch to select"))("max-switch-cases-per-result" ,
cl::Hidden ,
cl::init(16) ,
cl::desc("Limit cases to analyze when converting a switch to select")  
)
static

Referenced byinitializeUniqueCases().

◆ MergeCondStores

cl::opt<bool > MergeCondStores("simplifycfg-merge-cond-stores", cl::Hidden, cl::init(true),cl::desc("Hoist conditionalstores evenif an unconditional store does not " "precede -hoist multiple conditionalstores into a single " "predicated store"))("simplifycfg-merge-cond-stores" ,
cl::Hidden ,
cl::init(true,
cl::desc("Hoist conditionalstores evenif an unconditional store does not " "precede -hoist multiple conditionalstores into a single " "predicated store")  
)
static

Referenced bySimplifyCondBranchToCondBranch().

◆ MergeCondStoresAggressively

cl::opt<bool > MergeCondStoresAggressively("simplifycfg-merge-cond-stores-aggressively", cl::Hidden, cl::init(false),cl::desc("When merging conditionalstores, do so evenif the resultant " "basicblocks are unlikely to beif-converted as a result"))("simplifycfg-merge-cond-stores-aggressively" ,
cl::Hidden ,
cl::init(false) ,
cl::desc("When merging conditionalstores, do so evenif the resultant " "basicblocks are unlikely to beif-converted as a result")  
)
static

Referenced bymergeConditionalStoreToAddress().

◆ PHINodeFoldingThreshold

cl::opt<unsigned > PHINodeFoldingThreshold("phi-node-folding-threshold", cl::Hidden, cl::init(2),cl::desc( "Control the amount of phi node folding to perform (default = 2)"))("phi-node-folding-threshold" ,
cl::Hidden ,
cl::init(2) ,
cl::desc( "Control the amount of phi node folding to perform (default = 2)")  
)
static

Referenced bymergeConditionalStoreToAddress(), andvalidateAndCostRequiredSelects().

◆ SinkCommon

cl::opt<bool > SinkCommon("simplifycfg-sink-common", cl::Hidden, cl::init(true),cl::desc("Sink commoninstructions down to the end block"))("simplifycfg-sink-common" ,
cl::Hidden ,
cl::init(true,
cl::desc("Sink commoninstructions down to the end block")  
)
static

◆ SpeculateOneExpensiveInst

cl::opt<bool > SpeculateOneExpensiveInst("speculate-one-expensive-inst", cl::Hidden, cl::init(true),cl::desc("Allow exactly one expensive instruction to be speculatively " "executed"))("speculate-one-expensive-inst" ,
cl::Hidden ,
cl::init(true,
cl::desc("Allow exactly one expensive instruction to be speculatively " "executed")  
)
static

Referenced bydominatesMergePoint().

◆ TwoEntryPHINodeFoldingThreshold

cl::opt<unsigned > TwoEntryPHINodeFoldingThreshold("two-entry-phi-node-folding-threshold", cl::Hidden, cl::init(4),cl::desc("Control the maximal total instruction cost that we are willing " "to speculatively execute tofold a 2-entryPHI node into a " "select (default = 4)"))("two-entry-phi-node-folding-threshold" ,
cl::Hidden ,
cl::init(4) ,
cl::desc("Control the maximal total instruction cost that we are willing " "to speculatively execute tofold a 2-entryPHI node into a " "select (default = 4)")  
)
static

Referenced byfoldTwoEntryPHINode().


Generated on Sun Jul 20 2025 15:03:42 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp