Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
CorrelatedValuePropagation.cpp File Reference

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "correlated-value-propagation"

Enumerations

enum class  Domain { NonNegative , NonPositive , Unknown }

Functions

 STATISTIC (NumPhis, "Number of phis propagated")
 STATISTIC (NumPhiCommon, "Number of phis deleted via common incoming value")
 STATISTIC (NumSelects, "Number of selects propagated")
 STATISTIC (NumCmps, "Number of comparisons propagated")
 STATISTIC (NumReturns, "Number of return values propagated")
 STATISTIC (NumDeadCases, "Number of switch cases removed")
 STATISTIC (NumSDivSRemsNarrowed, "Number of sdivs/srems whose width was decreased")
 STATISTIC (NumSDivs, "Number of sdiv converted to udiv")
 STATISTIC (NumUDivURemsNarrowed, "Number of udivs/urems whose width was decreased")
 STATISTIC (NumAShrsConverted, "Number of ashr converted to lshr")
 STATISTIC (NumAShrsRemoved, "Number of ashr removed")
 STATISTIC (NumSRems, "Number of srem converted to urem")
 STATISTIC (NumSExt, "Number of sext converted to zext")
 STATISTIC (NumSIToFP, "Number of sitofp converted to uitofp")
 STATISTIC (NumSICmps, "Number of signed icmp preds simplified to unsigned")
 STATISTIC (NumAnd, "Number of ands removed")
 STATISTIC (NumNW, "Number of no-wrap deductions")
 STATISTIC (NumNSW, "Number of no-signed-wrap deductions")
 STATISTIC (NumNUW, "Number of no-unsigned-wrap deductions")
 STATISTIC (NumAddNW, "Number of no-wrap deductions for add")
 STATISTIC (NumAddNSW, "Number of no-signed-wrap deductions for add")
 STATISTIC (NumAddNUW, "Number of no-unsigned-wrap deductions for add")
 STATISTIC (NumSubNW, "Number of no-wrap deductions for sub")
 STATISTIC (NumSubNSW, "Number of no-signed-wrap deductions for sub")
 STATISTIC (NumSubNUW, "Number of no-unsigned-wrap deductions for sub")
 STATISTIC (NumMulNW, "Number of no-wrap deductions for mul")
 STATISTIC (NumMulNSW, "Number of no-signed-wrap deductions for mul")
 STATISTIC (NumMulNUW, "Number of no-unsigned-wrap deductions for mul")
 STATISTIC (NumShlNW, "Number of no-wrap deductions for shl")
 STATISTIC (NumShlNSW, "Number of no-signed-wrap deductions for shl")
 STATISTIC (NumShlNUW, "Number of no-unsigned-wrap deductions for shl")
 STATISTIC (NumAbs, "Number of llvm.abs intrinsics removed")
 STATISTIC (NumOverflows, "Number of overflow checks removed")
 STATISTIC (NumSaturating, "Number of saturating arithmetics converted to normal arithmetics")
 STATISTIC (NumNonNull, "Number of function pointer arguments marked non-null")
 STATISTIC (NumCmpIntr, "Number of llvm.[us]cmp intrinsics removed")
 STATISTIC (NumMinMax, "Number of llvm.[us]{min,max} intrinsics removed")
 STATISTIC (NumSMinMax, "Number of llvm.s{min,max} intrinsics simplified to unsigned")
 STATISTIC (NumUDivURemsNarrowedExpanded, "Number of bound udiv's/urem's expanded")
 STATISTIC (NumNNeg, "Number of zext/uitofp non-negative deductions")
static ConstantgetConstantAt (Value *V, Instruction *At, LazyValueInfo *LVI)
static bool processSelect (SelectInst *S, LazyValueInfo *LVI)
static bool simplifyCommonValuePhi (PHINode *P, LazyValueInfo *LVI, DominatorTree *DT)
 Try to simplify a phi with constant incoming values that match the edge values of a non-constant value on all other edges: bb0: isnull = icmp eq i8* x, null br i1 isnull, label bb2, label bb1 bb1: br label bb2 bb2: r = phi i8* [ x, bb1 ], [ null, bb0 ] --> r = x.
