LLVM 20.0.0git
|
#include "InstCombineInternal.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/VectorUtils.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.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/User.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Transforms/InstCombine/InstCombiner.h"
#include <cassert>
#include <cstdint>
#include <iterator>
#include <utility>
Go to the source code of this file.
Classes | |
struct | BinopElts |
These are the ingredients in an alternate form binary operator as described below. More... | |
Macros | |
#define | DEBUG_TYPE "instcombine" |
Typedefs | |
using | ShuffleOps = std::pair< Value *, Value * > |
We are building a shuffle to create V, which is a sequence of insertelement, extractelement pairs. | |
Functions | |
STATISTIC (NumAggregateReconstructionsSimplified, "Number of aggregate reconstructions turned into reuse of the " "original aggregate") | |
static bool | cheapToScalarize (Value *V, Value *EI) |
Return true if the value is cheaper to scalarize than it is to leave as a vector operation. | |
static APInt | findDemandedEltsBySingleUser (Value *V, Instruction *UserInstr) |
Find elements of V demanded by UserInstr. | |
static APInt | findDemandedEltsByAllUsers (Value *V) |
Find union of elements of V demanded by all its users. | |
static ConstantInt * | getPreferredVectorIndex (ConstantInt *IndexC) |
Given a constant index for a extractelement or insertelement instruction, return it with the canonical type if it isn't already canonical. | |
static bool | collectSingleShuffleElements (Value *V, Value *LHS, Value *RHS, SmallVectorImpl< int > &Mask) |
If V is a shuffle of values that ONLY returns elements from either LHS or RHS, return the shuffle mask and true. | |
static bool | replaceExtractElements (InsertElementInst *InsElt, ExtractElementInst *ExtElt, InstCombinerImpl &IC) |
If we have insertion into a vector that is wider than the vector that we are extracting from, try to widen the source vector to allow a single shufflevector to replace one or more insert/extract pairs. | |
static ShuffleOps | collectShuffleElements (Value *V, SmallVectorImpl< int > &Mask, Value *PermittedRHS, InstCombinerImpl &IC, bool &Rerun) |
static bool | isShuffleEquivalentToSelect (ShuffleVectorInst &Shuf) |
static Instruction * | foldInsSequenceIntoSplat (InsertElementInst &InsElt) |
Turn a chain of inserts that splats a value into an insert + shuffle: insertelt(insertelt(insertelt(insertelt X, k, 0), k, 1), k, 2) ... -> shufflevector(insertelt(X, k, 0), poison, zero) | |
static Instruction * | foldInsEltIntoSplat (InsertElementInst &InsElt) |
Try to fold an insert element into an existing splat shuffle by changing the shuffle's mask to include the index of this insert element. | |
static Instruction * | foldInsEltIntoIdentityShuffle (InsertElementInst &InsElt) |
Try to fold an extract+insert element into an existing identity shuffle by changing the shuffle's mask to include the index of this insert element. | |
static Instruction * | hoistInsEltConst (InsertElementInst &InsElt2, InstCombiner::BuilderTy &Builder) |
If we have an insertelement instruction feeding into another insertelement and the 2nd is inserting a constant into the vector, canonicalize that constant insertion before the insertion of a variable: | |
static Instruction * | foldConstantInsEltIntoShuffle (InsertElementInst &InsElt) |
insertelt (shufflevector X, CVec, Mask|insertelt X, C1, CIndex1), C, CIndex --> shufflevector X, CVec', Mask' | |
static Instruction * | narrowInsElt (InsertElementInst &InsElt, InstCombiner::BuilderTy &Builder) |
If both the base vector and the inserted element are extended from the same type, do the insert element in the narrow source type followed by extend. | |
static Instruction * | foldTruncInsEltPair (InsertElementInst &InsElt, bool IsBigEndian, InstCombiner::BuilderTy &Builder) |
If we are inserting 2 halves of a value into adjacent elements of a vector, try to convert to a single insert with appropriate bitcasts. | |
static bool | canEvaluateShuffled (Value *V, ArrayRef< int > Mask, unsigned Depth=5) |
Return true if we can evaluate the specified expression tree if the vector elements were shuffled in a different order. | |
static Value * | buildNew (Instruction *I, ArrayRef< Value * > NewOps, IRBuilderBase &Builder) |
Rebuild a new instruction just like 'I' but with the new operands given. | |
static Value * | evaluateInDifferentElementOrder (Value *V, ArrayRef< int > Mask, IRBuilderBase &Builder) |
static bool | isShuffleExtractingFromLHS (ShuffleVectorInst &SVI, ArrayRef< int > Mask) |
static BinopElts | getAlternateBinop (BinaryOperator *BO, const DataLayout &DL) |
Binops may be transformed into binops with different opcodes and operands. | |
static Instruction * | foldSelectShuffleOfSelectShuffle (ShuffleVectorInst &Shuf) |
A select shuffle of a select shuffle with a shared operand can be reduced to a single select shuffle. | |
static Instruction * | foldSelectShuffleWith1Binop (ShuffleVectorInst &Shuf, const SimplifyQuery &SQ) |
static Instruction * | canonicalizeInsertSplat (ShuffleVectorInst &Shuf, InstCombiner::BuilderTy &Builder) |
If we have an insert of a scalar to a non-zero element of an undefined vector and then shuffle that value, that's the same as inserting to the zero element and shuffling. | |
static Instruction * | foldTruncShuffle (ShuffleVectorInst &Shuf, bool IsBigEndian) |
Convert a narrowing shuffle of a bitcasted vector into a vector truncate. | |
static Instruction * | narrowVectorSelect (ShuffleVectorInst &Shuf, InstCombiner::BuilderTy &Builder) |
Match a shuffle-select-shuffle pattern where the shuffles are widening and narrowing (concatenating with poison and extracting back to the original length). | |
static Instruction * | foldShuffleOfUnaryOps (ShuffleVectorInst &Shuf, InstCombiner::BuilderTy &Builder) |
Canonicalize FP negate/abs after shuffle. | |
static Instruction * | foldCastShuffle (ShuffleVectorInst &Shuf, InstCombiner::BuilderTy &Builder) |
Canonicalize casts after shuffle. | |
static Instruction * | foldIdentityExtractShuffle (ShuffleVectorInst &Shuf) |
Try to fold an extract subvector operation. | |
static Instruction * | foldShuffleWithInsert (ShuffleVectorInst &Shuf, InstCombinerImpl &IC) |
Try to replace a shuffle with an insertelement or try to replace a shuffle operand with the operand of an insertelement. | |
static Instruction * | foldIdentityPaddedShuffles (ShuffleVectorInst &Shuf) |
#define DEBUG_TYPE "instcombine" |
Definition at line 44 of file InstCombineVectorOps.cpp.
using ShuffleOps = std::pair<Value *, Value *> |
We are building a shuffle to create V, which is a sequence of insertelement, extractelement pairs.
If PermittedRHS is set, then we must either use it or not rely on the second vector source. Return a std::pair containing the left and right vectors of the proposed shuffle (or 0), and set the Mask parameter as required.
Note: we intentionally don't try to fold earlier shuffles since they have often been chosen carefully to be efficiently implementable on the target.
Definition at line 779 of file InstCombineVectorOps.cpp.
|
static |
Rebuild a new instruction just like 'I' but with the new operands given.
In the event of type mismatch, the type of the operands is correct.
Definition at line 1915 of file InstCombineVectorOps.cpp.
References assert(), llvm::IRBuilderBase::CreateBinOp(), llvm::IRBuilderBase::CreateCast(), llvm::IRBuilderBase::CreateFCmp(), llvm::IRBuilderBase::CreateGEP(), llvm::IRBuilderBase::CreateICmp(), llvm::VectorType::get(), getOpcode(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::hasNoUnsignedWrap(), I, Idx, llvm::Instruction::isExact(), llvm_unreachable, Ptr, llvm::IRBuilderBase::SetInsertPoint(), llvm::ArrayRef< T >::size(), and llvm::ArrayRef< T >::slice().
Referenced by evaluateInDifferentElementOrder().
Return true if we can evaluate the specified expression tree if the vector elements were shuffled in a different order.
Definition at line 1827 of file InstCombineVectorOps.cpp.
References canEvaluateShuffled(), llvm::Depth, llvm::ConstantInt::getLimitedValue(), I, llvm::is_contained(), and llvm::Type::isVectorTy().
Referenced by canEvaluateShuffled(), and llvm::InstCombinerImpl::visitShuffleVectorInst().
|
static |
If we have an insert of a scalar to a non-zero element of an undefined vector and then shuffle that value, that's the same as inserting to the zero element and shuffling.
Splatting from the zero element is recognized as the canonical form of splat.
Definition at line 2281 of file InstCombineVectorOps.cpp.
References llvm::IRBuilderBase::CreateInsertElement(), llvm::PoisonValue::get(), llvm::User::getOperand(), llvm::ShuffleVectorInst::getShuffleMask(), llvm::ShuffleVectorInst::getType(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_InsertElt(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Poison(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::PoisonMaskElem, and X.
Referenced by llvm::InstCombinerImpl::visitShuffleVectorInst().
Return true if the value is cheaper to scalarize than it is to leave as a vector operation.
If the extract index EI
is a constant integer then some operations may be cheap to scalarize.
FIXME: It's possible to create more instructions than previously existed.
Definition at line 58 of file InstCombineVectorOps.cpp.
References llvm::CallingConv::C, cheapToScalarize(), llvm::ConstantInt::getValue(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_Cmp(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_InsertElt(), llvm::PatternMatch::m_Load(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_UnOp(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and llvm::APInt::ult().
Referenced by cheapToScalarize(), and llvm::InstCombinerImpl::visitExtractElementInst().
|
static |
Definition at line 781 of file InstCombineVectorOps.cpp.
References assert(), collectShuffleElements(), collectSingleShuffleElements(), llvm::PoisonValue::get(), llvm::User::getOperand(), llvm::Value::getType(), llvm::PatternMatch::m_Poison(), llvm::PatternMatch::match(), replaceExtractElements(), and RHS.
Referenced by collectShuffleElements(), and llvm::InstCombinerImpl::visitInsertElementInst().
|
static |
If V is a shuffle of values that ONLY returns elements from either LHS or RHS, return the shuffle mask and true.
Otherwise, return false.
Definition at line 621 of file InstCombineVectorOps.cpp.
References assert(), collectSingleShuffleElements(), llvm::User::getOperand(), llvm::Value::getType(), LHS, llvm::PatternMatch::m_Poison(), llvm::PatternMatch::match(), and RHS.
Referenced by collectShuffleElements(), and collectSingleShuffleElements().
|
static |
Definition at line 1991 of file InstCombineVectorOps.cpp.
References assert(), buildNew(), llvm::CallingConv::C, llvm::IRBuilderBase::CreateInsertElement(), evaluateInDifferentElementOrder(), llvm::FixedVectorType::get(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::ConstantAggregateZero::get(), llvm::ConstantExpr::getShuffleVector(), I, llvm_unreachable, llvm::PatternMatch::m_Undef(), llvm::PatternMatch::match(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::IRBuilderBase::SetInsertPoint().
Referenced by evaluateInDifferentElementOrder(), and llvm::InstCombinerImpl::visitShuffleVectorInst().
Find union of elements of V demanded by all its users.
If it is known by querying findDemandedEltsBySingleUser that no user demands an element of V, then the corresponding bit remains unset in the returned value.
Definition at line 367 of file InstCombineVectorOps.cpp.
References findDemandedEltsBySingleUser(), llvm::APInt::getAllOnes(), I, and llvm::APInt::isAllOnes().
Referenced by llvm::InstCombinerImpl::visitExtractElementInst().
|
static |
Find elements of V demanded by UserInstr.
Definition at line 323 of file InstCombineVectorOps.cpp.
References assert(), llvm::APInt::getAllOnes(), llvm::ExtractElementInst::getIndexOperand(), llvm::ShuffleVectorInst::getMaskValue(), llvm::APInt::getOneBitSet(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), llvm::ConstantInt::getValue(), llvm::ExtractElementInst::getVectorOperand(), llvm::ConstantInt::getZExtValue(), llvm::APInt::setBit(), and llvm::APInt::ult().
Referenced by findDemandedEltsByAllUsers().
|
static |
Canonicalize casts after shuffle.
Definition at line 2574 of file InstCombineVectorOps.cpp.
References assert(), llvm::CastInst::Create(), llvm::IRBuilderBase::CreateShuffleVector(), llvm::User::getOperand(), llvm::ShuffleVectorInst::getShuffleMask(), llvm::ShuffleVectorInst::getType(), llvm::Value::getType(), X, and Y.
Referenced by llvm::InstCombinerImpl::visitShuffleVectorInst().
|
static |
insertelt (shufflevector X, CVec, Mask|insertelt X, C1, CIndex1), C, CIndex --> shufflevector X, CVec', Mask'
Definition at line 1472 of file InstCombineVectorOps.cpp.
References llvm::ConstantVector::get(), llvm::PoisonValue::get(), llvm::Constant::getAggregateElement(), llvm::VectorType::getElementType(), llvm::User::getOperand(), llvm::InsertElementInst::getType(), I, isShuffleEquivalentToSelect(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ConstantInt(), and llvm::PatternMatch::match().
Referenced by llvm::InstCombinerImpl::visitInsertElementInst().
|
static |
Try to fold an extract subvector operation.
Definition at line 2623 of file InstCombineVectorOps.cpp.
References assert(), llvm::ShuffleVectorInst::getMaskValue(), llvm::User::getOperand(), llvm::Type::getPrimitiveSizeInBits(), llvm::ShuffleVectorInst::getType(), llvm::Value::hasOneUse(), llvm::ShuffleVectorInst::isIdentityWithExtract(), llvm::PatternMatch::m_BitCast(), llvm::PatternMatch::m_InsertElt(), llvm::PatternMatch::m_Poison(), llvm::PatternMatch::m_Shuffle(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_Zero(), llvm::PatternMatch::match(), llvm::PoisonMaskElem, X, and Y.
Referenced by llvm::InstCombinerImpl::visitShuffleVectorInst().
|
static |
Definition at line 2761 of file InstCombineVectorOps.cpp.
References assert(), llvm::User::getOperand(), llvm::ShuffleVectorInst::getShuffleMask(), llvm::ShuffleVectorInst::getType(), llvm::isPowerOf2_32(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::match(), X, and Y.
Referenced by llvm::InstCombinerImpl::visitShuffleVectorInst().
|
static |
Try to fold an extract+insert element into an existing identity shuffle by changing the shuffle's mask to include the index of this insert element.
Definition at line 1390 of file InstCombineVectorOps.cpp.
References assert(), llvm::User::getOperand(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_ExtractElt(), llvm::PatternMatch::m_Poison(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificInt(), llvm::PatternMatch::match(), llvm::PoisonMaskElem, and X.
Referenced by llvm::InstCombinerImpl::visitInsertElementInst().
|
static |
Try to fold an insert element into an existing splat shuffle by changing the shuffle's mask to include the index of this insert element.
Definition at line 1353 of file InstCombineVectorOps.cpp.
References llvm::User::getOperand(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_InsertElt(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_ZeroInt(), llvm::PatternMatch::match(), and X.
Referenced by llvm::InstCombinerImpl::visitInsertElementInst().
|
static |
Turn a chain of inserts that splats a value into an insert + shuffle: insertelt(insertelt(insertelt(insertelt X, k, 0), k, 1), k, 2) ... -> shufflevector(insertelt(X, k, 0), poison, zero)
Definition at line 1279 of file InstCombineVectorOps.cpp.
References llvm::SmallBitVector::all(), llvm::InsertElementInst::Create(), llvm::PoisonValue::get(), llvm::Value::getContext(), llvm::Type::getInt64Ty(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::User::getOperand(), llvm::InsertElementInst::getType(), llvm::Value::hasOneUse(), Idx, llvm::PatternMatch::m_Poison(), llvm::PatternMatch::match(), and llvm::Instruction::user_back().
Referenced by llvm::InstCombinerImpl::visitInsertElementInst().
|
static |
A select shuffle of a select shuffle with a shared operand can be reduced to a single select shuffle.
This is an obvious improvement in IR, and the backend is expected to lower select shuffles efficiently.
Definition at line 2165 of file InstCombineVectorOps.cpp.
References assert(), llvm::ShuffleVectorInst::commuteShuffleMask(), llvm::User::getOperand(), llvm::ShuffleVectorInst::getShuffleMask(), llvm::ShuffleVectorInst::isIdentityMask(), llvm::ShuffleVectorInst::isSelect(), llvm::ShuffleVectorInst::isSelectMask(), llvm::SmallVectorBase< Size_T >::size(), std::swap(), X, and Y.
Referenced by llvm::InstCombinerImpl::foldSelectShuffle().
|
static |
Definition at line 2212 of file InstCombineVectorOps.cpp.
References assert(), llvm::CallingConv::C, llvm::Instruction::copyIRFlags(), llvm::BinaryOperator::Create(), llvm::Instruction::dropPoisonGeneratingFlags(), llvm::ConstantExpr::getBinOpIdentity(), llvm::VectorType::getElementType(), llvm::User::getOperand(), llvm::InstCombiner::getSafeVectorConstantForBinop(), llvm::ShuffleVectorInst::getShuffleMask(), llvm::ConstantExpr::getShuffleVector(), llvm::ShuffleVectorInst::getType(), llvm::is_contained(), llvm::Type::isFloatingPointTy(), llvm::Instruction::isIntDivRem(), llvm::isKnownNeverNaN(), llvm::ShuffleVectorInst::isSelect(), llvm::Instruction::isShift(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::match(), llvm::PoisonMaskElem, and X.
Referenced by llvm::InstCombinerImpl::foldSelectShuffle().
|
static |
Canonicalize FP negate/abs after shuffle.
Definition at line 2527 of file InstCombineVectorOps.cpp.
References llvm::Instruction::andIRFlags(), llvm::Instruction::copyIRFlags(), llvm::CallInst::Create(), llvm::UnaryOperator::CreateFNegFMF(), llvm::IRBuilderBase::CreateShuffleVector(), llvm::Instruction::getModule(), llvm::User::getOperand(), llvm::Intrinsic::getOrInsertDeclaration(), llvm::ShuffleVectorInst::getShuffleMask(), llvm::ShuffleVectorInst::getType(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_FAbs(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_Poison(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), S1, llvm::Instruction::setFastMathFlags(), X, and Y.
Referenced by llvm::InstCombinerImpl::visitShuffleVectorInst().
|
static |
Try to replace a shuffle with an insertelement or try to replace a shuffle operand with the operand of an insertelement.
Definition at line 2673 of file InstCombineVectorOps.cpp.
References assert(), llvm::ShuffleVectorInst::commuteShuffleMask(), llvm::InsertElementInst::Create(), llvm::User::getOperand(), llvm::ShuffleVectorInst::getShuffleMask(), llvm::Value::getType(), llvm::is_contained(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_InsertElt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceOperand(), std::swap(), and X.
Referenced by llvm::InstCombinerImpl::visitShuffleVectorInst().
|
static |
If we are inserting 2 halves of a value into adjacent elements of a vector, try to convert to a single insert with appropriate bitcasts.
Definition at line 1609 of file InstCombineVectorOps.cpp.
References llvm::IRBuilderBase::CreateBitCast(), llvm::IRBuilderBase::CreateInsertElement(), llvm::FixedVectorType::get(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::InsertElementInst::getType(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_InsertElt(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Trunc(), llvm::PatternMatch::m_Undef(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and X.
Referenced by llvm::InstCombinerImpl::visitInsertElementInst().
|
static |
Convert a narrowing shuffle of a bitcasted vector into a vector truncate.
Example (little endian): shuf (bitcast <4 x i16> X to <8 x i8>), <0, 2, 4, 6> --> trunc X to <4 x i8>
Definition at line 2452 of file InstCombineVectorOps.cpp.
References assert(), llvm::ShuffleVectorInst::changesLength(), llvm::User::getOperand(), llvm::Type::getScalarSizeInBits(), llvm::ShuffleVectorInst::getShuffleMask(), llvm::ShuffleVectorInst::getType(), llvm::ShuffleVectorInst::increasesLength(), llvm::Type::isIntOrIntVectorTy(), llvm::Type::isVectorTy(), llvm::PatternMatch::m_BitCast(), llvm::PatternMatch::m_Poison(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::PoisonMaskElem, and X.
Referenced by llvm::InstCombinerImpl::visitShuffleVectorInst().
|
static |
Binops may be transformed into binops with different opcodes and operands.
Reverse the usual canonicalization to enable folds with the non-canonical form of the binop. If a transform is possible, return the elements of the new binop. If not, return invalid elements.
Definition at line 2130 of file InstCombineVectorOps.cpp.
References assert(), llvm::CallingConv::C, llvm::ConstantFoldBinaryOpOperands(), DL, llvm::Constant::getAllOnesValue(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), llvm::PatternMatch::m_ImmConstant(), llvm::PatternMatch::m_ZeroInt(), and llvm::PatternMatch::match().
Referenced by llvm::InstCombinerImpl::foldSelectShuffle().
|
static |
Given a constant index for a extractelement or insertelement instruction, return it with the canonical type if it isn't already canonical.
We arbitrarily pick 64 bit as our canonical type. The actual bitwidth doesn't matter, we just want a consistent type to simplify CSE.
Definition at line 390 of file InstCombineVectorOps.cpp.
References llvm::APInt::getActiveBits(), llvm::ConstantInt::getBitWidth(), llvm::Value::getContext(), llvm::ConstantInt::getValue(), and llvm::APInt::zextOrTrunc().
Referenced by llvm::InstCombinerImpl::visitExtractElementInst(), and llvm::InstCombinerImpl::visitInsertElementInst().
|
static |
If we have an insertelement instruction feeding into another insertelement and the 2nd is inserting a constant into the vector, canonicalize that constant insertion before the insertion of a variable:
insertelement (insertelement X, Y, IdxC1), ScalarC, IdxC2 --> insertelement (insertelement X, ScalarC, IdxC2), Y, IdxC1
This has the potential of eliminating the 2nd insertelement instruction via constant folding of the scalar constant into a vector constant.
Definition at line 1449 of file InstCombineVectorOps.cpp.
References llvm::InsertElementInst::Create(), llvm::IRBuilderBase::CreateInsertElement(), llvm::User::getOperand(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), X, and Y.
Referenced by llvm::InstCombinerImpl::visitInsertElementInst().
|
static |
Definition at line 1251 of file InstCombineVectorOps.cpp.
References llvm::ShuffleVectorInst::getMaskValue(), llvm::User::getOperand(), llvm::ShuffleVectorInst::getShuffleMask(), and llvm::Value::getType().
Referenced by foldConstantInsEltIntoShuffle().
|
static |
Definition at line 2099 of file InstCombineVectorOps.cpp.
References llvm::User::getOperand(), llvm::Value::getType(), and I.
Referenced by llvm::InstCombinerImpl::visitShuffleVectorInst().
|
static |
If both the base vector and the inserted element are extended from the same type, do the insert element in the narrow source type followed by extend.
TODO: This can be extended to include other cast opcodes, but particularly if we create a wider insertelement, make sure codegen is not harmed.
Definition at line 1576 of file InstCombineVectorOps.cpp.
References llvm::CastInst::Create(), llvm::IRBuilderBase::CreateInsertElement(), llvm::User::getOperand(), llvm::InsertElementInst::getType(), llvm::Value::hasOneUse(), llvm::PatternMatch::m_FPExt(), llvm::PatternMatch::m_SExt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), X, and Y.
Referenced by llvm::InstCombinerImpl::visitInsertElementInst().
|
static |
Match a shuffle-select-shuffle pattern where the shuffles are widening and narrowing (concatenating with poison and extracting back to the original length).
This allows replacing the wide select with a narrow select.
Definition at line 2493 of file InstCombineVectorOps.cpp.
References Cond, llvm::SelectInst::Create(), llvm::IRBuilderBase::CreateShuffleVector(), llvm::User::getOperand(), llvm::ShuffleVectorInst::getShuffleMask(), llvm::ShuffleVectorInst::getType(), llvm::Value::getType(), llvm::ShuffleVectorInst::isIdentityWithExtract(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Poison(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_Shuffle(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), X, and Y.
|
static |
If we have insertion into a vector that is wider than the vector that we are extracting from, try to widen the source vector to allow a single shufflevector to replace one or more insert/extract pairs.
Definition at line 694 of file InstCombineVectorOps.cpp.
References llvm::InstCombiner::addToWorklist(), llvm::ExtractElementInst::Create(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::User::getOperand(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getParent(), llvm::InsertElementInst::getType(), llvm::ExtractElementInst::getVectorOperand(), llvm::ExtractElementInst::getVectorOperandType(), llvm::Value::hasOneUse(), llvm::InstCombiner::InsertNewInstWith(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::InstCombiner::replaceInstUsesWith(), llvm::Instruction::user_back(), and llvm::Value::users().
Referenced by collectShuffleElements().
STATISTIC | ( | NumAggregateReconstructionsSimplified | , |
"Number of aggregate reconstructions turned into reuse of the " "original aggregate" | |||
) |