1//===----- RISCVCodeGenPrepare.cpp ----------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This is a RISC-V specific version of CodeGenPrepare.
10// It munges the code in the input function to better prepare it for
11// SelectionDAG-based code generation. This works around limitations in it's
12// basic-block-at-a-time approach.
13//
14//===----------------------------------------------------------------------===//
15
16#include "RISCV.h"
17#include "RISCVTargetMachine.h"
18#include "llvm/ADT/Statistic.h"
19#include "llvm/Analysis/ValueTracking.h"
20#include "llvm/CodeGen/TargetPassConfig.h"
21#include "llvm/IR/Dominators.h"
22#include "llvm/IR/IRBuilder.h"
23#include "llvm/IR/InstVisitor.h"
24#include "llvm/IR/IntrinsicInst.h"
25#include "llvm/IR/Intrinsics.h"
26#include "llvm/IR/PatternMatch.h"
27#include "llvm/InitializePasses.h"
28#include "llvm/Pass.h"
29#include "llvm/Transforms/Utils/Local.h"
30
31using namespace llvm;
32
33#define DEBUG_TYPE "riscv-codegenprepare"
34#define PASS_NAME "RISC-V CodeGenPrepare"
35
36namespace {
37class RISCVCodeGenPrepareImpl
38 : public InstVisitor<RISCVCodeGenPrepareImpl, bool> {
39 Function &F;
40 const DataLayout *DL;
41 const DominatorTree *DT;
42 const RISCVSubtarget *ST;
43
44public:
45 RISCVCodeGenPrepareImpl(Function &F, const DominatorTree *DT,
46 const RISCVSubtarget *ST)
47 : F(F), DL(&F.getDataLayout()), DT(DT), ST(ST) {}
48 bool run();
49 bool visitInstruction(Instruction &I) { return false; }
50 bool visitAnd(BinaryOperator &BO);
51 bool visitMul(BinaryOperator &BO);
52 bool visitIntrinsicInst(IntrinsicInst &I);
53 bool expandVPStrideLoad(IntrinsicInst &I);
54 bool expandMulReduction(IntrinsicInst &I);
55 bool widenVPMerge(Instruction *I);
56 bool visitFreezeInst(FreezeInst &BO);
57};
58} // namespace
59
60namespace {
61class RISCVCodeGenPrepareLegacy : public FunctionPass {
62public:
63 static char ID;
64
65 RISCVCodeGenPrepareLegacy() : FunctionPass(ID) {}
66
67 bool runOnFunction(Function &F) override;
68 StringRef getPassName() const override { return PASS_NAME; }
69
70 void getAnalysisUsage(AnalysisUsage &AU) const override {
71 AU.setPreservesCFG();
72 AU.addRequired<DominatorTreeWrapperPass>();
73 AU.addRequired<TargetPassConfig>();
74 }
75};
76} // namespace
77
78// Try to optimize (i64 (and (zext/sext (i32 X), C1))) if C1 has bit 31 set,
79// but bits 63:32 are zero. If we know that bit 31 of X is 0, we can fill
80// the upper 32 bits with ones.
81bool RISCVCodeGenPrepareImpl::visitAnd(BinaryOperator &BO) {
82 if (!ST->is64Bit())
83 return false;
84
85 if (!BO.getType()->isIntegerTy(BitWidth: 64))
86 return false;
87
88 using namespace PatternMatch;
89
90 // Left hand side should be a zext nneg.
91 Value *LHSSrc;
92 if (!match(V: BO.getOperand(i_nocapture: 0), P: m_NNegZExt(Op: m_Value(V&: LHSSrc))))
93 return false;
94
95 if (!LHSSrc->getType()->isIntegerTy(BitWidth: 32))
96 return false;
97
98 // Right hand side should be a constant.
99 Value *RHS = BO.getOperand(i_nocapture: 1);
100
101 auto *CI = dyn_cast<ConstantInt>(Val: RHS);
102 if (!CI)
103 return false;
104 uint64_t C = CI->getZExtValue();
105
106 // Look for constants that fit in 32 bits but not simm12, and can be made
107 // into simm12 by sign extending bit 31. This will allow use of ANDI.
108 // TODO: Is worth making simm32?
109 if (!isUInt<32>(x: C) || isInt<12>(x: C) || !isInt<12>(x: SignExtend64<32>(x: C)))
110 return false;
111
112 // Sign extend the constant and replace the And operand.
113 C = SignExtend64<32>(x: C);
114 BO.setOperand(i_nocapture: 1, Val_nocapture: ConstantInt::get(Ty: RHS->getType(), V: C));
115
116 return true;
117}
118
119// Look for (mul (zext X), (splat Y)) where zext is doubling the
120// element size and Y is known to be zero extended. Replace with
121// (mul (zext X), (zext (splat (trunc Y)))) to encourage the use of
122// widening multiply. Only do this if the splat isn't already in the same
123// basic block as the mul. We put the zext with the mul and the new
124// splat and trunc in the basic block with the original splat.
125// We only need to do this when sinkSplatOperands() is false, otherwise
126// CodeGenPrepare will just sink the splat and SelectionDAG can sort it out.
127// TODO: Extend to sign extend or mismatched extends.
128bool RISCVCodeGenPrepareImpl::visitMul(BinaryOperator &BO) {
129 using namespace PatternMatch;
130
131 if (!ST->hasVInstructions() || ST->sinkSplatOperands())
132 return false;
133
134 Value *LHS = BO.getOperand(i_nocapture: 0);
135 Value *RHS = BO.getOperand(i_nocapture: 1);
136
137 // Canonicalize zext to the LHS.
138 if (isa<ZExtInst>(Val: RHS))
139 std::swap(a&: LHS, b&: RHS);
140
141 // LHS should be a zext.
142 Value *ZExtSrc;
143 if (!match(V: LHS, P: m_ZExt(Op: m_Value(V&: ZExtSrc))))
144 return false;
145
146 // RHS should be a splat shuffle.
147 Value *SplatVal;
148 Instruction *RHSI;
149 if (!match(V: RHS, P: m_Instruction(I&: RHSI, P: m_OneUse(SubPattern: m_Splat(SubPattern: m_Value(V&: SplatVal))))))
150 return false;
151
152 // zext should be in the same basic block as the mul.
153 if (cast<Instruction>(Val: LHS)->getParent() != BO.getParent())
154 return false;
155
156 // The extend should be doubling.
157 unsigned Size = BO.getType()->getScalarSizeInBits();
158 unsigned SrcSize = ZExtSrc->getType()->getScalarSizeInBits();
159 if (Size != SrcSize * 2)
160 return false;
161
162 // Types should be legal.
163 if (Size != 64 && Size != 32 && Size != 16)
164 return false;
165 if (Size == 64 && !ST->hasVInstructionsI64())
166 return false;
167
168 // Splat should be in another basic block.
169 if (RHSI->getParent() == BO.getParent())
170 return false;
171
172 // Make sure we can freely truncate the value.
173 KnownBits Known = computeKnownBits(V: SplatVal, DL: *DL);
174 if (Known.countMaxActiveBits() > SrcSize)
175 return false;
176
177 VectorType *VecTy = cast<VectorType>(Val: ZExtSrc->getType());
178 Type *ScalarTy = VecTy->getElementType();
179 IRBuilder<> Builder(RHSI);
180 Value *Splat = Builder.CreateVectorSplat(
181 EC: VecTy->getElementCount(), V: Builder.CreateTrunc(V: SplatVal, DestTy: ScalarTy));
182
183 Builder.SetInsertPoint(&BO);
184 Value *NewZExt = Builder.CreateZExt(V: Splat, DestTy: BO.getType());
185
186 RHSI->replaceAllUsesWith(V: NewZExt);
187 RHSI->eraseFromParent();
188
189 return true;
190}
191
192// With EVL tail folding, an AnyOf reduction will generate an i1 vp.merge like
193// follows:
194//
195// loop:
196// %phi = phi <vscale x 4 x i1> [zeroinitializer, %entry], [%freeze, %loop]
197// %cmp = icmp ...
198// %rec = call <vscale x 4 x i1> @llvm.vp.merge(%cmp, i1 true, %phi, %evl)
199// %freeze = freeze <vscale x 4 x i1> %rec [optional]
200// ...
201// middle:
202// %res = call i1 @llvm.vector.reduce.or(<vscale x 4 x i1> %freeze)
203//
204// However RVV doesn't have any tail undisturbed mask instructions and so we
205// need a convoluted sequence of mask instructions to lower the i1 vp.merge: see
206// llvm/test/CodeGen/RISCV/rvv/vpmerge-sdnode.ll.
207//
208// To avoid that this widens the i1 vp.merge to an i8 vp.merge, which will
209// generate a single vmerge.vim:
210//
211// loop:
212// %phi = phi <vscale x 4 x i8> [zeroinitializer, %entry], [%freeze, %loop]
213// %cmp = icmp ...
214// %rec = call <vscale x 4 x i8> @llvm.vp.merge(%cmp, i8 true, %phi, %evl)
215// %freeze = freeze <vscale x 4 x i8> %rec
216// %trunc = trunc <vscale x 4 x i8> %freeze to <vscale x 4 x i1>
217// ...
218// middle:
219// %res = call i1 @llvm.vector.reduce.or(<vscale x 4 x i1> %trunc)
220//
221// The trunc will normally be sunk outside of the loop, but even if there are
222// users inside the loop it is still profitable.
223bool RISCVCodeGenPrepareImpl::widenVPMerge(Instruction *Root) {
224 if (!Root->getType()->getScalarType()->isIntegerTy(BitWidth: 1))
225 return false;
226
227 Value *Mask, *True, *EVL;
228 PHINode *Phi;
229 using namespace PatternMatch;
230 auto m_VPMerge = m_Intrinsic<Intrinsic::vp_merge>(
231 Ops: m_Value(V&: Mask), Ops: m_Value(V&: True), Ops: m_Phi(PN&: Phi), Ops: m_Value(V&: EVL));
232 if (!match(V: Root, P: m_CombineOr(Ps: m_VPMerge, Ps: m_Freeze(Op: m_VPMerge))))
233 return false;
234
235 if (!Phi->hasOneUse() || Phi->getNumIncomingValues() != 2 ||
236 !match(V: Phi->getIncomingValue(i: 0), P: m_Zero()) ||
237 Phi->getIncomingValue(i: 1) != Root)
238 return false;
239
240 Type *WideTy =
241 VectorType::get(ElementType: IntegerType::getInt8Ty(C&: Root->getContext()),
242 EC: cast<VectorType>(Val: Root->getType())->getElementCount());
243
244 IRBuilder<> Builder(Phi);
245 PHINode *WidePhi = Builder.CreatePHI(Ty: WideTy, NumReservedValues: 2);
246 WidePhi->addIncoming(V: ConstantAggregateZero::get(Ty: WideTy),
247 BB: Phi->getIncomingBlock(i: 0));
248 Builder.SetInsertPoint(Root);
249 Value *WideTrue = Builder.CreateZExt(V: True, DestTy: WideTy);
250 Value *WideMerge = Builder.CreateIntrinsic(ID: Intrinsic::vp_merge, OverloadTypes: {WideTy},
251 Args: {Mask, WideTrue, WidePhi, EVL});
252 if (isa<FreezeInst>(Val: Root))
253 WideMerge = Builder.CreateFreeze(V: WideMerge);
254 WidePhi->addIncoming(V: WideMerge, BB: Phi->getIncomingBlock(i: 1));
255 Value *Trunc = Builder.CreateTrunc(V: WideMerge, DestTy: Root->getType());
256
257 Root->replaceAllUsesWith(V: Trunc);
258
259 // Break the cycle and delete the old chain.
260 Phi->setIncomingValue(i: 1, V: Phi->getIncomingValue(i: 0));
261 llvm::RecursivelyDeleteTriviallyDeadInstructions(V: Root);
262
263 return true;
264}
265
266bool RISCVCodeGenPrepareImpl::visitFreezeInst(FreezeInst &I) {
267 if (auto *II = dyn_cast<IntrinsicInst>(Val: I.getOperand(i_nocapture: 0)))
268 if (II->getIntrinsicID() == Intrinsic::vp_merge)
269 return widenVPMerge(Root: &I);
270 return false;
271}
272
273// LLVM vector reduction intrinsics return a scalar result, but on RISC-V vector
274// reduction instructions write the result in the first element of a vector
275// register. So when a reduction in a loop uses a scalar phi, we end up with
276// unnecessary scalar moves:
277//
278// loop:
279// vfmv.s.f v10, fa0
280// vfredosum.vs v8, v8, v10
281// vfmv.f.s fa0, v8
282//
283// This mainly affects ordered fadd reductions and VP reductions that have a
284// scalar start value, since other types of reduction typically use element-wise
285// vectorisation in the loop body. This tries to vectorize any scalar phis that
286// feed into these reductions:
287//
288// loop:
289// %phi = phi <float> [ ..., %entry ], [ %acc, %loop ]
290// %acc = call float @llvm.vector.reduce.fadd.nxv2f32(float %phi,
291// <vscale x 2 x float> %vec)
292//
293// ->
294//
295// loop:
296// %phi = phi <vscale x 2 x float> [ ..., %entry ], [ %acc.vec, %loop ]
297// %phi.scalar = extractelement <vscale x 2 x float> %phi, i64 0
298// %acc = call float @llvm.vector.reduce.fadd.nxv2f32(float %x,
299// <vscale x 2 x float> %vec)
300// %acc.vec = insertelement <vscale x 2 x float> poison, float %acc.next, i64 0
301//
302// Which eliminates the scalar -> vector -> scalar crossing during instruction
303// selection.
304bool RISCVCodeGenPrepareImpl::visitIntrinsicInst(IntrinsicInst &I) {
305 if (expandVPStrideLoad(I))
306 return true;
307
308 if (expandMulReduction(I))
309 return true;
310
311 if (widenVPMerge(Root: &I))
312 return true;
313
314 if (I.getIntrinsicID() != Intrinsic::vector_reduce_fadd &&
315 !isa<VPReductionIntrinsic>(Val: &I))
316 return false;
317
318 auto *PHI = dyn_cast<PHINode>(Val: I.getOperand(i_nocapture: 0));
319 if (!PHI || !PHI->hasOneUse() ||
320 !llvm::is_contained(Range: PHI->incoming_values(), Element: &I))
321 return false;
322
323 Type *VecTy = I.getOperand(i_nocapture: 1)->getType();
324 IRBuilder<> Builder(PHI);
325 auto *VecPHI = Builder.CreatePHI(Ty: VecTy, NumReservedValues: PHI->getNumIncomingValues());
326
327 for (auto *BB : PHI->blocks()) {
328 Builder.SetInsertPoint(BB->getTerminator());
329 Value *InsertElt = Builder.CreateInsertElement(
330 VecTy, NewElt: PHI->getIncomingValueForBlock(BB), Idx: (uint64_t)0);
331 VecPHI->addIncoming(V: InsertElt, BB);
332 }
333
334 Builder.SetInsertPoint(&I);
335 I.setOperand(i_nocapture: 0, Val_nocapture: Builder.CreateExtractElement(Vec: VecPHI, Idx: (uint64_t)0));
336
337 PHI->eraseFromParent();
338
339 return true;
340}
341
342// Extract pieces of size PieceEC from Vec, then build a binary tree of
343// element-wise multiplies reducing to a single piece.
344static Value *buildMulTree(IRBuilder<> &Builder, ElementCount PieceEC,
345 Value *Vec) {
346 auto *VecTy = cast<VectorType>(Val: Vec->getType());
347 auto *PieceTy = VectorType::get(ElementType: VecTy->getElementType(), EC: PieceEC);
348 unsigned PieceElts = PieceEC.getKnownMinValue();
349 unsigned NumPieces = VecTy->getElementCount().getKnownMinValue() / PieceElts;
350 assert(isPowerOf2_32(NumPieces));
351
352 SmallVector<Value *, 8> Pieces(NumPieces);
353 for (unsigned i = 0; i < NumPieces; i++)
354 Pieces[i] = Builder.CreateExtractVector(DstType: PieceTy, SrcVec: Vec, Idx: i * PieceElts);
355
356 while (Pieces.size() > 1) {
357 for (unsigned i = 0; i < Pieces.size() / 2; i++)
358 Pieces[i] =
359 Builder.CreateMul(LHS: Pieces[i * 2], RHS: Pieces[i * 2 + 1], Name: "bin.rdx");
360 Pieces.truncate(N: Pieces.size() / 2);
361 }
362 return Pieces[0];
363}
364
365// Partially expand a vector_reduce_mul wider than M1 to reduce
366// register pressure and the number of vsetvlis required.
367bool RISCVCodeGenPrepareImpl::expandMulReduction(IntrinsicInst &II) {
368 if (II.getIntrinsicID() != Intrinsic::vector_reduce_mul)
369 return false;
370
371 if (!ST->hasVInstructions())
372 return false;
373
374 Value *TmpVec = II.getArgOperand(i: 0);
375 auto *VecTy = cast<VectorType>(Val: TmpVec->getType());
376 unsigned EltSize = VecTy->getScalarSizeInBits();
377
378 if (auto *ScalTy = dyn_cast<ScalableVectorType>(Val: VecTy)) {
379 unsigned MinElts = ScalTy->getMinNumElements();
380
381 if (auto VLen = ST->getRealVLen()) {
382 // If VLEN is exactly known, convert to a fixed vector reduction and
383 // recurse to let the fixed path handle it (shuffle reduction instead
384 // of a scalar loop).
385 unsigned VScale = *VLen / RISCV::RVVBitsPerBlock;
386 auto *FixedTy =
387 FixedVectorType::get(ElementType: VecTy->getElementType(), NumElts: MinElts * VScale);
388 IRBuilder<> Builder(&II);
389 Value *Fixed = Builder.CreateExtractVector(DstType: FixedTy, SrcVec: TmpVec, Idx: (uint64_t)0);
390 auto *FixedRdx = cast<IntrinsicInst>(Val: Builder.CreateIntrinsic(
391 ID: Intrinsic::vector_reduce_mul, OverloadTypes: {FixedTy}, Args: {Fixed}));
392 II.replaceAllUsesWith(V: FixedRdx);
393 II.eraseFromParent();
394 expandMulReduction(II&: *FixedRdx);
395 return true;
396 }
397
398 unsigned M1MinElts = RISCV::RVVBitsPerBlock / EltSize;
399 if (MinElts <= M1MinElts || !isPowerOf2_32(Value: MinElts / M1MinElts))
400 return false;
401
402 IRBuilder<> Builder(&II);
403 auto M1EC = ElementCount::getScalable(MinVal: M1MinElts);
404 Value *Reduced = buildMulTree(Builder, PieceEC: M1EC, Vec: TmpVec);
405 Value *Rdx = Builder.CreateIntrinsic(ID: Intrinsic::vector_reduce_mul,
406 OverloadTypes: {Reduced->getType()}, Args: {Reduced});
407 II.replaceAllUsesWith(V: Rdx);
408 II.eraseFromParent();
409 return true;
410 }
411
412 unsigned VF = cast<FixedVectorType>(Val: VecTy)->getNumElements();
413 unsigned MinVLen = ST->getRealMinVLen();
414 unsigned M1VF = MinVLen / EltSize;
415
416 if (!isPowerOf2_32(Value: VF) || VF <= M1VF)
417 return false;
418
419 IRBuilder<> Builder(&II);
420 auto M1EC = ElementCount::getFixed(MinVal: M1VF);
421 auto *M1Ty = VectorType::get(ElementType: VecTy->getElementType(), EC: M1EC);
422
423 // When VLEN is exactly known, extract m1 pieces and build a mul tree.
424 // This greatly reduces register pressure during the reduction, and
425 // avoids all but one vsetvli (the one from original LMUL to m1).
426 // TODO: Generalize to handle the splitting case.
427 if (MinVLen == ST->getRealMaxVLen() && VF <= 8 * M1VF) {
428 TmpVec = buildMulTree(Builder, PieceEC: M1EC, Vec: TmpVec);
429 } else {
430 // For non-exact VLEN, shuffle-reduce at the original vector width down to
431 // m1, then extract. This prioritizes reducing the number of vsetvli
432 // over maximal reduction of LMUL for the intermediate states.
433 SmallVector<int, 32> ShuffleMask(VF);
434 for (unsigned LiveElts = VF; LiveElts > M1VF; LiveElts /= 2) {
435 unsigned Half = LiveElts / 2;
436 std::iota(first: ShuffleMask.begin(), last: ShuffleMask.begin() + Half, value: Half);
437 std::fill(first: ShuffleMask.begin() + Half, last: ShuffleMask.end(), value: -1);
438 Value *Shuf =
439 Builder.CreateShuffleVector(V: TmpVec, Mask: ShuffleMask, Name: "rdx.shuf");
440 TmpVec = Builder.CreateMul(LHS: TmpVec, RHS: Shuf, Name: "bin.rdx");
441 }
442 // Extract the M1-sized subvector and emit the final reduction intrinsic.
443 // This is the reason we're here - to force a vsetvli toggle once at m1.
444 TmpVec = Builder.CreateExtractVector(DstType: M1Ty, SrcVec: TmpVec, Idx: (uint64_t)0, Name: "rdx.sub");
445 }
446
447 Value *Rdx =
448 Builder.CreateIntrinsic(ID: Intrinsic::vector_reduce_mul, OverloadTypes: {M1Ty}, Args: {TmpVec});
449 II.replaceAllUsesWith(V: Rdx);
450 II.eraseFromParent();
451 return true;
452}
453
454// Always expand zero strided loads so we match more .vx splat patterns, even if
455// we have +optimized-zero-stride-loads. RISCVDAGToDAGISel::Select will convert
456// it back to a strided load if it's optimized.
457bool RISCVCodeGenPrepareImpl::expandVPStrideLoad(IntrinsicInst &II) {
458 Value *BasePtr, *VL;
459
460 using namespace PatternMatch;
461 if (!match(V: &II, P: m_Intrinsic<Intrinsic::experimental_vp_strided_load>(
462 Ops: m_Value(V&: BasePtr), Ops: m_Zero(), Ops: m_AllOnes(), Ops: m_Value(V&: VL))))
463 return false;
464
465 // If SEW>XLEN then a splat will get lowered as a zero strided load anyway, so
466 // avoid expanding here.
467 if (II.getType()->getScalarSizeInBits() > ST->getXLen())
468 return false;
469
470 if (!isKnownNonZero(V: VL, Q: {*DL, DT, nullptr, &II}))
471 return false;
472
473 auto *VTy = cast<VectorType>(Val: II.getType());
474
475 IRBuilder<> Builder(&II);
476 Type *STy = VTy->getElementType();
477 Value *Val = Builder.CreateLoad(Ty: STy, Ptr: BasePtr);
478 Value *Res = Builder.CreateIntrinsic(
479 ID: Intrinsic::vp_merge, OverloadTypes: VTy,
480 Args: {II.getOperand(i_nocapture: 2), Builder.CreateVectorSplat(EC: VTy->getElementCount(), V: Val),
481 PoisonValue::get(T: VTy), VL});
482
483 II.replaceAllUsesWith(V: Res);
484 II.eraseFromParent();
485 return true;
486}
487
488bool RISCVCodeGenPrepareImpl::run() {
489 bool MadeChange = false;
490 for (auto &BB : F)
491 for (Instruction &I : llvm::make_early_inc_range(Range&: BB))
492 MadeChange |= visit(I);
493
494 return MadeChange;
495}
496
497bool RISCVCodeGenPrepareLegacy::runOnFunction(Function &F) {
498 if (skipFunction(F))
499 return false;
500
501 auto &TPC = getAnalysis<TargetPassConfig>();
502 auto &TM = TPC.getTM<RISCVTargetMachine>();
503 auto ST = &TM.getSubtarget<RISCVSubtarget>(F);
504 auto DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
505
506 RISCVCodeGenPrepareImpl RVCGP(F, DT, ST);
507 return RVCGP.run();
508}
509
510INITIALIZE_PASS_BEGIN(RISCVCodeGenPrepareLegacy, DEBUG_TYPE, PASS_NAME, false,
511 false)
512INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
513INITIALIZE_PASS_END(RISCVCodeGenPrepareLegacy, DEBUG_TYPE, PASS_NAME, false,
514 false)
515
516char RISCVCodeGenPrepareLegacy::ID = 0;
517
518FunctionPass *llvm::createRISCVCodeGenPrepareLegacyPass() {
519 return new RISCVCodeGenPrepareLegacy();
520}
521
522PreservedAnalyses RISCVCodeGenPreparePass::run(Function &F,
523 FunctionAnalysisManager &FAM) {
524 DominatorTree *DT = &FAM.getResult<DominatorTreeAnalysis>(IR&: F);
525 auto ST = &TM->getSubtarget<RISCVSubtarget>(F);
526 bool Changed = RISCVCodeGenPrepareImpl(F, DT, ST).run();
527 if (!Changed)
528 return PreservedAnalyses::all();
529
530 PreservedAnalyses PA = PreservedAnalyses::none();
531 PA.preserveSet<CFGAnalyses>();
532 return PA;
533}
534