LLVM 22.0.0git
InstCombineAddSub.cpp File Reference

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "instcombine"

Functions

static ValuecheckForNegativeOperand (BinaryOperator &I, InstCombiner::BuilderTy &Builder)
static InstructionfoldNoWrapAdd (BinaryOperator &Add, InstCombiner::BuilderTy &Builder)
 Wrapping flags may allow combining constants separated by an extend.
template<bool FP, typename Mul2Rhs>
static bool matchesSquareSum (BinaryOperator &I, Mul2Rhs M2Rhs, Value *&A, Value *&B)
static bool MatchMul (Value *E, Value *&Op, APInt &C)
static bool MatchRem (Value *E, Value *&Op, APInt &C, bool &IsSigned)
static bool MatchDiv (Value *E, Value *&Op, APInt &C, bool IsSigned)
static bool MulWillOverflow (APInt &C0, APInt &C1, bool IsSigned)
static InstructioncanonicalizeLowbitMask (BinaryOperator &I, InstCombiner::BuilderTy &Builder)
 Fold (1 << NBits) - 1 Into: ~(-(1 << NBits)) Because a 'not' is better for bit-tracking analysis and other transforms than an 'add'.
static InstructionfoldToUnsignedSaturatedAdd (BinaryOperator &I)
static InstructioncombineAddSubWithShlAddSub (InstCombiner::BuilderTy &Builder, const BinaryOperator &I)
static InstructionfoldAddToAshr (BinaryOperator &Add)
 Try to reduce signed division by power-of-2 to an arithmetic shift right.
static InstructionfactorizeMathWithShlOps (BinaryOperator &I, InstCombiner::BuilderTy &Builder)
 This is a specialization of a more general transform from foldUsingDistributiveLaws.
static InstructionfoldBoxMultiply (BinaryOperator &I)
 Reduce a sequence of masked half-width multiplies to a single multiply.
static InstructionfactorizeLerp (BinaryOperator &I, InstCombiner::BuilderTy &Builder)
 Eliminate an op from a linear interpolation (lerp) pattern.
static InstructionfactorizeFAddFSub (BinaryOperator &I, InstCombiner::BuilderTy &Builder)
 Factor a common operand out of fadd/fsub of fmul/fdiv.
static InstructionfoldSubOfMinMax (BinaryOperator &I, InstCombiner::BuilderTy &Builder)
static InstructionfoldFNegIntoConstant (Instruction &I, const DataLayout &DL)
 This eliminates floating-point negation in either 'fneg(X)' or 'fsub(-0.0, X)' form by combining into a constant operand.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "instcombine"

Definition at line 39 of file InstCombineAddSub.cpp.

Function Documentation

◆ canonicalizeLowbitMask()

Instruction * canonicalizeLowbitMask ( BinaryOperator & I,
InstCombiner::BuilderTy & Builder )
static

Fold (1 << NBits) - 1 Into: ~(-(1 << NBits)) Because a 'not' is better for bit-tracking analysis and other transforms than an 'add'.

The new shl is always nsw, and is nuw if old and was.

Definition at line 1221 of file InstCombineAddSub.cpp.

References llvm::BinaryOperator::CreateNot(), llvm::dyn_cast(), llvm::Constant::getAllOnesValue(), llvm::Value::getType(), I, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_One(), llvm::MIPatternMatch::m_OneUse(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Value(), and llvm::PatternMatch::match().

Referenced by llvm::InstCombinerImpl::visitAdd().

◆ checkForNegativeOperand()

◆ combineAddSubWithShlAddSub()

◆ factorizeFAddFSub()

◆ factorizeLerp()

◆ factorizeMathWithShlOps()

Instruction * factorizeMathWithShlOps ( BinaryOperator & I,
InstCombiner::BuilderTy & Builder )
static

This is a specialization of a more general transform from foldUsingDistributiveLaws.

If that code can be made to work optimally for multi-use cases or propagating nsw/nuw, then we would not need this.

Definition at line 1446 of file InstCombineAddSub.cpp.

References assert(), llvm::dyn_cast(), I, llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), X, and Y.

Referenced by llvm::InstCombinerImpl::visitAdd(), and llvm::InstCombinerImpl::visitSub().

◆ foldAddToAshr()

◆ foldBoxMultiply()

◆ foldFNegIntoConstant()

◆ foldNoWrapAdd()

◆ foldSubOfMinMax()

◆ foldToUnsignedSaturatedAdd()

◆ MatchDiv()

◆ matchesSquareSum()

◆ MatchMul()

◆ MatchRem()

◆ MulWillOverflow()

bool MulWillOverflow ( APInt & C0,
APInt & C1,
bool IsSigned )
static