|
LLVM
3.7.0
|
#include "InstCombineInternal.h"#include "llvm/Analysis/ConstantFolding.h"#include "llvm/IR/DataLayout.h"#include "llvm/IR/PatternMatch.h"#include "llvm/Analysis/TargetLibraryInfo.h"Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "instcombine" |
Functions | |
| static Value * | DecomposeSimpleLinearExpr (Value *Val, unsigned &Scale, uint64_t &Offset) |
| DecomposeSimpleLinearExpr - Analyze 'Val', seeing if it is a simple linear expression. More... | |
| static Instruction::CastOps | isEliminableCastPair (const CastInst *CI, unsigned opcode, Type *DstTy, const DataLayout &DL) |
| This function is a wrapper around CastInst::isEliminableCastPair. More... | |
| static bool | CanEvaluateTruncated (Value *V, Type *Ty, InstCombiner &IC, Instruction *CxtI) |
| CanEvaluateTruncated - Return true if we can evaluate the specified expression tree as type Ty instead of its larger type, and arrive with the same value. More... | |
| static bool | CanEvaluateZExtd (Value *V, Type *Ty, unsigned &BitsToClear, InstCombiner &IC, Instruction *CxtI) |
| CanEvaluateZExtd - Determine if the specified value can be computed in the specified wider type and produce the same low bits. More... | |
| static bool | CanEvaluateSExtd (Value *V, Type *Ty) |
| CanEvaluateSExtd - Return true if we can take the specified value and return it as type Ty without inserting any new casts and without changing the value of the common low bits. More... | |
| static Constant * | FitsInFPType (ConstantFP *CFP, const fltSemantics &Sem) |
| FitsInFPType - Return a Constant* for the specified FP constant if it fits in the specified FP type without changing its value. More... | |
| static Value * | LookThroughFPExtensions (Value *V) |
| LookThroughFPExtensions - If this is an fp extension instruction, look through it until we get the source value. More... | |
| static Instruction * | OptimizeVectorResize (Value *InVal, VectorType *DestTy, InstCombiner &IC) |
| OptimizeVectorResize - This input value (which is known to have vector type) is being zero extended or truncated to the specified vector type. More... | |
| static bool | isMultipleOfTypeSize (unsigned Value, Type *Ty) |
| static unsigned | getTypeSizeIndex (unsigned Value, Type *Ty) |
| static bool | CollectInsertionElements (Value *V, unsigned Shift, SmallVectorImpl< Value * > &Elements, Type *VecEltTy, bool isBigEndian) |
| CollectInsertionElements - V is a value which is inserted into a vector of VecEltTy. More... | |
| static Value * | OptimizeIntegerToVectorInsertions (BitCastInst &CI, InstCombiner &IC) |
| OptimizeIntegerToVectorInsertions - If the input is an 'or' instruction, we may be doing shifts and ors to assemble the elements of the vector manually. More... | |
| static Instruction * | OptimizeIntToFloatBitCast (BitCastInst &CI, InstCombiner &IC, const DataLayout &DL) |
| OptimizeIntToFloatBitCast - See if we can optimize an integer->float/double bitcast. More... | |
| #define DEBUG_TYPE "instcombine" |
Definition at line 22 of file InstCombineCasts.cpp.
CanEvaluateSExtd - Return true if we can take the specified value and return it as type Ty without inserting any new casts and without changing the value of the common low bits.
This is used by code that tries to promote integer operations to a wider types will allow us to eliminate the extension.
This function works on both vectors and scalars.
Definition at line 996 of file InstCombineCasts.cpp.
References llvm::APIntOps::And(), llvm::dyn_cast(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::Value::hasOneUse(), I, llvm::PHINode::incoming_values(), llvm::APIntOps::Or(), llvm::TargetOpcode::PHI, llvm::MCID::Select, and llvm::APIntOps::Xor().
Referenced by llvm::InstCombiner::visitSExt().
|
static |
CanEvaluateTruncated - Return true if we can evaluate the specified expression tree as type Ty instead of its larger type, and arrive with the same value.
This is used by code that tries to eliminate truncates.
Ty will always be a type smaller than V. We should return true if trunc(V) can be computed by computing V in the smaller type. If V is an instruction, then trunc(inst(x,y)) can be computed as inst(trunc(x),trunc(y)), which only makes sense if x and y can be efficiently truncated.
This function works on both vectors and scalars.
Definition at line 332 of file InstCombineCasts.cpp.
References llvm::APIntOps::And(), llvm::dyn_cast(), llvm::SelectInst::getFalseValue(), llvm::APInt::getHighBitsSet(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::SelectInst::getTrueValue(), llvm::Value::getType(), llvm::Value::hasOneUse(), I, llvm::PHINode::incoming_values(), llvm::APIntOps::Or(), llvm::TargetOpcode::PHI, llvm::MCID::Select, SI, and llvm::APIntOps::Xor().
Referenced by CanEvaluateShifted(), and llvm::InstCombiner::visitTrunc().
|
static |
CanEvaluateZExtd - Determine if the specified value can be computed in the specified wider type and produce the same low bits.
If not, return false.
If this function returns true, it can also return a non-zero number of bits (in BitsToClear) which indicates that the value it computes is correct for the zero extend, but that the additional BitsToClear bits need to be zero'd out. For example, to promote something like:
B = trunc i64 A to i32 C = lshr i32 B, 8 E = zext i32 C to i64
CanEvaluateZExtd for the 'lshr' will return true, and BitsToClear will be set to 8 to indicate that the promoted value needs to have bits 24-31 cleared in addition to bits 32-63. Since an 'and' will be generated to clear the top bits anyway, doing this has no extra cost.
This function works on both vectors and scalars.
Definition at line 658 of file InstCombineCasts.cpp.
References llvm::APIntOps::And(), llvm::dyn_cast(), llvm::APInt::getHighBitsSet(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::Value::getType(), llvm::Value::hasOneUse(), I, llvm::APIntOps::Or(), llvm::TargetOpcode::PHI, llvm::MCID::Select, and llvm::APIntOps::Xor().
Referenced by llvm::InstCombiner::visitZExt().
|
static |
CollectInsertionElements - V is a value which is inserted into a vector of VecEltTy.
Look through the value to see if we can decompose it into insertions into the vector. See the example in the comment for OptimizeIntegerToVectorInsertions for the pattern this handles. The type of V is always a non-zero multiple of VecEltTy's size. Shift is the number of bits between the lsb of V and the lsb of the vector.
This returns false if the pattern can't be matched or true if it can, filling in Elements with the elements found here.
Definition at line 1561 of file InstCombineCasts.cpp.
References llvm::dyn_cast(), llvm::IntegerType::get(), llvm::ConstantInt::get(), llvm::ConstantExpr::getBitCast(), llvm::Value::getContext(), llvm::ConstantExpr::getLShr(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Type::getPrimitiveSizeInBits(), llvm::ConstantExpr::getTrunc(), llvm::Value::getType(), getTypeSizeIndex(), llvm::ConstantInt::getZExtValue(), llvm::Value::hasOneUse(), isMultipleOfTypeSize(), llvm::APIntOps::Or(), and llvm::SmallVectorTemplateCommon< T >::size().
Referenced by OptimizeIntegerToVectorInsertions().
DecomposeSimpleLinearExpr - Analyze 'Val', seeing if it is a simple linear expression.
If so, decompose it, returning some value X, such that Val is X*Scale+Offset.
Definition at line 28 of file InstCombineCasts.cpp.
References llvm::dyn_cast(), llvm::ConstantInt::get(), llvm::Value::getType(), llvm::OverflowingBinaryOperator::hasNoSignedWrap(), llvm::OverflowingBinaryOperator::hasNoUnsignedWrap(), and I.
|
static |
FitsInFPType - Return a Constant* for the specified FP constant if it fits in the specified FP type without changing its value.
Definition at line 1154 of file InstCombineCasts.cpp.
References llvm::APFloat::convert(), F(), llvm::ConstantFP::get(), llvm::Value::getContext(), llvm::ConstantFP::getValueAPF(), and llvm::APFloat::rmNearestTiesToEven.
Referenced by LookThroughFPExtensions().
Definition at line 1547 of file InstCombineCasts.cpp.
References llvm::Type::getPrimitiveSizeInBits().
Referenced by CollectInsertionElements().
|
static |
This function is a wrapper around CastInst::isEliminableCastPair.
It simply extracts arguments and returns what that function returns.
| CI | First cast instruction |
| opcode | Opcode for the second cast |
| DstTy | Target type for the second cast |
Definition at line 235 of file InstCombineCasts.cpp.
References llvm::DataLayout::getIntPtrType(), llvm::CastInst::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), llvm::CastInst::isEliminableCastPair(), and llvm::Type::isPtrOrPtrVectorTy().
Referenced by llvm::InstCombiner::commonCastTransforms().
Definition at line 1543 of file InstCombineCasts.cpp.
References llvm::Type::getPrimitiveSizeInBits().
Referenced by CollectInsertionElements().
LookThroughFPExtensions - If this is an fp extension instruction, look through it until we get the source value.
Definition at line 1165 of file InstCombineCasts.cpp.
References FitsInFPType(), llvm::Value::getContext(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Type::getPPC_FP128Ty(), llvm::APFloat::IEEEdouble, llvm::APFloat::IEEEhalf, and llvm::APFloat::IEEEsingle.
Referenced by llvm::InstCombiner::visitFPTrunc().
|
static |
OptimizeIntegerToVectorInsertions - If the input is an 'or' instruction, we may be doing shifts and ors to assemble the elements of the vector manually.
Try to rip the code out and replace it with insertelements. This is to optimize code like this:
tmp37 = bitcast float inc to i32 tmp38 = zext i32 tmp37 to i64 tmp31 = bitcast float inc5 to i32 tmp32 = zext i32 tmp31 to i64 tmp33 = shl i64 tmp32, 32 ins35 = or i64 tmp33, tmp38 tmp43 = bitcast i64 ins35 to <2 x float>
Into two insertelements that do "buildvector{%inc, %inc5}".
Definition at line 1670 of file InstCombineCasts.cpp.
References llvm::InstCombiner::Builder, CollectInsertionElements(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateInsertElement(), llvm::InstCombiner::getDataLayout(), llvm::SequentialType::getElementType(), llvm::IRBuilderBase::getInt32(), llvm::Constant::getNullValue(), llvm::VectorType::getNumElements(), llvm::User::getOperand(), llvm::Value::getType(), and llvm::DataLayout::isBigEndian().
Referenced by llvm::InstCombiner::visitBitCast().
|
static |
OptimizeIntToFloatBitCast - See if we can optimize an integer->float/double bitcast.
The various long double bitcasts can't get in here.
Definition at line 1698 of file InstCombineCasts.cpp.
References llvm::InstCombiner::Builder, llvm::ExtractElementInst::Create(), llvm::IRBuilder< preserveNames, T, Inserter >::CreateBitCast(), llvm::VectorType::get(), llvm::SequentialType::getElementType(), llvm::IRBuilderBase::getInt32(), llvm::User::getOperand(), llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), llvm::ConstantInt::getZExtValue(), llvm::DataLayout::isBigEndian(), llvm::PatternMatch::m_BitCast(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Value(), and llvm::PatternMatch::match().
Referenced by llvm::InstCombiner::visitBitCast().
|
static |
OptimizeVectorResize - This input value (which is known to have vector type) is being zero extended or truncated to the specified vector type.
Try to replace it with a shuffle (and vector/vector bitcast) if possible.
The source and destination vector types may have different element types.
Definition at line 1491 of file InstCombineCasts.cpp.
References llvm::InstCombiner::Builder, llvm::IRBuilder< preserveNames, T, Inserter >::CreateBitCast(), llvm::VectorType::get(), llvm::ConstantDataVector::get(), llvm::UndefValue::get(), llvm::Value::getContext(), llvm::SequentialType::getElementType(), llvm::Constant::getNullValue(), llvm::VectorType::getNumElements(), llvm::Type::getPrimitiveSizeInBits(), llvm::Value::getType(), llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), and llvm::NVPTX::PTXLdStInstCode::V2.
Referenced by llvm::InstCombiner::visitBitCast().
1.8.6