LLVM 20.0.0git
Macros | Functions
InstCombineAddSub.cpp File Reference
#include "InstCombineInternal.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/AlignOf.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Transforms/InstCombine/InstCombiner.h"
#include <cassert>
#include <utility>

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()

static 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 1219 of file InstCombineAddSub.cpp.

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

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

◆ checkForNegativeOperand()

static Value * checkForNegativeOperand ( BinaryOperator I,
InstCombiner::BuilderTy Builder 
)
static

◆ combineAddSubWithShlAddSub()

static Instruction * combineAddSubWithShlAddSub ( InstCombiner::BuilderTy Builder,
const BinaryOperator I 
)
static

◆ factorizeFAddFSub()

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

◆ factorizeLerp()

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

◆ factorizeMathWithShlOps()

static 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 1432 of file InstCombineAddSub.cpp.

References assert(), llvm::IRBuilderBase::CreateBinOp(), 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()

static Instruction * foldAddToAshr ( BinaryOperator Add)
static

◆ foldBoxMultiply()

static Instruction * foldBoxMultiply ( BinaryOperator I)
static

◆ foldFNegIntoConstant()

static Instruction * foldFNegIntoConstant ( Instruction I,
const DataLayout DL 
)
static

◆ foldNoWrapAdd()

static Instruction * foldNoWrapAdd ( BinaryOperator Add,
InstCombiner::BuilderTy Builder 
)
static

◆ foldSubOfMinMax()

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

◆ foldToUnsignedSaturatedAdd()

static Instruction * foldToUnsignedSaturatedAdd ( BinaryOperator I)
static

◆ MatchDiv()

static bool MatchDiv ( Value E,
Value *&  Op,
APInt C,
bool  IsSigned 
)
static

◆ matchesSquareSum()

template<bool FP, typename Mul2Rhs >
static bool matchesSquareSum ( BinaryOperator I,
Mul2Rhs  M2Rhs,
Value *&  A,
Value *&  B 
)
static

◆ MatchMul()

static bool MatchMul ( Value E,
Value *&  Op,
APInt C 
)
static

◆ MatchRem()

static bool MatchRem ( Value E,
Value *&  Op,
APInt C,
bool IsSigned 
)
static

◆ MulWillOverflow()

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