32#define DEBUG_TYPE "riscv-codegenprepare"
33#define PASS_NAME "RISC-V CodeGenPrepare"
77 using namespace PatternMatch;
90 auto *CI = dyn_cast<ConstantInt>(RHS);
98 if (!isUInt<32>(
C) || isInt<12>(
C) || !isInt<12>(SignExtend64<32>(
C)))
102 C = SignExtend64<32>(
C);
138 if (!
II.getType()->getScalarType()->isIntegerTy(1))
142 using namespace PatternMatch;
148 auto *
Phi = dyn_cast<PHINode>(PhiV);
149 if (!Phi || !
Phi->hasOneUse() ||
Phi->getNumIncomingValues() != 2 ||
151 Phi->getIncomingValue(1) != &
II)
155 VectorType::get(IntegerType::getInt8Ty(
II.getContext()),
156 cast<VectorType>(
II.getType())->getElementCount());
159 PHINode *WidePhi = Builder.CreatePHI(WideTy, 2);
161 Phi->getIncomingBlock(0));
162 Builder.SetInsertPoint(&
II);
163 Value *WideTrue = Builder.CreateZExt(True, WideTy);
164 Value *WideMerge = Builder.CreateIntrinsic(Intrinsic::vp_merge, {WideTy},
165 {
Mask, WideTrue, WidePhi, EVL});
167 Value *Trunc = Builder.CreateTrunc(WideMerge,
II.getType());
169 II.replaceAllUsesWith(Trunc);
172 Phi->setIncomingValue(1,
Phi->getIncomingValue(0));
210 if (expandVPStrideLoad(
I))
216 if (
I.getIntrinsicID() != Intrinsic::vector_reduce_fadd &&
217 !isa<VPReductionIntrinsic>(&
I))
220 auto *
PHI = dyn_cast<PHINode>(
I.getOperand(0));
221 if (!
PHI || !
PHI->hasOneUse() ||
225 Type *VecTy =
I.getOperand(1)->getType();
227 auto *VecPHI = Builder.CreatePHI(VecTy,
PHI->getNumIncomingValues());
229 for (
auto *BB :
PHI->blocks()) {
230 Builder.SetInsertPoint(BB->getTerminator());
231 Value *InsertElt = Builder.CreateInsertElement(
232 VecTy,
PHI->getIncomingValueForBlock(BB), (
uint64_t)0);
233 VecPHI->addIncoming(InsertElt, BB);
236 Builder.SetInsertPoint(&
I);
237 I.setOperand(0, Builder.CreateExtractElement(VecPHI, (
uint64_t)0));
239 PHI->eraseFromParent();
250 using namespace PatternMatch;
251 if (!
match(&
II, m_Intrinsic<Intrinsic::experimental_vp_strided_load>(
257 if (
II.getType()->getScalarSizeInBits() >
ST->getXLen())
263 auto *VTy = cast<VectorType>(
II.getType());
266 Type *STy = VTy->getElementType();
267 Value *Val = Builder.CreateLoad(STy, BasePtr);
268 Value *Res = Builder.CreateIntrinsic(Intrinsic::experimental_vp_splat, {VTy},
269 {Val,
II.getOperand(2), VL});
271 II.replaceAllUsesWith(Res);
272 II.eraseFromParent();
276bool RISCVCodeGenPrepare::runOnFunction(
Function &
F) {
280 auto &TPC = getAnalysis<TargetPassConfig>();
284 DL = &
F.getDataLayout();
285 DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
287 bool MadeChange =
false;
299char RISCVCodeGenPrepare::
ID = 0;
302 return new RISCVCodeGenPrepare();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
void visit(MachineFunction &MF, MachineBasicBlock &Start, std::function< void(MachineBasicBlock *)> op)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
Target-Independent Code Generator Pass Configuration Options pass.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
static LLVM_ABI ConstantAggregateZero * get(Type *Ty)
A parsed version of the target data layout string in and methods for querying it.
Legacy analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
FunctionPass class - This class is used to implement most global optimizations.
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Base class for instruction visitors.
RetTy visitIntrinsicInst(IntrinsicInst &I)
void visitInstruction(Instruction &I)
A wrapper class for inspecting calls to intrinsic functions.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
StringRef - Represent a constant reference to a string, i.e.
Target-Independent Code Generator Pass Configuration Options.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isIntegerTy() const
True if this is an instance of IntegerType.
void setOperand(unsigned i, Value *Val)
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
bool match(Val *V, const Pattern &P)
NNegZExt_match< OpTy > m_NNegZExt(const OpTy &Op)
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
NodeAddr< PhiNode * > Phi
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
If the specified value is a trivially dead instruction, delete it.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ABI bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth=0)
Return true if the given value is known to be non-zero when defined.
FunctionPass * createRISCVCodeGenPreparePass()
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.