LLVM  14.0.0git
Macros | Functions
InstCombineShifts.cpp File Reference
#include "InstCombineInternal.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/Transforms/InstCombine/InstCombiner.h"
Include dependency graph for InstCombineShifts.cpp:

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 InstructionfoldShiftOfShiftedLogic (BinaryOperator &I, InstCombiner::BuilderTy &Builder)
 If we have a shift-by-constant of a bitwise logic op 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. More...
 
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. More...
 
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. More...
 
static ValuefoldShiftedShift (BinaryOperator *InnerShift, unsigned OuterShAmt, bool IsOuterShl, InstCombiner::BuilderTy &Builder)
 Fold OuterShift (InnerShift X, C1), C2. More...
 
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. More...
 
static bool canShiftBinOpWithConstantRHS (BinaryOperator &Shift, BinaryOperator *BO)
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "instcombine"

Definition at line 22 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 482 of file InstCombineShifts.cpp.

References canEvaluateShiftedShift(), llvm::tgtok::FalseVal, I, llvm::PHINode::incoming_values(), llvm::MCID::Select, SI, and llvm::tgtok::TrueVal.

Referenced by 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

◆ foldShiftOfShiftedLogic()

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

If we have a shift-by-constant of a bitwise logic op 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 a use of an intermediate value (reduces dependency chain).

Definition at line 330 of file InstCombineShifts.cpp.

References assert(), Builder, C1, llvm::BinaryOperator::Create(), llvm::ConstantExpr::getAdd(), llvm::Type::getScalarSizeInBits(), I, llvm::CmpInst::ICMP_ULT, llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Shift(), llvm::PatternMatch::m_SpecificInt_ICMP(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), Threshold, X, and Y.

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

◆ getShiftedValue()

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