LLVM 20.0.0git
Macros | Functions
InstCombineShifts.cpp File Reference
#include "InstCombineInternal.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/Transforms/InstCombine/InstCombiner.h"

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "instcombine"
 

Functions

bool canTryToConstantAddTwoShiftAmounts (Value *Sh0, Value *ShAmt0, Value *Sh1, Value *ShAmt1)
 
static InstructiondropRedundantMaskingOfLeftShiftInput (BinaryOperator *OuterShift, const SimplifyQuery &Q, InstCombiner::BuilderTy &Builder)
 
static InstructionfoldShiftOfShiftedBinOp (BinaryOperator &I, InstCombiner::BuilderTy &Builder)
 If we have a shift-by-constant of a bin op (bitwise logic op or add/sub w/ shl) that itself has a shift-by-constant operand with identical opcode, we may be able to convert that into 2 independent shifts followed by the logic op.
 
static bool canEvaluateShiftedShift (unsigned OuterShAmt, bool IsOuterShl, Instruction *InnerShift, InstCombinerImpl &IC, Instruction *CxtI)
 Return true if we can simplify two logical (either left or right) shifts that have constant shift amounts: OuterShift (InnerShift X, C1), C2.
 
static bool canEvaluateShifted (Value *V, unsigned NumBits, bool IsLeftShift, InstCombinerImpl &IC, Instruction *CxtI)
 See if we can compute the specified value, but shifted logically to the left or right by some number of bits.
 
static ValuefoldShiftedShift (BinaryOperator *InnerShift, unsigned OuterShAmt, bool IsOuterShl, InstCombiner::BuilderTy &Builder)
 Fold OuterShift (InnerShift X, C1), C2.
 
static ValuegetShiftedValue (Value *V, unsigned NumBits, bool isLeftShift, InstCombinerImpl &IC, const DataLayout &DL)
 When canEvaluateShifted() returns true for an expression, this function inserts the new computation that produces the shifted value.
 
static bool canShiftBinOpWithConstantRHS (BinaryOperator &Shift, BinaryOperator *BO)
 
static bool setShiftFlags (BinaryOperator &I, const SimplifyQuery &Q)
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "instcombine"

Definition at line 21 of file InstCombineShifts.cpp.

Function Documentation

◆ canEvaluateShifted()

static bool canEvaluateShifted ( Value V,
unsigned  NumBits,
bool  IsLeftShift,
InstCombinerImpl IC,
Instruction CxtI 
)
static

See if we can compute the specified value, but shifted logically to the left or right by some number of bits.

This should return true if the expression can be computed for the same cost as the current expression tree. This is used to eliminate extraneous shifting from things like: C = shl i128 A, 64 D = shl i128 B, 96 E = or i128 C, D F = lshr i128 E, 64 where the client will ask if E can be computed shifted right by 64-bits. If this succeeds, getShiftedValue() will be called to produce the value.

Definition at line 586 of file InstCombineShifts.cpp.

References canEvaluateShifted(), canEvaluateShiftedShift(), llvm::APInt::countr_zero(), I, llvm::PHINode::incoming_values(), llvm::APInt::isNegatedPowerOf2(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_ImmConstant(), and llvm::PatternMatch::match().

Referenced by canEvaluateShifted(), and llvm::InstCombinerImpl::FoldShiftByConstant().

◆ canEvaluateShiftedShift()

static bool canEvaluateShiftedShift ( unsigned  OuterShAmt,
bool  IsOuterShl,
Instruction InnerShift,
InstCombinerImpl IC,
Instruction CxtI 
)
static

◆ canShiftBinOpWithConstantRHS()

static bool canShiftBinOpWithConstantRHS ( BinaryOperator Shift,
BinaryOperator BO 
)
static

◆ canTryToConstantAddTwoShiftAmounts()

bool canTryToConstantAddTwoShiftAmounts ( Value Sh0,
Value ShAmt0,
Value Sh1,
Value ShAmt1 
)

◆ dropRedundantMaskingOfLeftShiftInput()

static Instruction * dropRedundantMaskingOfLeftShiftInput ( BinaryOperator OuterShift,
const SimplifyQuery Q,
InstCombiner::BuilderTy Builder 
)
static

◆ foldShiftedShift()

static Value * foldShiftedShift ( BinaryOperator InnerShift,
unsigned  OuterShAmt,
bool  IsOuterShl,
InstCombiner::BuilderTy Builder 
)
static

◆ foldShiftOfShiftedBinOp()

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

If we have a shift-by-constant of a bin op (bitwise logic op or add/sub w/ shl) that itself has a shift-by-constant operand with identical opcode, we may be able to convert that into 2 independent shifts followed by the logic op.

This eliminates a use of an intermediate value (reduces dependency chain).

Definition at line 348 of file InstCombineShifts.cpp.

References assert(), llvm::BinaryOperator::Create(), llvm::IRBuilderBase::CreateBinOp(), llvm::ConstantExpr::getAdd(), llvm::Type::getScalarSizeInBits(), I, llvm::CmpInst::ICMP_ULT, llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_SpecificInt_ICMP(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), Size, X, and Y.

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

◆ getShiftedValue()

static Value * getShiftedValue ( Value V,
unsigned  NumBits,
bool  isLeftShift,
InstCombinerImpl IC,
const DataLayout DL 
)
static

◆ setShiftFlags()

static bool setShiftFlags ( BinaryOperator I,
const SimplifyQuery Q 
)
static