LLVM 24.0.0git
CombinerHelper.h
Go to the documentation of this file.
1//===-- llvm/CodeGen/GlobalISel/CombinerHelper.h --------------*- C++ -*-===//
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/// \file
9/// This contains common combine transformations that may be used in a combine
10/// pass,or by the target elsewhere.
11/// Targets can pick individual opcode transformations from the helper or use
12/// tryCombine which invokes all transformations. All of the transformations
13/// return true if the MachineInstruction changed and false otherwise.
14///
15//===--------------------------------------------------------------------===//
16
17#ifndef LLVM_CODEGEN_GLOBALISEL_COMBINERHELPER_H
18#define LLVM_CODEGEN_GLOBALISEL_COMBINERHELPER_H
19
20#include "llvm/ADT/DenseMap.h"
26#include "llvm/IR/InstrTypes.h"
27#include <functional>
28
29namespace llvm {
30
32class APInt;
33class ConstantFP;
34class GPtrAdd;
35class GZExtLoad;
39class MachineInstr;
40class MachineOperand;
42struct KnownBits;
44class LegalizerInfo;
45struct LegalityQuery;
46class RegisterBank;
48class TargetInstrInfo;
49class TargetLowering;
51
53 LLT Ty; // The result type of the extend.
54 unsigned ExtendOpcode; // G_ANYEXT/G_SEXT/G_ZEXT
56};
57
62 bool RematOffset = false; // True if Offset is a constant that needs to be
63 // rematerialized before the new load/store.
64 bool IsPre = false;
65};
66
68 int64_t Imm;
71 unsigned Flags;
72};
73
76 int64_t Imm;
77};
78
85
94
95using BuildFnTy = std::function<void(MachineIRBuilder &)>;
96
98 SmallVector<std::function<void(MachineInstrBuilder &)>, 4>;
100 unsigned Opcode = 0; /// The opcode for the produced instruction.
101 OperandBuildSteps OperandFns; /// Operands to be added to the instruction.
105};
106
108 /// Describes instructions to be built during a combine.
112 std::initializer_list<InstructionBuildSteps> InstrsToBuild)
114};
115
117protected:
128
129public:
131 bool IsPreLegalize, GISelValueTracking *VT = nullptr,
132 MachineDominatorTree *MDT = nullptr,
133 const LegalizerInfo *LI = nullptr);
134
136
138 return Builder;
139 }
140
141 const TargetInstrInfo &getTII() const { return *TII; }
142
143 const TargetRegisterInfo &getTRI() const { return *TRI; }
144
145 const RegisterBankInfo &getRBI() const { return *RBI; }
146
148
150
152
153 /// \returns true if the combiner is running pre-legalization.
154 LLVM_ABI bool isPreLegalize() const;
155
156 /// \returns true if \p Query is legal on the target.
157 LLVM_ABI bool isLegal(const LegalityQuery &Query) const;
158
159 /// \return true if the combine is running prior to legalization, or if \p
160 /// Query is legal on the target.
161 LLVM_ABI bool isLegalOrBeforeLegalizer(const LegalityQuery &Query) const;
162
163 /// \return true if \p Query is legal on the target, or if \p Query will
164 /// perform WidenScalar action on the target.
165 LLVM_ABI bool isLegalOrHasWidenScalar(const LegalityQuery &Query) const;
166
167 /// \return true if \p Query is legal on the target, or if \p Query will
168 /// perform a FewerElements action on the target.
169 LLVM_ABI bool isLegalOrHasFewerElements(const LegalityQuery &Query) const;
170
171 /// \return true if the combine is running prior to legalization, or if a
172 /// scalar \p Ty G_CONSTANT is legal. For fixed vectors, also requires
173 /// G_BUILD_VECTOR of those scalar constants to be legal. Scalable vectors are
174 /// not constant folded and return false.
175 LLVM_ABI bool isConstantLegalOrBeforeLegalizer(const LLT Ty) const;
176
177 /// \return true if the combine is running prior to legalization, or if a
178 /// scalar \p Ty G_FCONSTANT is legal. For fixed vectors, also requires
179 /// G_BUILD_VECTOR of those scalar constants to be legal. Scalable vectors are
180 /// not constant folded and return false.
182
183 /// MachineRegisterInfo::replaceRegWith() and inform the observer of the changes
185 Register ToReg) const;
186
187 /// Replace a single register operand with a new register and inform the
188 /// observer of the changes.
190 MachineOperand &FromRegOp,
191 Register ToReg) const;
192
193 /// Replace the opcode in instruction with a new opcode and inform the
194 /// observer of the changes.
196 unsigned ToOpcode) const;
197
198 /// Get the register bank of \p Reg.
199 /// If Reg has not been assigned a register, a register class,
200 /// or a register bank, then this returns nullptr.
201 ///
202 /// \pre Reg.isValid()
204
205 /// Set the register bank of \p Reg.
206 /// Does nothing if the RegBank is null.
207 /// This is the counterpart to getRegBank.
208 LLVM_ABI void setRegBank(Register Reg, const RegisterBank *RegBank) const;
209
212
213 /// Returns true if \p DefMI precedes \p UseMI or they are the same
214 /// instruction. Both must be in the same basic block.
216 const MachineInstr &UseMI) const;
217
218 /// Returns true if \p DefMI dominates \p UseMI. By definition an
219 /// instruction dominates itself.
220 ///
221 /// If we haven't been provided with a MachineDominatorTree during
222 /// construction, this function returns a conservative result that tracks just
223 /// a single basic block.
225 const MachineInstr &UseMI) const;
226
227 /// If \p MI is extend that consumes the result of a load, try to combine it.
228 /// Returns true if MI changed.
231 PreferredTuple &MatchInfo) const;
233 PreferredTuple &MatchInfo) const;
234
235 /// Match (and (load x), mask) -> zextload x
237 BuildFnTy &MatchInfo) const;
238
239 /// Combine a G_EXTRACT_VECTOR_ELT of a load into a narrowed
240 /// load.
242 BuildFnTy &MatchInfo) const;
243
244 LLVM_ABI bool
246 IndexedLoadStoreMatchInfo &MatchInfo) const;
247 LLVM_ABI void
249 IndexedLoadStoreMatchInfo &MatchInfo) const;
250
252
253 /// Match sext_inreg(load p), imm -> sextload p
254 LLVM_ABI bool
256 std::tuple<Register, unsigned> &MatchInfo) const;
257 LLVM_ABI void
259 std::tuple<Register, unsigned> &MatchInfo) const;
260
261 /// Try to combine G_[SU]DIV and G_[SU]REM into a single G_[SU]DIVREM
262 /// when their source operands are identical.
264 MachineInstr *&OtherMI) const;
266 MachineInstr *&OtherMI) const;
267
268 /// If a brcond's true block is not the fallthrough, make it so by inverting
269 /// the condition and swapping operands.
271 MachineInstr *&BrCond) const;
273 MachineInstr *&BrCond) const;
274
275 /// If \p MI is G_CONCAT_VECTORS, try to combine it.
276 /// Returns true if MI changed.
277 /// Right now, we support:
278 /// - concat_vector(undef, undef) => undef
279 /// - concat_vector(build_vector(A, B), build_vector(C, D)) =>
280 /// build_vector(A, B, C, D)
281 /// ==========================================================
282 /// Check if the G_CONCAT_VECTORS \p MI is undef or if it
283 /// can be flattened into a build_vector.
284 /// In the first case \p Ops will be empty
285 /// In the second case \p Ops will contain the operands
286 /// needed to produce the flattened build_vector.
287 ///
288 /// \pre MI.getOpcode() == G_CONCAT_VECTORS.
291 /// Replace \p MI with a flattened build_vector with \p Ops
292 /// or an implicit_def if \p Ops is empty.
295
298 /// Replace \p MI with a flattened build_vector with \p Ops
299 /// or an implicit_def if \p Ops is empty.
302
303 /// Replace shuffle \p MI with a build_vector.
305 /// Replace shuffle of build_vector with a build_vector.
307
308 /// Combine G_BUILD_VECTOR(G_UNMERGE(G_BITCAST), Undef) to
309 /// G_BITCAST(G_BUILD_VECTOR(..))
310 LLVM_ABI bool
313 LLVM_ABI void
316
317 /// Check if the G_SHUFFLE_VECTOR \p MI can be replaced by a
318 /// concat_vectors.
319 /// \p Ops will contain the operands needed to produce the flattened
320 /// concat_vectors.
321 ///
322 /// \pre MI.getOpcode() == G_SHUFFLE_VECTOR.
325 /// Replace \p MI with a concat_vectors with \p Ops.
327 ArrayRef<Register> Ops) const;
328
329 /// Optimize memcpy intrinsics et al, e.g. constant len calls.
330 /// /p MaxLen if non-zero specifies the max length of a mem libcall to inline.
331 ///
332 /// For example (pre-indexed):
333 ///
334 /// $addr = G_PTR_ADD $base, $offset
335 /// [...]
336 /// $val = G_LOAD $addr
337 /// [...]
338 /// $whatever = COPY $addr
339 ///
340 /// -->
341 ///
342 /// $val, $addr = G_INDEXED_LOAD $base, $offset, 1 (IsPre)
343 /// [...]
344 /// $whatever = COPY $addr
345 ///
346 /// or (post-indexed):
347 ///
348 /// G_STORE $val, $base
349 /// [...]
350 /// $addr = G_PTR_ADD $base, $offset
351 /// [...]
352 /// $whatever = COPY $addr
353 ///
354 /// -->
355 ///
356 /// $addr = G_INDEXED_STORE $val, $base, $offset
357 /// [...]
358 /// $whatever = COPY $addr
360 unsigned MaxLen = 0) const;
362 MemCpyFamilyLoweringInfo &MatchInfo,
363 unsigned MaxLen = 0) const;
364 LLVM_ABI void
366 MemCpyFamilyLoweringInfo &MatchInfo) const;
367
369 PtrAddChain &MatchInfo) const;
371 PtrAddChain &MatchInfo) const;
372
373 /// Fold (shift (shift base, x), y) -> (shift base (x+y))
375 RegisterImmPair &MatchInfo) const;
377 RegisterImmPair &MatchInfo) const;
378
379 /// If we have a shift-by-constant of a bitwise logic op that itself has a
380 /// shift-by-constant operand with identical opcode, we may be able to convert
381 /// that into 2 independent shifts followed by the logic op.
383 ShiftOfShiftedLogic &MatchInfo) const;
385 ShiftOfShiftedLogic &MatchInfo) const;
386
387 /// \return true if the target's TargetLowering::isDesirableToCommuteWithShift
388 /// hook approves of commuting \p MI (a G_SHL) with the binop feeding it.
390
391 /// Fold (lshr (trunc (lshr x, C1)), C2) -> trunc (shift x, (C1 + C2))
393 LshrOfTruncOfLshr &MatchInfo,
394 MachineInstr &ShiftMI) const;
396 LshrOfTruncOfLshr &MatchInfo) const;
397
398 /// Transform a multiply by a power-of-2 value to a left shift.
400 unsigned &ShiftVal) const;
402 unsigned &ShiftVal) const;
403
404 // Transform a G_SUB with constant on the RHS to G_ADD.
406 BuildFnTy &MatchInfo) const;
407
408 // Transform a G_SHL with an extended source into a narrower shift if
409 // possible.
411 RegisterImmPair &MatchData) const;
413 const RegisterImmPair &MatchData) const;
414
415 /// Reduce a shift by a constant to an unmerge and a shift on a half sized
416 /// type. This will not produce a shift smaller than \p TargetShiftSize.
418 unsigned TargetShiftSize,
419 unsigned &ShiftVal) const;
421 const unsigned &ShiftVal) const;
423 unsigned TargetShiftAmount) const;
424
425 /// Transform <ty,...> G_UNMERGE(G_MERGE ty X, Y, Z) -> ty X, Y, Z.
430
431 /// Transform G_UNMERGE Constant -> Constant1, Constant2, ...
433 SmallVectorImpl<APInt> &Csts) const;
435 SmallVectorImpl<APInt> &Csts) const;
436
437 /// Transform G_UNMERGE G_IMPLICIT_DEF -> G_IMPLICIT_DEF, G_IMPLICIT_DEF, ...
440 std::function<void(MachineIRBuilder &)> &MatchInfo) const;
441
442 /// Transform X, Y<dead> = G_UNMERGE Z -> X = G_TRUNC Z.
445
446 /// Transform X, Y = G_UNMERGE(G_ZEXT(Z)) -> X = G_ZEXT(Z); Y = G_CONSTANT 0
449
450 /// Constant fold a unary integer op (G_CTLZ, G_CTTZ, G_CTPOP and their
451 /// _ZERO_POISON variants, G_ABS, G_BSWAP, G_BITREVERSE) when the operand is
452 /// a scalar constant or a G_BUILD_VECTOR of constants.
454 BuildFnTy &MatchInfo) const;
455
456 /// Transform anyext(trunc(x)) to x.
458
459 /// Transform zext(trunc(x)) to x.
461
462 /// Transform trunc (shl x, K) to shl (trunc x), K
463 /// if K < VT.getScalarSizeInBits().
464 ///
465 /// Transforms trunc ([al]shr x, K) to (trunc ([al]shr (MidVT (trunc x)), K))
466 /// if K <= (MidVT.getScalarSizeInBits() - VT.getScalarSizeInBits())
467 /// MidVT is obtained by finding a legal type between the trunc's src and dst
468 /// types.
469 LLVM_ABI bool
471 std::pair<MachineInstr *, LLT> &MatchInfo) const;
472 LLVM_ABI void
474 std::pair<MachineInstr *, LLT> &MatchInfo) const;
475
476 /// Return true if all register explicit use operands on \p MI are defined by
477 /// a G_IMPLICIT_DEF.
479
480 /// Return true if a G_SHUFFLE_VECTOR instruction \p MI has an undef mask.
482
483 /// Return true if a G_{EXTRACT,INSERT}_VECTOR_ELT has an out of range index.
485
486 /// Replace an instruction with a G_FCONSTANT with value \p C.
488
489 /// Replace an instruction with an G_FCONSTANT with value \p CFP.
491 ConstantFP *CFP) const;
492
493 /// Replace an instruction with a G_CONSTANT with value \p C.
494 LLVM_ABI void replaceInstWithConstant(MachineInstr &MI, int64_t C) const;
495
496 /// Replace an instruction with a G_CONSTANT with value \p C.
498
499 /// Replace an instruction with a G_IMPLICIT_DEF.
501
502 /// Delete \p MI and replace all of its uses with its \p OpIdx-th operand.
504 unsigned OpIdx) const;
505
506 /// Delete \p MI and replace all of its uses with \p Replacement.
508 Register Replacement) const;
509
510 /// @brief Replaces the shift amount in \p MI with ShiftAmt % BW
511 /// @param MI
513
514 /// Return true if \p MOP1 and \p MOP2 are register operands are defined by
515 /// equivalent instructions.
516 LLVM_ABI bool matchEqualDefs(const MachineOperand &MOP1,
517 const MachineOperand &MOP2) const;
518
519 /// Return true if \p MOP is defined by a G_CONSTANT or splat with a value
520 /// equal to \p C.
521 LLVM_ABI bool matchConstantOp(const MachineOperand &MOP, int64_t C) const;
522
523 /// Return true if \p MOP is defined by a G_FCONSTANT or splat with a value exactly
524 /// equal to \p C.
525 LLVM_ABI bool matchConstantFPOp(const MachineOperand &MOP, double C) const;
526
527 /// @brief Checks if constant at \p ConstIdx is larger than \p MI 's bitwidth
528 /// @param ConstIdx Index of the constant
530 unsigned ConstIdx) const;
531
532 /// Optimize (cond ? x : x) -> x
534
535 /// Check if operand \p MO is known to be a power of 2. When \p OrNegative
536 /// is true, also match operands whose negation is a power of 2 (i.e. whose
537 /// absolute value is a power of 2). When \p OrZero is true, also match
538 /// operands that may be zero (i.e. that are known to be either zero or a
539 /// power of two).
541 bool OrNegative = false,
542 bool OrZero = false) const;
543
544 /// Erase \p MI
545 LLVM_ABI void eraseInst(MachineInstr &MI) const;
546
547 /// Fold `a bitwiseop (~b +/- c)` -> `a bitwiseop ~(b -/+ c)`
548 LLVM_ABI bool matchBinopWithNeg(MachineInstr &MI, BuildFnTy &MatchInfo) const;
549
550 /// Match (logic_op (op x...), (op y...)) -> (op (logic_op x, y))
552 MachineInstr &MI, InstructionStepsMatchInfo &MatchInfo) const;
553
554 /// Replace \p MI with a series of instructions described in \p MatchInfo.
555 LLVM_ABI void
557 InstructionStepsMatchInfo &MatchInfo) const;
558
559 /// Match ashr (shl x, C), C -> sext_inreg (C)
560 LLVM_ABI bool
562 std::tuple<Register, int64_t> &MatchInfo) const;
563 LLVM_ABI void
565 std::tuple<Register, int64_t> &MatchInfo) const;
566
567 /// Fold and(and(x, C1), C2) -> C1&C2 ? and(x, C1&C2) : 0
569 BuildFnTy &MatchInfo) const;
570
571 /// \return true if \p MI is a G_AND instruction whose operands are x and y
572 /// where x & y == x or x & y == y. (E.g., one of operands is all-ones value.)
573 ///
574 /// \param [in] MI - The G_AND instruction.
575 /// \param [out] Replacement - A register the G_AND should be replaced with on
576 /// success.
578 Register &Replacement) const;
579
580 /// \return true if \p MI is a G_OR instruction whose operands are x and y
581 /// where x | y == x or x | y == y. (E.g., one of operands is all-zeros
582 /// value.)
583 ///
584 /// \param [in] MI - The G_OR instruction.
585 /// \param [out] Replacement - A register the G_OR should be replaced with on
586 /// success.
587 LLVM_ABI bool matchRedundantOr(MachineInstr &MI, Register &Replacement) const;
588
589 /// \return true if \p MI is a G_SEXT_INREG that can be erased.
591
592 /// Combine inverting a result of a compare into the opposite cond code.
594 SmallVectorImpl<Register> &RegsToNegate) const;
596 SmallVectorImpl<Register> &RegsToNegate) const;
597
598 /// Fold (xor (and x, y), y) -> (and (not x), y)
599 ///{
600 LLVM_ABI bool
602 std::pair<Register, Register> &MatchInfo) const;
603 LLVM_ABI void
605 std::pair<Register, Register> &MatchInfo) const;
606 ///}
607
608 /// Combine a vector G_PTR_ADD with a zero splat to G_INTTOPTR.
610
611 /// Combine G_UREM x, (known power of 2) to an add and bitmasking.
613
614 /// Push a binary operator through a select on constants.
615 ///
616 /// binop (select cond, K0, K1), K2 ->
617 /// select cond, (binop K0, K2), (binop K1, K2)
619 unsigned &SelectOpNo) const;
621 const unsigned &SelectOpNo) const;
622
623 LLVM_ABI bool
625 SmallVectorImpl<Register> &MatchInfo) const;
626
627 LLVM_ABI void
629 SmallVectorImpl<Register> &MatchInfo) const;
630
631 /// Match expression trees of the form
632 ///
633 /// \code
634 /// sN *a = ...
635 /// sM val = a[0] | (a[1] << N) | (a[2] << 2N) | (a[3] << 3N) ...
636 /// \endcode
637 ///
638 /// And check if the tree can be replaced with a M-bit load + possibly a
639 /// bswap.
641 BuildFnTy &MatchInfo) const;
642
644 MachineInstr *&ExtMI) const;
646 MachineInstr *&ExtMI) const;
647
649 Register &Reg) const;
651 Register &Reg) const;
652
655 SmallVectorImpl<std::pair<Register, MachineInstr *>> &MatchInfo) const;
658 SmallVectorImpl<std::pair<Register, MachineInstr *>> &MatchInfo) const;
659
660 /// Use a function which takes in a MachineIRBuilder to perform a combine.
661 /// By default, it erases the instruction \p MI from the function.
662 LLVM_ABI void applyBuildFn(MachineInstr &MI, BuildFnTy &MatchInfo) const;
663 /// Use a function which takes in a MachineIRBuilder to perform a combine.
664 /// This variant does not erase \p MI after calling the build function.
666 BuildFnTy &MatchInfo) const;
667
669 bool AllowScalarConstants,
670 BuildFnTy &MatchInfo) const;
673
676 Register &UnmergeSrc) const;
680 Register &UnmergeSrc) const;
681
683 Register &MatchInfo) const;
685 Register &MatchInfo) const;
686
687 /// \returns true if a G_ICMP instruction \p MI can be replaced with a true
688 /// or false constant based off of KnownBits information.
690 int64_t &MatchInfo) const;
691
692 /// \returns true if a G_ICMP \p MI can be replaced with its LHS based off of
693 /// KnownBits information.
695 BuildFnTy &MatchInfo) const;
696
697 /// \returns true if (and (or x, c1), c2) can be replaced with (and x, c2)
699 BuildFnTy &MatchInfo) const;
700
702 BuildFnTy &MatchInfo) const;
703 /// Match: and (lshr x, cst), mask -> ubfx x, cst, width
705 BuildFnTy &MatchInfo) const;
706
707 /// Match: shr (shl x, n), k -> sbfx/ubfx x, pos, width
709 BuildFnTy &MatchInfo) const;
710
711 /// Match: shr (and x, n), k -> ubfx x, pos, width
713 BuildFnTy &MatchInfo) const;
714
715 // Helpers for reassociation:
717 BuildFnTy &MatchInfo) const;
721 BuildFnTy &MatchInfo) const;
724 BuildFnTy &MatchInfo) const;
725 /// Reassociate pointer calculations with G_ADD involved, to allow better
726 /// addressing mode usage.
728 BuildFnTy &MatchInfo) const;
729
730 /// Try to reassociate to reassociate operands of a commutative binop.
731 LLVM_ABI bool tryReassocBinOp(unsigned Opc, Register DstReg, Register Op0,
732 Register Op1, BuildFnTy &MatchInfo) const;
733 /// Reassociate commutative binary operations like G_ADD.
735 BuildFnTy &MatchInfo) const;
736
737 /// Do constant folding when opportunities are exposed after MIR building.
739 BuildFnTy &MatchInfo) const;
740
741 /// Do constant folding when opportunities are exposed after MIR building.
743 BuildFnTy &MatchInfo) const;
744
745 /// Do constant FP folding when opportunities are exposed after MIR building.
747 BuildFnTy &MatchInfo) const;
748
749 /// Constant fold a unary FP operation when the source is constant.
751 BuildFnTy &MatchInfo) const;
752
753 /// Constant fold G_FMA/G_FMAD.
755 BuildFnTy &MatchInfo) const;
756
757 /// \returns true if it is possible to narrow the width of a scalar binop
758 /// feeding a G_AND instruction \p MI.
760 BuildFnTy &MatchInfo) const;
761
762 /// Given an G_UDIV \p MI or G_UREM \p MI expressing a divide by constant,
763 /// return an expression that implements it by multiplying by a magic number.
764 /// Ref: "Hacker's Delight" or "The PowerPC Compiler Writer's Guide".
766 /// Combine G_UDIV or G_UREM by constant into a multiply by magic constant.
769
770 /// Given an G_SDIV \p MI or G_SREM \p MI expressing a signed divide by
771 /// constant, return an expression that implements it by multiplying by a
772 /// magic number. Ref: "Hacker's Delight" or "The PowerPC Compiler Writer's
773 /// Guide".
775 /// Combine G_SDIV or G_SREM by constant into a multiply by magic constant.
778
779 /// Given an G_SDIV \p MI expressing a signed divided by a pow2 constant,
780 /// return expressions that implements it by shifting.
781 LLVM_ABI bool matchDivByPow2(MachineInstr &MI, bool IsSigned) const;
783 /// Given an G_UDIV \p MI expressing an unsigned divided by a pow2 constant,
784 /// return expressions that implements it by shifting.
786
787 /// Combine unsigned division by a shifted power of two into a right shift.
789 BuildFnTy &MatchInfo) const;
790
791 /// Convert signed division or remainder of nonnegative operands to unsigned.
793 unsigned UnsignedOpcode) const;
794
795 /// Combine G_SREM x, (+/-2^k) to a bias-and-mask sequence.
797
798 // G_UMULH x, (1 << c)) -> x >> (bitwidth - c)
801
802 // Combine trunc(smin(smax(x, C1), C2)) -> truncssat_s(x)
803 // or trunc(smax(smin(x, C2), C1)) -> truncssat_s(x).
804 LLVM_ABI bool matchTruncSSatS(MachineInstr &MI, Register &MatchInfo) const;
805 LLVM_ABI void applyTruncSSatS(MachineInstr &MI, Register &MatchInfo) const;
806
807 // Combine trunc(smin(smax(x, 0), C)) -> truncssat_u(x)
808 // or trunc(smax(smin(x, C), 0)) -> truncssat_u(x)
809 // or trunc(umin(smax(x, 0), C)) -> truncssat_u(x)
810 LLVM_ABI bool matchTruncSSatU(MachineInstr &MI, Register &MatchInfo) const;
811 LLVM_ABI void applyTruncSSatU(MachineInstr &MI, Register &MatchInfo) const;
812
813 // Combine trunc(umin(x, C)) -> truncusat_u(x).
815
816 // Combine truncusat_u(fptoui(x)) -> fptoui_sat(x)
818 MachineInstr &SrcMI) const;
819
820 /// Match:
821 /// (G_*MULO x, 0) -> 0 + no carry out
822 LLVM_ABI bool matchMulOBy0(MachineInstr &MI, BuildFnTy &MatchInfo) const;
823
825
826 LLVM_ABI bool canCombineFMadOrFMA(MachineInstr &MI, bool &AllowFusionGlobally,
827 bool &HasFMAD, bool &Aggressive,
828 bool CanReassociate = false) const;
829
830 /// Transform (fadd (fmul x, y), z) -> (fma x, y, z)
831 /// (fadd (fmul x, y), z) -> (fmad x, y, z)
833 BuildFnTy &MatchInfo) const;
834
835 /// Transform (fadd (fpext (fmul x, y)), z) -> (fma (fpext x), (fpext y), z)
836 /// (fadd (fpext (fmul x, y)), z) -> (fmad (fpext x), (fpext y), z)
837 LLVM_ABI bool
839 BuildFnTy &MatchInfo) const;
840
841 /// Transform (fadd (fma x, y, (fmul u, v)), z) -> (fma x, y, (fma u, v, z))
842 /// (fadd (fmad x, y, (fmul u, v)), z) -> (fmad x, y, (fmad u, v, z))
844 BuildFnTy &MatchInfo) const;
845
846 // Transform (fadd (fma x, y, (fpext (fmul u, v))), z)
847 // -> (fma x, y, (fma (fpext u), (fpext v), z))
848 // (fadd (fmad x, y, (fpext (fmul u, v))), z)
849 // -> (fmad x, y, (fmad (fpext u), (fpext v), z))
850 LLVM_ABI bool
852 BuildFnTy &MatchInfo) const;
853
854 /// Transform (fsub (fmul x, y), z) -> (fma x, y, -z)
855 /// (fsub (fmul x, y), z) -> (fmad x, y, -z)
857 BuildFnTy &MatchInfo) const;
858
859 /// Transform (fsub (fneg (fmul, x, y)), z) -> (fma (fneg x), y, (fneg z))
860 /// (fsub (fneg (fmul, x, y)), z) -> (fmad (fneg x), y, (fneg z))
862 BuildFnTy &MatchInfo) const;
863
864 /// Transform (fsub (fpext (fmul x, y)), z)
865 /// -> (fma (fpext x), (fpext y), (fneg z))
866 /// (fsub (fpext (fmul x, y)), z)
867 /// -> (fmad (fpext x), (fpext y), (fneg z))
868 LLVM_ABI bool
870 BuildFnTy &MatchInfo) const;
871
872 /// Transform (fsub (fpext (fneg (fmul x, y))), z)
873 /// -> (fneg (fma (fpext x), (fpext y), z))
874 /// (fsub (fpext (fneg (fmul x, y))), z)
875 /// -> (fneg (fmad (fpext x), (fpext y), z))
876 LLVM_ABI bool
878 BuildFnTy &MatchInfo) const;
879
880 LLVM_ABI bool
882 SmallVector<MachineInstr *> &MatchInfo) const;
883 LLVM_ABI void
885
887 Register &MatchInfo) const;
889 Register &MatchInfo) const;
891 Register &MatchInfo) const;
892
893 /// True when \p A and \p B are the same register, including through copies,
894 /// or different registers holding the same scalar or splat integer constant.
896
898
899 /// \returns true if it is possible to simplify a select instruction \p MI
900 /// to a min/max instruction of some sort.
902 BuildFnTy &MatchInfo) const;
903
904 /// Transform:
905 /// (X + Y) == X -> Y == 0
906 /// (X - Y) == X -> Y == 0
907 /// (X ^ Y) == X -> Y == 0
908 /// (X + Y) != X -> Y != 0
909 /// (X - Y) != X -> Y != 0
910 /// (X ^ Y) != X -> Y != 0
912 BuildFnTy &MatchInfo) const;
913
914 /// Match shifts greater or equal to the range (the bitwidth of the result
915 /// datatype, or the effective bitwidth of the source value).
916 LLVM_ABI bool matchShiftsTooBig(MachineInstr &MI, BuildFnTy &MatchInfo) const;
917
918 /// Match constant LHS ops that should be commuted.
920
921 /// Combine sext of trunc.
923 BuildFnTy &MatchInfo) const;
924
925 /// Combine zext of trunc.
927 BuildFnTy &MatchInfo) const;
928
929 /// Combine zext nneg to sext.
931 BuildFnTy &MatchInfo) const;
932
933 /// Match constant LHS FP ops that should be commuted.
935
936 /// Combine select to integer min/max.
938 BuildFnTy &MatchInfo) const;
939
940 /// Tranform (neg (min/max x, (neg x))) into (max/min x, (neg x)).
942 BuildFnTy &MatchInfo) const;
943
944 /// Combine selects.
945 LLVM_ABI bool matchSelect(MachineInstr &MI, BuildFnTy &MatchInfo) const;
946
947 /// Combine ands.
948 LLVM_ABI bool matchAnd(MachineInstr &MI, BuildFnTy &MatchInfo) const;
949
950 /// Combine ors.
951 LLVM_ABI bool matchOr(MachineInstr &MI, BuildFnTy &MatchInfo) const;
952
953 /// trunc (binop X, C) --> binop (trunc X, trunc C).
954 LLVM_ABI bool matchNarrowBinop(const MachineInstr &TruncMI,
955 const MachineInstr &BinopMI,
956 BuildFnTy &MatchInfo) const;
957
958 LLVM_ABI bool matchCastOfInteger(const MachineInstr &CastMI,
959 BuildFnTy &MatchInfo) const;
960
961 /// Combine addos.
962 LLVM_ABI bool matchAddOverflow(MachineInstr &MI, BuildFnTy &MatchInfo) const;
963
964 /// Combine extract vector element.
966
967 /// Combine extract vector element with a build vector on the vector register.
968 LLVM_ABI bool
970 const MachineInstr &MI2,
971 BuildFnTy &MatchInfo) const;
972
973 /// Combine extract vector element with a build vector trunc on the vector
974 /// register.
975 LLVM_ABI bool
977 BuildFnTy &MatchInfo) const;
978
979 /// Combine extract vector element with a shuffle vector on the vector
980 /// register.
981 LLVM_ABI bool
983 const MachineInstr &MI2,
984 BuildFnTy &MatchInfo) const;
985
986 /// Combine extract vector element with a insert vector element on the vector
987 /// register and different indices.
988 LLVM_ABI bool
990 BuildFnTy &MatchInfo) const;
991
992 /// Remove references to rhs if it is undef
994 BuildFnTy &MatchInfo) const;
995
996 /// Turn shuffle a, b, mask -> shuffle undef, b, mask iff mask does not
997 /// reference a.
999 BuildFnTy &MatchInfo) const;
1000
1001 /// Use a function which takes in a MachineIRBuilder to perform a combine.
1002 /// By default, it erases the instruction def'd on \p MO from the function.
1003 LLVM_ABI void applyBuildFnMO(const MachineOperand &MO,
1004 BuildFnTy &MatchInfo) const;
1005
1006 /// Match FPOWI if it's safe to extend it into a series of multiplications.
1007 LLVM_ABI bool matchFPowIExpansion(MachineInstr &MI, int64_t Exponent) const;
1008
1009 /// Expands FPOWI into a series of multiplications and a division if the
1010 /// exponent is negative.
1011 LLVM_ABI void applyExpandFPowI(MachineInstr &MI, int64_t Exponent) const;
1012
1013 /// Combine insert vector element OOB.
1015
1016 LLVM_ABI bool
1018 BuildFnTy &MatchInfo) const;
1019
1021 BuildFnTy &MatchInfo) const;
1022
1024 BuildFnTy &MatchInfo) const;
1025
1027 BuildFnTy &MatchInfo) const;
1028
1030 BuildFnTy &MatchInfo) const;
1031
1032 /// Transform trunc ([asz]ext x) to x or ([asz]ext x) or (trunc x).
1033 LLVM_ABI bool matchTruncateOfExt(const MachineInstr &Root,
1034 const MachineInstr &ExtMI,
1035 BuildFnTy &MatchInfo) const;
1036
1037 LLVM_ABI bool matchCastOfSelect(const MachineInstr &Cast,
1038 const MachineInstr &SelectMI,
1039 BuildFnTy &MatchInfo) const;
1041 BuildFnTy &MatchInfo) const;
1042
1044 BuildFnTy &MatchInfo) const;
1045
1047 BuildFnTy &MatchInfo) const;
1048
1050 BuildFnTy &MatchInfo) const;
1051
1052 // fold ((A-C1)+C2) -> (A+(C2-C1))
1054 BuildFnTy &MatchInfo) const;
1055
1056 LLVM_ABI bool matchExtOfExt(const MachineInstr &FirstMI,
1057 const MachineInstr &SecondMI,
1058 BuildFnTy &MatchInfo) const;
1059
1060 LLVM_ABI bool matchCastOfBuildVector(const MachineInstr &CastMI,
1061 const MachineInstr &BVMI,
1062 BuildFnTy &MatchInfo) const;
1063
1065 BuildFnTy &MatchInfo) const;
1067 BuildFnTy &MatchInfo) const;
1068
1069 // unmerge_values(anyext(build vector)) -> build vector(anyext)
1071 BuildFnTy &MatchInfo) const;
1072
1073 // overflow sub
1075 BuildFnTy &MatchInfo) const;
1076
1077 // (sext_inreg (sext_inreg x, K0), K1)
1079 BuildFnTy &MatchInfo) const;
1080
1081 // (ctlz (xor x, (sra x, bitwidth-1))) -> (add (ctls x), 1) or
1082 // (ctlz (or (shl (xor x, (sra x, bitwidth-1)), 1), 1) -> (ctls x)
1083 LLVM_ABI bool matchCtls(MachineInstr &CtlzMI, BuildFnTy &MatchInfo) const;
1084
1086 unsigned ZeroPoisonOpc) const;
1087
1088 /// Simplify a register use under \p DemandedBits and compute \p Known in
1089 /// the same walk. Partial-demand rewrites of shared values update only this
1090 /// use.
1091 LLVM_ABI bool simplifyDemandedBits(MachineInstr &MI, unsigned OpNo,
1092 const APInt &DemandedBits,
1094 unsigned Depth = 0) const;
1095
1096 /// Match demanded-bits simplification of a root's register use.
1098 BuildFnTy &MatchInfo) const;
1099
1100private:
1101 Register simplifyMultipleUseDemandedBits(Register R,
1102 const APInt &DemandedBits,
1103 unsigned Depth) const;
1104
1105 /// Walk a use operand; \p DoRewrite false probes without changing MIR.
1106 bool simplifyDemandedBitsImpl(MachineInstr &MI, unsigned OpNo,
1108 unsigned Depth, bool DoRewrite) const;
1109
1110 /// Checks for legality of an indexed variant of \p LdSt.
1111 bool isIndexedLoadStoreLegal(GLoadStore &LdSt) const;
1112
1113 /// \return true if the combine is running prior to legalization, or if a
1114 /// scalar \p Ty \p Opc (G_CONSTANT or G_FCONSTANT) is legal. For fixed
1115 /// vectors, also requires G_BUILD_VECTOR of those scalar constants to be
1116 /// legal. Scalable vectors are not constant folded and return false.
1117 bool isImmConstantLegalOrBeforeLegalizer(unsigned Opc, const LLT Ty) const;
1118
1119 /// Helper function for matchBinopWithNeg: tries to match one commuted form
1120 /// of `a bitwiseop (~b +/- c)` -> `a bitwiseop ~(b -/+ c)`.
1121 bool matchBinopWithNegInner(Register MInner, Register Other, unsigned RootOpc,
1122 Register Dst, LLT Ty, BuildFnTy &MatchInfo) const;
1123 /// Given a non-indexed load or store instruction \p MI, find an offset that
1124 /// can be usefully and legally folded into it as a post-indexing operation.
1125 ///
1126 /// \returns true if a candidate is found.
1127 bool findPostIndexCandidate(GLoadStore &MI, Register &Addr, Register &Base,
1128 Register &Offset, bool &RematOffset) const;
1129
1130 /// Given a non-indexed load or store instruction \p MI, find an offset that
1131 /// can be usefully and legally folded into it as a pre-indexing operation.
1132 ///
1133 /// \returns true if a candidate is found.
1134 bool findPreIndexCandidate(GLoadStore &MI, Register &Addr, Register &Base,
1135 Register &Offset) const;
1136
1137 /// Helper function for matchLoadOrCombine. Searches for Registers
1138 /// which may have been produced by a load instruction + some arithmetic.
1139 ///
1140 /// \param [in] Root - The search root.
1141 ///
1142 /// \returns The Registers found during the search.
1143 std::optional<SmallVector<Register, 8>>
1144 findCandidatesForLoadOrCombine(const MachineInstr *Root) const;
1145
1146 /// Helper function for matchLoadOrCombine.
1147 ///
1148 /// Checks if every register in \p RegsToVisit is defined by a load
1149 /// instruction + some arithmetic.
1150 ///
1151 /// \param [out] MemOffset2Idx - Maps the byte positions each load ends up
1152 /// at to the index of the load.
1153 /// \param [in] MemSizeInBits - The number of bits each load should produce.
1154 ///
1155 /// \returns On success, a 3-tuple containing lowest-index load found, the
1156 /// lowest index, and the last load in the sequence.
1157 std::optional<std::tuple<GZExtLoad *, int64_t, GZExtLoad *>>
1158 findLoadOffsetsForLoadOrCombine(
1160 const SmallVector<Register, 8> &RegsToVisit,
1161 const unsigned MemSizeInBits) const;
1162
1163 /// Examines the G_PTR_ADD instruction \p PtrAdd and determines if performing
1164 /// a re-association of its operands would break an existing legal addressing
1165 /// mode that the address computation currently represents.
1166 bool reassociationCanBreakAddressingModePattern(MachineInstr &PtrAdd) const;
1167
1168 /// Behavior when a floating point min/max is given one NaN and one
1169 /// non-NaN as input.
1170 enum class SelectPatternNaNBehaviour {
1171 NOT_APPLICABLE = 0, /// NaN behavior not applicable.
1172 RETURNS_NAN, /// Given one NaN input, returns the NaN.
1173 RETURNS_OTHER, /// Given one NaN input, returns the non-NaN.
1174 RETURNS_ANY /// Given one NaN input, can return either (or both operands are
1175 /// known non-NaN.)
1176 };
1177
1178 /// \returns which of \p LHS and \p RHS would be the result of a non-equality
1179 /// floating point comparison where one of \p LHS and \p RHS may be NaN.
1180 ///
1181 /// If both \p LHS and \p RHS may be NaN, returns
1182 /// SelectPatternNaNBehaviour::NOT_APPLICABLE.
1183 SelectPatternNaNBehaviour
1184 computeRetValAgainstNaN(Register LHS, Register RHS,
1185 bool IsOrderedComparison) const;
1186
1187 /// Determines the floating point min/max opcode which should be used for
1188 /// a G_SELECT fed by a G_FCMP with predicate \p Pred.
1189 ///
1190 /// \returns 0 if this G_SELECT should not be combined to a floating point
1191 /// min or max. If it should be combined, returns one of
1192 ///
1193 /// * G_FMAXNUM
1194 /// * G_FMAXIMUM
1195 /// * G_FMINNUM
1196 /// * G_FMINIMUM
1197 ///
1198 /// Helper function for matchFPSelectToMinMax.
1199 unsigned getFPMinMaxOpcForSelect(CmpInst::Predicate Pred, LLT DstTy,
1200 SelectPatternNaNBehaviour VsNaNRetVal) const;
1201
1202 /// Handle floating point cases for matchSimplifySelectToMinMax.
1203 ///
1204 /// E.g.
1205 ///
1206 /// select (fcmp uge x, 1.0) x, 1.0 -> fmax x, 1.0
1207 /// select (fcmp uge x, 1.0) 1.0, x -> fminnm x, 1.0
1208 bool matchFPSelectToMinMax(Register Dst, Register Cond, Register TrueVal,
1209 Register FalseVal, BuildFnTy &MatchInfo) const;
1210
1211 /// Try to fold selects to logical operations.
1212 bool tryFoldBoolSelectToLogic(GSelect *Select, BuildFnTy &MatchInfo) const;
1213
1214 bool tryFoldSelectOfConstants(GSelect *Select, BuildFnTy &MatchInfo) const;
1215
1216 bool isOneOrOneSplat(Register Src, bool AllowUndefs) const;
1217 bool isZeroOrZeroSplat(Register Src, bool AllowUndefs) const;
1218 bool isConstantSplatVector(Register Src, int64_t SplatValue,
1219 bool AllowUndefs) const;
1220 bool isConstantOrConstantVectorI(Register Src) const;
1221
1222 std::optional<APInt> getConstantOrConstantSplatVector(Register Src) const;
1223
1224 /// Fold (icmp Pred1 V1, C1) && (icmp Pred2 V2, C2)
1225 /// or (icmp Pred1 V1, C1) || (icmp Pred2 V2, C2)
1226 /// into a single comparison using range-based reasoning.
1227 bool tryFoldAndOrOrICmpsUsingRanges(GLogicalBinOp *Logic,
1228 BuildFnTy &MatchInfo) const;
1229
1230 // Simplify (cmp cc0 x, y) (&& or ||) (cmp cc1 x, y) -> cmp cc2 x, y.
1231 bool tryFoldLogicOfFCmps(GLogicalBinOp *Logic, BuildFnTy &MatchInfo) const;
1232
1233 bool isCastFree(unsigned Opcode, LLT ToTy, LLT FromTy) const;
1234
1235 bool constantFoldICmp(const GICmp &ICmp, const GIConstant &LHSCst,
1236 const GIConstant &RHSCst, BuildFnTy &MatchInfo) const;
1237 bool constantFoldFCmp(const GFCmp &FCmp, const GFConstant &LHSCst,
1238 const GFConstant &RHSCst, BuildFnTy &MatchInfo) const;
1239};
1240} // namespace llvm
1241
1242#endif
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
SDValue Pred
uint64_t uint64_t
AMDGPU Register Bank Select
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
This file defines the DenseMap class.
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
IRTranslator LLVM IR MI
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static bool isConstantSplatVector(SDValue N, APInt &SplatValue, unsigned MinSizeInBits)
Implement a low-level type suitable for MachineInstr level instruction selection.
Register Reg
Promote Memory to Register
Definition Mem2Reg.cpp:110
SmallVector< MachineOperand, 4 > Cond
MachineRegisterInfo & MRI
SI Fold Operands
This file defines the SmallVector class.
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
LLVM_ABI void applyCombineBuildVectorOfBitcast(MachineInstr &MI, SmallVector< Register > &Ops) const
LLVM_ABI void applyCombineExtendingLoads(MachineInstr &MI, PreferredTuple &MatchInfo) const
LLVM_ABI bool matchRepeatedFPDivisor(MachineInstr &MI, SmallVector< MachineInstr * > &MatchInfo) const
LLVM_ABI bool isFPConstantLegalOrBeforeLegalizer(const LLT Ty) const
LLVM_ABI bool matchFoldC2MinusAPlusC1(const MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchLoadOrCombine(MachineInstr &MI, BuildFnTy &MatchInfo) const
Match expression trees of the form.
LLVM_ABI const RegisterBank * getRegBank(Register Reg) const
Get the register bank of Reg.
LLVM_ABI bool matchEqualDefs(const MachineOperand &MOP1, const MachineOperand &MOP2) const
Return true if MOP1 and MOP2 are register operands are defined by equivalent instructions.
LLVM_ABI void applyUDivOrURemByConst(MachineInstr &MI) const
LLVM_ABI void applyCombineUnmergeWithDeadLanesToTrunc(MachineInstr &MI) const
LLVM_ABI bool matchUnmergeValuesAnyExtBuildVector(const MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchFsubToFneg(MachineInstr &MI) const
LLVM_ABI bool matchCtls(MachineInstr &CtlzMI, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchSelectSameVal(MachineInstr &MI) const
Optimize (cond ? x : x) -> x.
LLVM_ABI bool matchReassocConstantInnerRHS(GPtrAdd &MI, MachineInstr *RHS, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchBitfieldExtractFromShr(MachineInstr &MI, BuildFnTy &MatchInfo) const
Match: shr (shl x, n), k -> sbfx/ubfx x, pos, width.
LLVM_ABI bool matchFoldAMinusC1PlusC2(const MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchTruncSSatU(MachineInstr &MI, Register &MatchInfo) const
LLVM_ABI void applySimplifyURemByPow2(MachineInstr &MI) const
Combine G_UREM x, (known power of 2) to an add and bitmasking.
LLVM_ABI bool matchCombineUnmergeZExtToZExt(MachineInstr &MI) const
Transform X, Y = G_UNMERGE(G_ZEXT(Z)) -> X = G_ZEXT(Z); Y = G_CONSTANT 0.
LLVM_ABI bool matchSimplifyDemandedBits(MachineInstr &MI, BuildFnTy &MatchInfo) const
Match demanded-bits simplification of a root's register use.
const TargetInstrInfo * TII
LLVM_ABI void applyCombineConcatVectors(MachineInstr &MI, SmallVector< Register > &Ops) const
Replace MI with a flattened build_vector with Ops or an implicit_def if Ops is empty.
LLVM_ABI void applyXorOfAndWithSameReg(MachineInstr &MI, std::pair< Register, Register > &MatchInfo) const
LLVM_ABI bool canCombineFMadOrFMA(MachineInstr &MI, bool &AllowFusionGlobally, bool &HasFMAD, bool &Aggressive, bool CanReassociate=false) const
LLVM_ABI bool matchFoldAPlusC1MinusC2(const MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchExtractVecEltBuildVec(MachineInstr &MI, Register &Reg) const
LLVM_ABI void applyCombineUnmergeConstant(MachineInstr &MI, SmallVectorImpl< APInt > &Csts) const
LLVM_ABI bool matchCombineFAddFpExtFMulToFMadOrFMA(MachineInstr &MI, BuildFnTy &MatchInfo) const
Transform (fadd (fpext (fmul x, y)), z) -> (fma (fpext x), (fpext y), z) (fadd (fpext (fmul x,...
LLVM_ABI bool matchCombineIndexedLoadStore(MachineInstr &MI, IndexedLoadStoreMatchInfo &MatchInfo) const
LLVM_ABI void applyCombineShuffleConcat(MachineInstr &MI, SmallVector< Register > &Ops) const
Replace MI with a flattened build_vector with Ops or an implicit_def if Ops is empty.
LLVM_ABI void replaceSingleDefInstWithReg(MachineInstr &MI, Register Replacement) const
Delete MI and replace all of its uses with Replacement.
LLVM_ABI void applyCombineShuffleToBuildVector(MachineInstr &MI) const
Replace shuffle MI with a build_vector.
LLVM_ABI bool matchZextOfTrunc(const MachineOperand &MO, BuildFnTy &MatchInfo) const
Combine zext of trunc.
LLVM_ABI bool matchCombineExtractedVectorLoad(MachineInstr &MI, BuildFnTy &MatchInfo) const
Combine a G_EXTRACT_VECTOR_ELT of a load into a narrowed load.
LLVM_ABI void replaceRegWith(MachineRegisterInfo &MRI, Register FromReg, Register ToReg) const
MachineRegisterInfo::replaceRegWith() and inform the observer of the changes.
LLVM_ABI void replaceRegOpWith(MachineRegisterInfo &MRI, MachineOperand &FromRegOp, Register ToReg) const
Replace a single register operand with a new register and inform the observer of the changes.
LLVM_ABI void applyCombineMemCpyFamily(MachineInstr &MI, MemCpyFamilyLoweringInfo &MatchInfo) const
LLVM_ABI bool matchReassocCommBinOp(MachineInstr &MI, BuildFnTy &MatchInfo) const
Reassociate commutative binary operations like G_ADD.
LLVM_ABI bool matchExtractVectorElementWithBuildVectorTrunc(const MachineOperand &MO, BuildFnTy &MatchInfo) const
Combine extract vector element with a build vector trunc on the vector register.
LLVM_ABI void applyBuildFnMO(const MachineOperand &MO, BuildFnTy &MatchInfo) const
Use a function which takes in a MachineIRBuilder to perform a combine.
LLVM_ABI bool matchCommuteConstantToRHS(MachineInstr &MI) const
Match constant LHS ops that should be commuted.
LLVM_ABI bool matchSimplifyNegMinMax(MachineInstr &MI, BuildFnTy &MatchInfo) const
Tranform (neg (min/max x, (neg x))) into (max/min x, (neg x)).
LLVM_ABI bool matchCombineDivRem(MachineInstr &MI, MachineInstr *&OtherMI) const
Try to combine G_[SU]DIV and G_[SU]REM into a single G_[SU]DIVREM when their source operands are iden...
LLVM_ABI bool matchNonNegZext(const MachineOperand &MO, BuildFnTy &MatchInfo) const
Combine zext nneg to sext.
LLVM_ABI void applyUMulHToLShr(MachineInstr &MI) const
LLVM_ABI void applyNotCmp(MachineInstr &MI, SmallVectorImpl< Register > &RegsToNegate) const
LLVM_ABI bool isLegalOrHasFewerElements(const LegalityQuery &Query) const
LLVM_ABI bool matchShiftImmedChain(MachineInstr &MI, RegisterImmPair &MatchInfo) const
Fold (shift (shift base, x), y) -> (shift base (x+y))
LLVM_ABI bool matchTruncLshrBuildVectorFold(MachineInstr &MI, Register &MatchInfo) const
LLVM_ABI bool matchAllExplicitUsesAreUndef(MachineInstr &MI) const
Return true if all register explicit use operands on MI are defined by a G_IMPLICIT_DEF.
LLVM_ABI bool isPredecessor(const MachineInstr &DefMI, const MachineInstr &UseMI) const
Returns true if DefMI precedes UseMI or they are the same instruction.
LLVM_ABI bool matchPtrAddImmedChain(MachineInstr &MI, PtrAddChain &MatchInfo) const
LLVM_ABI bool matchTruncSSatS(MachineInstr &MI, Register &MatchInfo) const
LLVM_ABI const TargetLowering & getTargetLowering() const
LLVM_ABI bool matchExtractVectorElementWithDifferentIndices(const MachineOperand &MO, BuildFnTy &MatchInfo) const
Combine extract vector element with a insert vector element on the vector register and different indi...
LLVM_ABI bool matchShuffleUndefRHS(MachineInstr &MI, BuildFnTy &MatchInfo) const
Remove references to rhs if it is undef.
LLVM_ABI void applyBuildInstructionSteps(MachineInstr &MI, InstructionStepsMatchInfo &MatchInfo) const
Replace MI with a series of instructions described in MatchInfo.
LLVM_ABI void applySDivByPow2(MachineInstr &MI) const
LLVM_ABI bool matchConstantFoldFPBinOp(MachineInstr &MI, BuildFnTy &MatchInfo) const
Do constant FP folding when opportunities are exposed after MIR building.
LLVM_ABI void applyUDivByPow2(MachineInstr &MI) const
Given an G_UDIV MI expressing an unsigned divided by a pow2 constant, return expressions that impleme...
LLVM_ABI bool matchOr(MachineInstr &MI, BuildFnTy &MatchInfo) const
Combine ors.
LLVM_ABI bool matchLshrOfTruncOfLshr(MachineInstr &MI, LshrOfTruncOfLshr &MatchInfo, MachineInstr &ShiftMI) const
Fold (lshr (trunc (lshr x, C1)), C2) -> trunc (shift x, (C1 + C2))
LLVM_ABI void replaceInstWithConstant(MachineInstr &MI, int64_t C) const
Replace an instruction with a G_CONSTANT with value C.
LLVM_ABI bool matchCombineFSubFpExtFMulToFMadOrFMA(MachineInstr &MI, BuildFnTy &MatchInfo) const
Transform (fsub (fpext (fmul x, y)), z) -> (fma (fpext x), (fpext y), (fneg z)) (fsub (fpext (fmul x,...
LLVM_ABI bool matchConstantLargerBitWidth(MachineInstr &MI, unsigned ConstIdx) const
Checks if constant at ConstIdx is larger than MI 's bitwidth.
GISelValueTracking * getValueTracking() const
LLVM_ABI void applyCombineCopy(MachineInstr &MI) const
LLVM_ABI bool matchSextOfTrunc(const MachineOperand &MO, BuildFnTy &MatchInfo) const
Combine sext of trunc.
LLVM_ABI bool matchCombineShlOfExtend(MachineInstr &MI, RegisterImmPair &MatchData) const
LLVM_ABI bool matchCombineFSubFMulToFMadOrFMA(MachineInstr &MI, BuildFnTy &MatchInfo) const
Transform (fsub (fmul x, y), z) -> (fma x, y, -z) (fsub (fmul x, y), z) -> (fmad x,...
LLVM_ABI bool matchCombineFAddFMAFMulToFMadOrFMA(MachineInstr &MI, BuildFnTy &MatchInfo) const
Transform (fadd (fma x, y, (fmul u, v)), z) -> (fma x, y, (fma u, v, z)) (fadd (fmad x,...
LLVM_ABI bool matchSextTruncSextLoad(MachineInstr &MI) const
LLVM_ABI bool matchMulOfVScale(const MachineOperand &MO, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchCombineInsertVecElts(MachineInstr &MI, SmallVectorImpl< Register > &MatchInfo) const
LLVM_ABI bool matchCombineBuildUnmerge(MachineInstr &MI, MachineRegisterInfo &MRI, Register &UnmergeSrc) const
LLVM_ABI bool matchDivByPow2(MachineInstr &MI, bool IsSigned) const
Given an G_SDIV MI expressing a signed divided by a pow2 constant, return expressions that implements...
LLVM_ABI bool matchAddOfVScale(const MachineOperand &MO, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchNarrowBinopFeedingAnd(MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchShlOfVScale(const MachineOperand &MO, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchCombineLoadWithAndMask(MachineInstr &MI, BuildFnTy &MatchInfo) const
Match (and (load x), mask) -> zextload x.
LLVM_ABI bool matchCombineFAddFMulToFMadOrFMA(MachineInstr &MI, BuildFnTy &MatchInfo) const
Transform (fadd (fmul x, y), z) -> (fma x, y, z) (fadd (fmul x, y), z) -> (fmad x,...
LLVM_ABI bool matchCombineCopy(MachineInstr &MI) const
LLVM_ABI bool matchExtendThroughPhis(MachineInstr &MI, MachineInstr *&ExtMI) const
LLVM_ABI void applyShiftImmedChain(MachineInstr &MI, RegisterImmPair &MatchInfo) const
LLVM_ABI bool matchXorOfAndWithSameReg(MachineInstr &MI, std::pair< Register, Register > &MatchInfo) const
Fold (xor (and x, y), y) -> (and (not x), y) {.
LLVM_ABI bool matchCombineShuffleVector(MachineInstr &MI, SmallVectorImpl< Register > &Ops) const
Check if the G_SHUFFLE_VECTOR MI can be replaced by a concat_vectors.
LLVM_ABI bool matchTruncateOfExt(const MachineInstr &Root, const MachineInstr &ExtMI, BuildFnTy &MatchInfo) const
Transform trunc ([asz]ext x) to x or ([asz]ext x) or (trunc x).
LLVM_ABI void replaceInstWithFConstant(MachineInstr &MI, double C) const
Replace an instruction with a G_FCONSTANT with value C.
LLVM_ABI bool matchOrShiftToFunnelShift(MachineInstr &MI, bool AllowScalarConstants, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchRedundantSExtInReg(MachineInstr &MI) const
LLVM_ABI void replaceOpcodeWith(MachineInstr &FromMI, unsigned ToOpcode) const
Replace the opcode in instruction with a new opcode and inform the observer of the changes.
LLVM_ABI void applyFunnelShiftConstantModulo(MachineInstr &MI) const
Replaces the shift amount in MI with ShiftAmt % BW.
LLVM_ABI bool matchFoldC1Minus2MinusC2(const MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI void applyCombineShlOfExtend(MachineInstr &MI, const RegisterImmPair &MatchData) const
LLVM_ABI void applyUseVectorTruncate(MachineInstr &MI, Register &MatchInfo) const
LLVM_ABI CombinerHelper(GISelChangeObserver &Observer, MachineIRBuilder &B, bool IsPreLegalize, GISelValueTracking *VT=nullptr, MachineDominatorTree *MDT=nullptr, const LegalizerInfo *LI=nullptr)
LLVM_ABI bool matchShuffleDisjointMask(MachineInstr &MI, BuildFnTy &MatchInfo) const
Turn shuffle a, b, mask -> shuffle undef, b, mask iff mask does not reference a.
LLVM_ABI bool matchCombineMulToShl(MachineInstr &MI, unsigned &ShiftVal) const
Transform a multiply by a power-of-2 value to a left shift.
LLVM_ABI void applyCombineShuffleVector(MachineInstr &MI, ArrayRef< Register > Ops) const
Replace MI with a concat_vectors with Ops.
LLVM_ABI bool matchCombineUnmergeUndef(MachineInstr &MI, std::function< void(MachineIRBuilder &)> &MatchInfo) const
Transform G_UNMERGE G_IMPLICIT_DEF -> G_IMPLICIT_DEF, G_IMPLICIT_DEF, ...
LLVM_ABI void applyFoldBinOpIntoSelect(MachineInstr &MI, const unsigned &SelectOpNo) const
SelectOperand is the operand in binary operator MI that is the select to fold.
LLVM_ABI bool matchFoldAMinusC1MinusC2(const MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI void applyCombineIndexedLoadStore(MachineInstr &MI, IndexedLoadStoreMatchInfo &MatchInfo) const
LLVM_ABI bool matchCombineShuffleConcat(MachineInstr &MI, SmallVector< Register > &Ops) const
LLVM_ABI void applySextInRegOfLoad(MachineInstr &MI, std::tuple< Register, unsigned > &MatchInfo) const
LLVM_ABI bool matchTruncUSatU(MachineInstr &MI, MachineInstr &MinMI) const
const RegisterBankInfo & getRBI() const
LLVM_ABI bool matchICmpToLHSKnownBits(MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchExtOfExt(const MachineInstr &FirstMI, const MachineInstr &SecondMI, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchReassocPtrAdd(MachineInstr &MI, BuildFnTy &MatchInfo) const
Reassociate pointer calculations with G_ADD involved, to allow better addressing mode usage.
LLVM_ABI bool matchCanonicalizeFCmp(const MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI bool isPreLegalize() const
LLVM_ABI bool matchUndefShuffleVectorMask(MachineInstr &MI) const
Return true if a G_SHUFFLE_VECTOR instruction MI has an undef mask.
LLVM_ABI bool matchCombineSubToAdd(MachineInstr &MI, BuildFnTy &MatchInfo) const
const TargetRegisterInfo & getTRI() const
LLVM_ABI bool matchShiftOfShiftedLogic(MachineInstr &MI, ShiftOfShiftedLogic &MatchInfo) const
If we have a shift-by-constant of a bitwise logic op that itself has a shift-by-constant operand with...
LLVM_ABI bool matchCombineConcatVectors(MachineInstr &MI, SmallVector< Register > &Ops) const
If MI is G_CONCAT_VECTORS, try to combine it.
LLVM_ABI bool matchInsertExtractVecEltOutOfBounds(MachineInstr &MI) const
Return true if a G_{EXTRACT,INSERT}_VECTOR_ELT has an out of range index.
LLVM_ABI bool matchExtractVectorElementWithShuffleVector(const MachineInstr &MI, const MachineInstr &MI2, BuildFnTy &MatchInfo) const
Combine extract vector element with a shuffle vector on the vector register.
LLVM_ABI bool matchOperandIsKnownToBeAPowerOfTwo(const MachineOperand &MO, bool OrNegative=false, bool OrZero=false) const
Check if operand MO is known to be a power of 2.
LLVM_ABI bool matchExtractAllEltsFromBuildVector(MachineInstr &MI, SmallVectorImpl< std::pair< Register, MachineInstr * > > &MatchInfo) const
LLVM_ABI LLVMContext & getContext() const
LLVM_ABI void applyPtrAddImmedChain(MachineInstr &MI, PtrAddChain &MatchInfo) const
LLVM_ABI bool isConstantLegalOrBeforeLegalizer(const LLT Ty) const
LLVM_ABI bool matchNotCmp(MachineInstr &MI, SmallVectorImpl< Register > &RegsToNegate) const
Combine inverting a result of a compare into the opposite cond code.
LLVM_ABI bool matchSextInRegOfLoad(MachineInstr &MI, std::tuple< Register, unsigned > &MatchInfo) const
Match sext_inreg(load p), imm -> sextload p.
LLVM_ABI bool matchSelectIMinMax(const MachineOperand &MO, BuildFnTy &MatchInfo) const
Combine select to integer min/max.
LLVM_ABI bool simplifyDemandedBits(MachineInstr &MI, unsigned OpNo, const APInt &DemandedBits, KnownBits &Known, unsigned Depth=0) const
Simplify a register use under DemandedBits and compute Known in the same walk.
LLVM_ABI bool matchConstantFoldUnaryIntOp(MachineInstr &MI, BuildFnTy &MatchInfo) const
Constant fold a unary integer op (G_CTLZ, G_CTTZ, G_CTPOP and their _ZERO_POISON variants,...
LLVM_ABI bool isLegal(const LegalityQuery &Query) const
LLVM_ABI bool matchShiftsTooBig(MachineInstr &MI, BuildFnTy &MatchInfo) const
Match shifts greater or equal to the range (the bitwidth of the result datatype, or the effective bit...
LLVM_ABI void applyCombineShuffleOfBuildVector(MachineInstr &MI) const
Replace shuffle of build_vector with a build_vector.
LLVM_ABI bool matchICmpToTrueFalseKnownBits(MachineInstr &MI, int64_t &MatchInfo) const
LLVM_ABI bool tryReassocBinOp(unsigned Opc, Register DstReg, Register Op0, Register Op1, BuildFnTy &MatchInfo) const
Try to reassociate to reassociate operands of a commutative binop.
LLVM_ABI void eraseInst(MachineInstr &MI) const
Erase MI.
LLVM_ABI void applyBuildFnNoErase(MachineInstr &MI, BuildFnTy &MatchInfo) const
Use a function which takes in a MachineIRBuilder to perform a combine.
LLVM_ABI bool matchUseVectorTruncate(MachineInstr &MI, Register &MatchInfo) const
LLVM_ABI bool matchConstantFoldBinOp(MachineInstr &MI, BuildFnTy &MatchInfo) const
Do constant folding when opportunities are exposed after MIR building.
MachineRegisterInfo & MRI
LLVM_ABI void applyExtendThroughPhis(MachineInstr &MI, MachineInstr *&ExtMI) const
LLVM_ABI bool matchConstantFPOp(const MachineOperand &MOP, double C) const
Return true if MOP is defined by a G_FCONSTANT or splat with a value exactly equal to C.
LLVM_ABI MachineInstr * buildUDivOrURemUsingMul(MachineInstr &MI) const
Given an G_UDIV MI or G_UREM MI expressing a divide by constant, return an expression that implements...
LLVM_ABI void applyExtractVecEltBuildVec(MachineInstr &MI, Register &Reg) const
LLVM_ABI bool matchFoldBinOpIntoSelect(MachineInstr &MI, unsigned &SelectOpNo) const
Push a binary operator through a select on constants.
LLVM_ABI bool tryCombineShiftToUnmerge(MachineInstr &MI, unsigned TargetShiftAmount) const
LLVM_ABI bool isConstantNaN(Register Reg) const
LLVM_ABI bool matchPtrAddZeroVector(MachineInstr &MI) const
}
LLVM_ABI bool tryCombineExtendingLoads(MachineInstr &MI) const
If MI is extend that consumes the result of a load, try to combine it.
LLVM_ABI bool isLegalOrBeforeLegalizer(const LegalityQuery &Query) const
LLVM_ABI bool matchBuildVectorIdentityFold(MachineInstr &MI, Register &MatchInfo) const
LLVM_ABI bool matchBitfieldExtractFromShrAnd(MachineInstr &MI, BuildFnTy &MatchInfo) const
Match: shr (and x, n), k -> ubfx x, pos, width.
LLVM_ABI void applyTruncSSatS(MachineInstr &MI, Register &MatchInfo) const
LLVM_ABI void applyRotateOutOfRange(MachineInstr &MI) const
LLVM_ABI bool matchReassocFoldConstantsInSubTree(GPtrAdd &MI, MachineInstr *LHS, MachineInstr *RHS, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchHoistLogicOpWithSameOpcodeHands(MachineInstr &MI, InstructionStepsMatchInfo &MatchInfo) const
Match (logic_op (op x...), (op y...)) -> (op (logic_op x, y))
LLVM_ABI bool matchBitfieldExtractFromAnd(MachineInstr &MI, BuildFnTy &MatchInfo) const
Match: and (lshr x, cst), mask -> ubfx x, cst, width.
LLVM_ABI bool matchBitfieldExtractFromSExtInReg(MachineInstr &MI, BuildFnTy &MatchInfo) const
Form a G_SBFX from a G_SEXT_INREG fed by a right shift.
LLVM_ABI bool matchNarrowBinop(const MachineInstr &TruncMI, const MachineInstr &BinopMI, BuildFnTy &MatchInfo) const
trunc (binop X, C) --> binop (trunc X, trunc C).
LLVM_ABI bool matchAndOrDisjointMask(MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI void replaceInstWithUndef(MachineInstr &MI) const
Replace an instruction with a G_IMPLICIT_DEF.
LLVM_ABI bool isDesirableToCommuteWithShift(const MachineInstr &MI) const
LLVM_ABI bool matchRedundantBinOpInEquality(MachineInstr &MI, BuildFnTy &MatchInfo) const
Transform: (X + Y) == X -> Y == 0 (X - Y) == X -> Y == 0 (X ^ Y) == X -> Y == 0 (X + Y) !...
LLVM_ABI bool matchConstantFoldFPUnary(MachineInstr &MI, BuildFnTy &MatchInfo) const
Constant fold a unary FP operation when the source is constant.
LLVM_ABI bool matchOptBrCondByInvertingCond(MachineInstr &MI, MachineInstr *&BrCond) const
If a brcond's true block is not the fallthrough, make it so by inverting the condition and swapping o...
LLVM_ABI bool matchAddOverflow(MachineInstr &MI, BuildFnTy &MatchInfo) const
Combine addos.
LLVM_ABI void applyAshShlToSextInreg(MachineInstr &MI, std::tuple< Register, int64_t > &MatchInfo) const
LLVM_ABI bool matchSelect(MachineInstr &MI, BuildFnTy &MatchInfo) const
Combine selects.
LLVM_ABI bool matchCombineExtendingLoads(MachineInstr &MI, PreferredTuple &MatchInfo) const
LLVM_ABI bool matchConstantFoldCastOp(MachineInstr &MI, BuildFnTy &MatchInfo) const
Do constant folding when opportunities are exposed after MIR building.
LLVM_ABI bool matchCombineUnmergeWithDeadLanesToTrunc(MachineInstr &MI) const
Transform X, Y<dead> = G_UNMERGE Z -> X = G_TRUNC Z.
LLVM_ABI bool matchRotateOutOfRange(MachineInstr &MI) const
LLVM_ABI void applyExpandFPowI(MachineInstr &MI, int64_t Exponent) const
Expands FPOWI into a series of multiplications and a division if the exponent is negative.
LLVM_ABI void setRegBank(Register Reg, const RegisterBank *RegBank) const
Set the register bank of Reg.
LLVM_ABI bool matchCommuteFPConstantToRHS(MachineInstr &MI) const
Match constant LHS FP ops that should be commuted.
LLVM_ABI void applyCombineDivRem(MachineInstr &MI, MachineInstr *&OtherMI) const
const TargetInstrInfo & getTII() const
LLVM_ABI bool matchRedundantOr(MachineInstr &MI, Register &Replacement) const
LLVM_ABI void applyTruncSSatU(MachineInstr &MI, Register &MatchInfo) const
LLVM_ABI void applySimplifySRemByPow2(MachineInstr &MI) const
Combine G_SREM x, (+/-2^k) to a bias-and-mask sequence.
LLVM_ABI bool matchCombineFSubFpExtFNegFMulToFMadOrFMA(MachineInstr &MI, BuildFnTy &MatchInfo) const
Transform (fsub (fpext (fneg (fmul x, y))), z) -> (fneg (fma (fpext x), (fpext y),...
LLVM_ABI bool matchTruncBuildVectorFold(MachineInstr &MI, Register &MatchInfo) const
LLVM_ABI bool matchInsertVectorElementOOB(MachineInstr &MI) const
Combine insert vector element OOB.
LLVM_ABI bool matchSubOfVScale(const MachineOperand &MO, BuildFnTy &MatchInfo) const
LLVM_ABI void applyCombineTruncOfShift(MachineInstr &MI, std::pair< MachineInstr *, LLT > &MatchInfo) const
LLVM_ABI bool matchConstantOp(const MachineOperand &MOP, int64_t C) const
Return true if MOP is defined by a G_CONSTANT or splat with a value equal to C.
const LegalizerInfo * LI
LLVM_ABI void applyCombineMulToShl(MachineInstr &MI, unsigned &ShiftVal) const
LLVM_ABI void applyCombineBuildUnmerge(MachineInstr &MI, MachineRegisterInfo &MRI, MachineIRBuilder &B, Register &UnmergeSrc) const
LLVM_ABI bool matchUMulHToLShr(MachineInstr &MI) const
MachineDominatorTree * MDT
MachineIRBuilder & getBuilder() const
LLVM_ABI bool matchSimplifySelectToMinMax(MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI void applyRepeatedFPDivisor(SmallVector< MachineInstr * > &MatchInfo) const
LLVM_ABI bool matchTruncUSatUToFPTOUISat(MachineInstr &MI, MachineInstr &SrcMI) const
const RegisterBankInfo * RBI
LLVM_ABI bool matchMulOBy0(MachineInstr &MI, BuildFnTy &MatchInfo) const
Match: (G_*MULO x, 0) -> 0 + no carry out.
GISelValueTracking * VT
LLVM_ABI bool matchBinopWithNeg(MachineInstr &MI, BuildFnTy &MatchInfo) const
Fold a bitwiseop (~b +/- c) -> a bitwiseop ~(b -/+ c)
LLVM_ABI bool matchCombineUnmergeConstant(MachineInstr &MI, SmallVectorImpl< APInt > &Csts) const
Transform G_UNMERGE Constant -> Constant1, Constant2, ...
LLVM_ABI bool matchCountZeroToZeroPoison(MachineInstr &MI, unsigned Opc, unsigned ZeroPoisonOpc) const
LLVM_ABI void applyShiftOfShiftedLogic(MachineInstr &MI, ShiftOfShiftedLogic &MatchInfo) const
const TargetRegisterInfo * TRI
LLVM_ABI bool matchRedundantAnd(MachineInstr &MI, Register &Replacement) const
LLVM_ABI bool dominates(const MachineInstr &DefMI, const MachineInstr &UseMI) const
Returns true if DefMI dominates UseMI.
GISelChangeObserver & Observer
LLVM_ABI void applyBuildFn(MachineInstr &MI, BuildFnTy &MatchInfo) const
Use a function which takes in a MachineIRBuilder to perform a combine.
LLVM_ABI bool matchCombineTruncOfShift(MachineInstr &MI, std::pair< MachineInstr *, LLT > &MatchInfo) const
Transform trunc (shl x, K) to shl (trunc x), K if K < VT.getScalarSizeInBits().
LLVM_ABI bool matchCombineShiftToUnmerge(MachineInstr &MI, unsigned TargetShiftSize, unsigned &ShiftVal) const
Reduce a shift by a constant to an unmerge and a shift on a half sized type.
LLVM_ABI bool matchUDivOrURemByConst(MachineInstr &MI) const
Combine G_UDIV or G_UREM by constant into a multiply by magic constant.
LLVM_ABI bool matchAnd(MachineInstr &MI, BuildFnTy &MatchInfo) const
Combine ands.
LLVM_ABI bool matchSuboCarryOut(const MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchRedundantSextInReg(MachineInstr &Root, MachineInstr &Other, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchCastOfInteger(const MachineInstr &CastMI, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchCombineFSubFNegFMulToFMadOrFMA(MachineInstr &MI, BuildFnTy &MatchInfo) const
Transform (fsub (fneg (fmul, x, y)), z) -> (fma (fneg x), y, (fneg z)) (fsub (fneg (fmul,...
LLVM_ABI bool matchCombineZextTrunc(MachineInstr &MI, Register &Reg) const
Transform zext(trunc(x)) to x.
LLVM_ABI bool matchUDivByShiftedPow2(MachineInstr &MI, BuildFnTy &MatchInfo) const
Combine unsigned division by a shifted power of two into a right shift.
LLVM_ABI bool matchSameRegOrICstOrSplat(Register A, Register B) const
True when A and B are the same register, including through copies, or different registers holding the...
LLVM_ABI void applyLshrOfTruncOfLshr(MachineInstr &MI, LshrOfTruncOfLshr &MatchInfo) const
LLVM_ABI bool tryCombineMemCpyFamily(MachineInstr &MI, unsigned MaxLen=0) const
Optimize memcpy intrinsics et al, e.g.
LLVM_ABI bool matchFreezeOfSingleMaybePoisonOperand(MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI void applySDivOrSRemByConst(MachineInstr &MI) const
LLVM_ABI bool matchCombineMemCpyFamily(MachineInstr &MI, MemCpyFamilyLoweringInfo &MatchInfo, unsigned MaxLen=0) const
LLVM_ABI MachineInstr * buildSDivOrSRemUsingMul(MachineInstr &MI) const
Given an G_SDIV MI or G_SREM MI expressing a signed divide by constant, return an expression that imp...
LLVM_ABI bool isLegalOrHasWidenScalar(const LegalityQuery &Query) const
LLVM_ABI bool matchCanonicalizeICmp(const MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchCastOfBuildVector(const MachineInstr &CastMI, const MachineInstr &BVMI, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchSignedDivRemToUnsigned(MachineInstr &MI, unsigned UnsignedOpcode) const
Convert signed division or remainder of nonnegative operands to unsigned.
LLVM_ABI bool matchReassocConstantInnerLHS(GPtrAdd &MI, MachineInstr *LHS, MachineInstr *RHS, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchOverlappingAnd(MachineInstr &MI, BuildFnTy &MatchInfo) const
Fold and(and(x, C1), C2) -> C1&C2 ? and(x, C1&C2) : 0.
LLVM_ABI bool matchCombineAnyExtTrunc(MachineInstr &MI, Register &Reg) const
Transform anyext(trunc(x)) to x.
LLVM_ABI void applyExtractAllEltsFromBuildVector(MachineInstr &MI, SmallVectorImpl< std::pair< Register, MachineInstr * > > &MatchInfo) const
MachineIRBuilder & Builder
LLVM_ABI bool matchExtractVectorElement(MachineInstr &MI) const
Combine extract vector element.
LLVM_ABI void replaceSingleDefInstWithOperand(MachineInstr &MI, unsigned OpIdx) const
Delete MI and replace all of its uses with its OpIdx-th operand.
LLVM_ABI const MachineFunction & getMachineFunction() const
LLVM_ABI bool matchCombineBuildVectorOfBitcast(MachineInstr &MI, SmallVector< Register > &Ops) const
Combine G_BUILD_VECTOR(G_UNMERGE(G_BITCAST), Undef) to G_BITCAST(G_BUILD_VECTOR(.....
LLVM_ABI bool matchCombineFAddFpExtFMulToFMadOrFMAAggressive(MachineInstr &MI, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchExtractVectorElementWithBuildVector(const MachineInstr &MI, const MachineInstr &MI2, BuildFnTy &MatchInfo) const
Combine extract vector element with a build vector on the vector register.
LLVM_ABI bool matchConstantFoldFMA(MachineInstr &MI, BuildFnTy &MatchInfo) const
Constant fold G_FMA/G_FMAD.
LLVM_ABI bool matchSDivOrSRemByConst(MachineInstr &MI) const
Combine G_SDIV or G_SREM by constant into a multiply by magic constant.
LLVM_ABI void applyOptBrCondByInvertingCond(MachineInstr &MI, MachineInstr *&BrCond) const
LLVM_ABI void applyCombineShiftToUnmerge(MachineInstr &MI, const unsigned &ShiftVal) const
LLVM_ABI bool matchCastOfSelect(const MachineInstr &Cast, const MachineInstr &SelectMI, BuildFnTy &MatchInfo) const
LLVM_ABI bool matchFPowIExpansion(MachineInstr &MI, int64_t Exponent) const
Match FPOWI if it's safe to extend it into a series of multiplications.
LLVM_ABI void applyCombineInsertVecElts(MachineInstr &MI, SmallVectorImpl< Register > &MatchInfo) const
LLVM_ABI bool matchCombineUnmergeMergeToPlainValues(MachineInstr &MI, SmallVectorImpl< Register > &Operands) const
Transform <ty,...> G_UNMERGE(G_MERGE ty X, Y, Z) -> ty X, Y, Z.
LLVM_ABI void applyCombineUnmergeMergeToPlainValues(MachineInstr &MI, SmallVectorImpl< Register > &Operands) const
LLVM_ABI bool matchAshrShlToSextInreg(MachineInstr &MI, std::tuple< Register, int64_t > &MatchInfo) const
Match ashr (shl x, C), C -> sext_inreg (C)
LLVM_ABI void applyCombineUnmergeZExtToZExt(MachineInstr &MI) const
ConstantFP - Floating Point Values [float, double].
Definition Constants.h:420
Abstract class that contains various methods for clients to notify about changes.
Represents any type of generic load or store.
Represents a G_PTR_ADD.
Represents a G_ZEXTLOAD.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
Helper class to build MachineInstr.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Holds all the information related to register banks.
This class implements the register bank concept.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetInstrInfo - Interface to description of machine instruction set.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
@ Known
Known to have no common set bits.
std::function< void(MachineIRBuilder &)> BuildFnTy
SmallVector< std::function< void(MachineInstrBuilder &)>, 4 > OperandBuildSteps
std::tuple< Register, Register, uint64_t, Align, bool, std::vector< LLT > > MemCpyFamilyLoweringInfo
Definition Utils.h:212
@ Other
Any other memory.
Definition ModRef.h:68
InstructionBuildSteps(unsigned Opcode, const OperandBuildSteps &OperandFns)
InstructionBuildSteps()=default
Operands to be added to the instruction.
OperandBuildSteps OperandFns
The opcode for the produced instruction.
InstructionStepsMatchInfo(std::initializer_list< InstructionBuildSteps > InstrsToBuild)
SmallVector< InstructionBuildSteps, 2 > InstrsToBuild
Describes instructions to be built during a combine.
The LegalityQuery object bundles together all the information that's needed to decide whether a given...
const RegisterBank * Bank