static ValuegetValueOnEdge (LazyValueInfo *LVI, Value *Incoming, BasicBlock *From, BasicBlock *To, Instruction *CxtI)
static bool processPHI (PHINode *P, LazyValueInfo *LVI, DominatorTree *DT, const SimplifyQuery &SQ)
static bool processICmp (ICmpInst *Cmp, LazyValueInfo *LVI)
static bool constantFoldCmp (CmpInst *Cmp, LazyValueInfo *LVI)
 See if LazyValueInfo's ability to exploit edge conditions or range information is sufficient to prove this comparison.
static bool processCmp (CmpInst *Cmp, LazyValueInfo *LVI)
static bool processSwitch (SwitchInst *I, LazyValueInfo *LVI, DominatorTree *DT)
 Simplify a switch instruction by removing cases which can never fire.
static bool willNotOverflow (BinaryOpIntrinsic *BO, LazyValueInfo *LVI)
static void setDeducedOverflowingFlags (Value *V, Instruction::BinaryOps Opcode, bool NewNSW, bool NewNUW)
static bool processBinOp (BinaryOperator *BinOp, LazyValueInfo *LVI)
static bool processAbsIntrinsic (IntrinsicInst *II, LazyValueInfo *LVI)
static bool processCmpIntrinsic (CmpIntrinsic *CI, LazyValueInfo *LVI)
static bool processMinMaxIntrinsic (MinMaxIntrinsic *MM, LazyValueInfo *LVI)
static bool processOverflowIntrinsic (WithOverflowInst *WO, LazyValueInfo *LVI)
static bool processSaturatingInst (SaturatingInst *SI, LazyValueInfo *LVI)
static bool processCallSite (CallBase &CB, LazyValueInfo *LVI)
 Infer nonnull attributes for the arguments at the specified callsite.
static Domain getDomain (const ConstantRange &CR)
static bool narrowSDivOrSRem (BinaryOperator *Instr, const ConstantRange &LCR, const ConstantRange &RCR)
 Try to shrink a sdiv/srem's width down to the smallest power of two that's sufficient to contain its operands.
static bool expandUDivOrURem (BinaryOperator *Instr, const ConstantRange &XCR, const ConstantRange &YCR)
static bool narrowUDivOrURem (BinaryOperator *Instr, const ConstantRange &XCR, const ConstantRange &YCR)
 Try to shrink a udiv/urem's width down to the smallest power of two that's sufficient to contain its operands.
static bool processUDivOrURem (BinaryOperator *Instr, LazyValueInfo *LVI)
static bool processSRem (BinaryOperator *SDI, const ConstantRange &LCR, const ConstantRange &RCR, LazyValueInfo *LVI)
static bool processSDiv (BinaryOperator *SDI, const ConstantRange &LCR, const ConstantRange &RCR, LazyValueInfo *LVI)
 See if LazyValueInfo's ability to exploit edge conditions or range information is sufficient to prove the signs of both operands of this SDiv.
static bool processSDivOrSRem (BinaryOperator *Instr, LazyValueInfo *LVI)
static bool processAShr (BinaryOperator *SDI, LazyValueInfo *LVI)
static bool processSExt (SExtInst *SDI, LazyValueInfo *LVI)
static bool processPossibleNonNeg (PossiblyNonNegInst *I, LazyValueInfo *LVI)
static bool processZExt (ZExtInst *ZExt, LazyValueInfo *LVI)
static bool processUIToFP (UIToFPInst *UIToFP, LazyValueInfo *LVI)
static bool processSIToFP (SIToFPInst *SIToFP, LazyValueInfo *LVI)
static bool processAnd (BinaryOperator *BinOp, LazyValueInfo *LVI)
static bool processTrunc (TruncInst *TI, LazyValueInfo *LVI)
static bool runImpl (Function &F, LazyValueInfo *LVI, DominatorTree *DT, const SimplifyQuery &SQ)

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "correlated-value-propagation"

Definition at line 48 of file CorrelatedValuePropagation.cpp.

Enumeration Type Documentation

◆ Domain

enum class Domain
strong
Enumerator
NonNegative 
NonPositive 
Unknown 

Definition at line 756 of file CorrelatedValuePropagation.cpp.

Function Documentation

◆ constantFoldCmp()

bool constantFoldCmp ( CmpInst * Cmp,
LazyValueInfo * LVI )
static

See if LazyValueInfo's ability to exploit edge conditions or range information is sufficient to prove this comparison.

Even for local conditions, this can sometimes prove conditions instcombine can't by exploiting range information.

Definition at line 326 of file CorrelatedValuePropagation.cpp.

References llvm::LazyValueInfo::getPredicateAt().

Referenced by processCmp().

◆ expandUDivOrURem()

◆ getConstantAt()

◆ getDomain()

◆ getValueOnEdge()

◆ narrowSDivOrSRem()

bool narrowSDivOrSRem ( BinaryOperator * Instr,
const ConstantRange & LCR,
const ConstantRange & RCR )
static

Try to shrink a sdiv/srem's width down to the smallest power of two that's sufficient to contain its operands.

Definition at line 768 of file CorrelatedValuePropagation.cpp.

References assert(), B(), llvm::ConstantRange::contains(), llvm::dyn_cast(), llvm::APInt::getAllOnes(), llvm::ConstantRange::getMinSignedBits(), llvm::APInt::getSignedMinValue(), LHS, llvm::PowerOf2Ceil(), and RHS.

Referenced by processSDivOrSRem().

◆ narrowUDivOrURem()

bool narrowUDivOrURem ( BinaryOperator * Instr,
const ConstantRange & XCR,
const ConstantRange & YCR )
static

Try to shrink a udiv/urem's width down to the smallest power of two that's sufficient to contain its operands.

Definition at line 895 of file CorrelatedValuePropagation.cpp.

References assert(), B(), llvm::dyn_cast(), llvm::ConstantRange::getActiveBits(), LHS, llvm::PowerOf2Ceil(), and RHS.

Referenced by processUDivOrURem().

◆ processAbsIntrinsic()

◆ processAnd()

◆ processAShr()

◆ processBinOp()

◆ processCallSite()

◆ processCmp()

bool processCmp ( CmpInst * Cmp,
LazyValueInfo * LVI )
static

Definition at line 340 of file CorrelatedValuePropagation.cpp.

References constantFoldCmp(), llvm::dyn_cast(), and processICmp().

Referenced by runImpl().

◆ processCmpIntrinsic()

◆ processICmp()

◆ processMinMaxIntrinsic()

◆ processOverflowIntrinsic()

◆ processPHI()

bool processPHI ( PHINode * P,
LazyValueInfo * LVI,
DominatorTree * DT,
const SimplifyQuery & SQ )
static

◆ processPossibleNonNeg()

◆ processSaturatingInst()

◆ processSDiv()

bool processSDiv ( BinaryOperator * SDI,
const ConstantRange & LCR,
const ConstantRange & RCR,
LazyValueInfo * LVI )
static

See if LazyValueInfo's ability to exploit edge conditions or range information is sufficient to prove the signs of both operands of this SDiv.

If this is the case, replace the SDiv with a UDiv. Even for local conditions, this can sometimes prove conditions instcombine can't by exploiting range information.

Definition at line 1005 of file CorrelatedValuePropagation.cpp.

References AbstractManglingParser< Derived, Alloc >::Ops, assert(), llvm::BinaryOperator::CreateNeg(), D(), llvm::Instruction::eraseFromParent(), llvm::Instruction::getDebugLoc(), getDomain(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getName(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::ConstantRange::getSingleElement(), llvm::Value::getType(), llvm::Instruction::isExact(), NonNegative, processUDivOrURem(), llvm::Value::replaceAllUsesWith(), llvm::ConstantRange::sdiv(), and Unknown.

Referenced by processSDivOrSRem().

◆ processSDivOrSRem()

bool processSDivOrSRem ( BinaryOperator * Instr,
LazyValueInfo * LVI )
static

◆ processSelect()

◆ processSExt()

◆ processSIToFP()

◆ processSRem()

◆ processSwitch()

bool processSwitch ( SwitchInst * I,
LazyValueInfo * LVI,
DominatorTree * DT )
static

Simplify a switch instruction by removing cases which can never fire.

If the uselessness of a case could be determined locally then constant propagation would already have figured it out. Instead, walk the predecessors and statically evaluate cases based on information available on that edge. Cases that cannot fire no matter what the incoming edge can safely be removed. If a case fires on every incoming edge then the entire switch can be removed and replaced with a branch to the case destination.

Definition at line 358 of file CorrelatedValuePropagation.cpp.

References llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdates(), llvm::GenericDomTreeUpdater< DerivedT, DomTreeT, PostDomTreeT >::applyUpdatesPermissive(), Changed, Cond, llvm::ConstantFoldTerminator(), llvm::ConstantRange::contains(), llvm::BasicBlock::Create(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::dyn_cast_or_null(), llvm::LazyValueInfo::getConstantRangeAtUse(), llvm::BasicBlock::getContext(), llvm::BasicBlock::getParent(), llvm::LazyValueInfo::getPredicateAt(), llvm::ConstantRange::getSingleElement(), llvm::DebugLoc::getTemporary(), llvm::ConstantInt::getValue(), I, llvm::CmpInst::ICMP_EQ, llvm::DominatorTreeBase< BasicBlock, false >::Insert, llvm::ConstantRange::isSingleElement(), llvm::ConstantRange::isSizeLargerThan(), llvm::BasicBlock::removePredecessor(), and llvm::successors().

Referenced by runImpl().

◆ processTrunc()

◆ processUDivOrURem()

bool processUDivOrURem ( BinaryOperator * Instr,
LazyValueInfo * LVI )
static

◆ processUIToFP()

bool processUIToFP ( UIToFPInst * UIToFP,
LazyValueInfo * LVI )
static

Definition at line 1148 of file CorrelatedValuePropagation.cpp.

References llvm::cast(), and processPossibleNonNeg().

Referenced by runImpl().

◆ processZExt()

bool processZExt ( ZExtInst * ZExt,
LazyValueInfo * LVI )
static

Definition at line 1144 of file CorrelatedValuePropagation.cpp.

References llvm::cast(), and processPossibleNonNeg().

Referenced by runImpl().

◆ runImpl()

◆ setDeducedOverflowingFlags()

void setDeducedOverflowingFlags ( Value * V,
Instruction::BinaryOps Opcode,
bool NewNSW,
bool NewNUW )
static

◆ simplifyCommonValuePhi()

bool simplifyCommonValuePhi ( PHINode * P,
LazyValueInfo * LVI,
DominatorTree * DT )
static

Try to simplify a phi with constant incoming values that match the edge values of a non-constant value on all other edges: bb0: isnull = icmp eq i8* x, null br i1 isnull, label bb2, label bb1 bb1: br label bb2 bb2: r = phi i8* [ x, bb1 ], [ null, bb0 ] --> r = x.

Definition at line 155 of file CorrelatedValuePropagation.cpp.

References llvm::CallingConv::C, llvm::DominatorTree::dominates(), llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::LazyValueInfo::getConstantOnEdge(), llvm::isGuaranteedNotToBePoison(), P, and llvm::SmallVectorTemplateBase< T, bool >::push_back().

Referenced by processPHI().

◆ STATISTIC() [1/40]

STATISTIC ( NumAbs ,
"Number of llvm.abs intrinsics removed"  )

◆ STATISTIC() [2/40]

STATISTIC ( NumAddNSW ,
"Number of no-signed-wrap deductions for add"  )

◆ STATISTIC() [3/40]

STATISTIC ( NumAddNUW ,
"Number of no-unsigned-wrap deductions for add"  )

◆ STATISTIC() [4/40]

STATISTIC ( NumAddNW ,
"Number of no-wrap deductions for add"  )

◆ STATISTIC() [5/40]

STATISTIC ( NumAnd ,
"Number of ands removed"  )

◆ STATISTIC() [6/40]

STATISTIC ( NumAShrsConverted ,
"Number of ashr converted to lshr"  )

◆ STATISTIC() [7/40]

STATISTIC ( NumAShrsRemoved ,
"Number of ashr removed"  )

◆ STATISTIC() [8/40]

STATISTIC ( NumCmpIntr ,
"Number of llvm.cmp intrinsics removed" [us] )

◆ STATISTIC() [9/40]

STATISTIC ( NumCmps ,
"Number of comparisons propagated"  )

◆ STATISTIC() [10/40]

STATISTIC ( NumDeadCases ,
"Number of switch cases removed"  )

◆ STATISTIC() [11/40]

STATISTIC ( NumMinMax ,
"Number of llvm.{min,max} intrinsics removed" [us] )

◆ STATISTIC() [12/40]

STATISTIC ( NumMulNSW ,
"Number of no-signed-wrap deductions for mul"  )

◆ STATISTIC() [13/40]

STATISTIC ( NumMulNUW ,
"Number of no-unsigned-wrap deductions for mul"  )

◆ STATISTIC() [14/40]

STATISTIC ( NumMulNW ,
"Number of no-wrap deductions for mul"  )

◆ STATISTIC() [15/40]

STATISTIC ( NumNNeg ,
"Number of zext/uitofp non-negative deductions"  )

◆ STATISTIC() [16/40]

STATISTIC ( NumNonNull ,
"Number of function pointer arguments marked non-null"  )

◆ STATISTIC() [17/40]

STATISTIC ( NumNSW ,
"Number of no-signed-wrap deductions"  )

◆ STATISTIC() [18/40]

STATISTIC ( NumNUW ,
"Number of no-unsigned-wrap deductions"  )

◆ STATISTIC() [19/40]

STATISTIC ( NumNW ,
"Number of no-wrap deductions"  )

◆ STATISTIC() [20/40]

STATISTIC ( NumOverflows ,
"Number of overflow checks removed"  )

◆ STATISTIC() [21/40]

STATISTIC ( NumPhiCommon ,
"Number of phis deleted via common incoming value"  )

◆ STATISTIC() [22/40]

STATISTIC ( NumPhis ,
"Number of phis propagated"  )

◆ STATISTIC() [23/40]

STATISTIC ( NumReturns ,
"Number of return values propagated"  )

◆ STATISTIC() [24/40]

STATISTIC ( NumSaturating ,
"Number of saturating arithmetics converted to normal arithmetics"  )

◆ STATISTIC() [25/40]

STATISTIC ( NumSDivs ,
"Number of sdiv converted to udiv"  )

◆ STATISTIC() [26/40]

STATISTIC ( NumSDivSRemsNarrowed ,
"Number of sdivs/srems whose width was decreased"  )

◆ STATISTIC() [27/40]

STATISTIC ( NumSelects ,
"Number of selects propagated"  )

◆ STATISTIC() [28/40]

STATISTIC ( NumSExt ,
"Number of sext converted to zext"  )

◆ STATISTIC() [29/40]

STATISTIC ( NumShlNSW ,
"Number of no-signed-wrap deductions for shl"  )

◆ STATISTIC() [30/40]

STATISTIC ( NumShlNUW ,
"Number of no-unsigned-wrap deductions for shl"  )

◆ STATISTIC() [31/40]

STATISTIC ( NumShlNW ,
"Number of no-wrap deductions for shl"  )

◆ STATISTIC() [32/40]

STATISTIC ( NumSICmps ,
"Number of signed icmp preds simplified to unsigned"  )

◆ STATISTIC() [33/40]

STATISTIC ( NumSIToFP ,
"Number of sitofp converted to uitofp"  )

◆ STATISTIC() [34/40]

STATISTIC ( NumSMinMax ,
"Number of llvm.s{min,max} intrinsics simplified to unsigned"  )

◆ STATISTIC() [35/40]

STATISTIC ( NumSRems ,
"Number of srem converted to urem"  )

◆ STATISTIC() [36/40]

STATISTIC ( NumSubNSW ,
"Number of no-signed-wrap deductions for sub"  )

◆ STATISTIC() [37/40]

STATISTIC ( NumSubNUW ,
"Number of no-unsigned-wrap deductions for sub"  )

◆ STATISTIC() [38/40]

STATISTIC ( NumSubNW ,
"Number of no-wrap deductions for sub"  )

◆ STATISTIC() [39/40]

STATISTIC ( NumUDivURemsNarrowed ,
"Number of udivs/urems whose width was decreased"  )

◆ STATISTIC() [40/40]

STATISTIC ( NumUDivURemsNarrowedExpanded ,
"Number of bound udiv's/urem's expanded"  )

◆ willNotOverflow()