aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-04[GlobalISel] Add constant matcher for APInt (#151357)jyli01161-0/+40
Changed m_SpecificICst, m_SpecificICstSplat and m_SpecificICstorSplat to match against APInt as well.
2025-03-10[GlobalISel] Add and use a m_GAddLike pattern matcher. NFC (#125435)David Green1-0/+23
This adds a Flags parameter to the BinaryOp_match, allowing it to detect different flags like Disjoint. A m_GDisjointOr is added to detect Or's with disjoint flags, and G_AddLike is then either a m_GADD or m_GDisjointOr. The rest is trying to allow matching `const MachineInstr&`, as opposed to non-const references.
2024-12-30[MIPatternMatch] Add m_DeferredReg/Type (#121218)Min-Yih Hsu1-0/+30
This pattern does the same thing as m_SpecificReg/Type except the value it matches against origniated from an earlier pattern in the same mi_match expression. This patch also changes how commutative patterns are handled: in order to support m_DefferedReg/Type, we always have to run the LHS-pattern before the RHS one.
2024-12-26[MIPatternMatch] Add m_GUMin and m_GUMax (#121068)Min-Yih Hsu1-0/+26
And make all unsigned and signed versions of min/max matchers commutative, since we already made a precedent of m_GAdd that is commutative by default.
2024-12-26[MIPatternMatch] Fix incorrect argument type of m_Type (#121074)Min-Yih Hsu1-0/+5
m_Type is supposed to extract the underlying value type (equality type comparison is covered by m_SpecificType), therefore it should take a LLT reference as its argument rather than passing by value. This was originated from de256478e61d6488db751689af82d280ba114a6f, which refactored out a good chunk of LLT reference usages. And it's just so happen that (for some reasons) no one is using m_Type and no test was covering it.
2024-03-07[GISEL] Add IRTranslation for shufflevector on scalable vector types (#80378)Michael Maitland1-3/+3
Recommits llvm/llvm-project#80378 which was reverted in llvm/llvm-project#84330. The problem was that the change in llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir used 217 as an opcode instead of a regex.
2024-03-07Revert "[GISEL] Add IRTranslation for shufflevector on scalable vector ↵Michael Maitland1-3/+3
types" (#84330) Reverts llvm/llvm-project#80378 causing Buildbot failures that did not show up with check-llvm or CI.
2024-03-07[GISEL] Add IRTranslation for shufflevector on scalable vector types (#80378)Michael Maitland1-3/+3
This patch is stacked on https://github.com/llvm/llvm-project/pull/80372, https://github.com/llvm/llvm-project/pull/80307, and https://github.com/llvm/llvm-project/pull/80306. ShuffleVector on scalable vector types gets IRTranslate'd to G_SPLAT_VECTOR since a ShuffleVector that has operates on scalable vectors is a splat vector where the value of the splat vector is the 0th element of the first operand, because the index mask operand is the zeroinitializer (undef and poison are treated as zeroinitializer here). This is analogous to what happens in SelectionDAG for ShuffleVector. `buildSplatVector` is renamed to`buildBuildVectorSplatVector`. I did not make this a separate patch because it would cause problems to revert that change without reverting this change too.
2023-01-25[unittests] Use GTEST_SKIP() instead of return when appropriatePaul Robinson1-24/+24
Basically NFC: A TEST/TEST_F/etc that bails out early (usually because setup failed or some other runtime condition wasn't met) generally should use GTEST_SKIP() to report its status correctly, unless it takes steps to report another status (e.g., FAIL()). I did see a handful of tests show up as SKIPPED after this change, which is not unexpected. The status seemed appropriate in all the new cases.
2023-01-18[GlobalISel] Detect splats built with G_CONCAT_VECTORSDiana Picus1-0/+45
Add support to the MI matching of vector splats for patterns that consist of `G_CONCAT_VECTORS` of smaller splats with the same constant value. With this, we would consider the following pseudo-MIR to be a splat: ``` %0 = G_[F]CONSTANT [...] %1 = G_BUILD_VECTOR %0, %0, ..., %0 %2 = G_CONCAT_VECTORS %1, %1, ..., %1 ``` Since it uses recursion for matching splats, it could match pretty complicated patterns with all sorts of combinations of `G_BUILD_VECTOR` and `G_CONCAT_VECTORS` (e.g. a `G_CONCAT_VECTORS` with a `G_BUILD_VECTOR_TRUNC` and another `G_CONCAT_VECTORS` as operands), and it should also look through copies etc. This should make it easier to match complex immediates for certain instructions on AMDGPU, where for instance a <8 x s16> will be split before instruction selection into a `G_CONCAT_VECTORS` of <2 x s16> splats. Differential Revision: https://reviews.llvm.org/D141902
2022-12-13[CodeGen] llvm::Optional => std::optionalFangrui Song1-4/+4
2022-10-07[GlobalISel] Add commutative matchers for compares.Jessica Paquette1-0/+58
This adds: * `m_c_GICmp` * `m_c_GFCmp` These work the same way as the standard matchers, but will also try to commute the LHS and RHS of a compare to get a match. E.g. ``` m_c_GICmp(m_Pred(...), m_GAdd(...), m_GSub(...)) ``` Can match either of ``` icmp cc (add x, y), (sub a, b) icmp swapped_cc (sub a, b), (add x, y) ``` Differential Revision: https://reviews.llvm.org/D135415
2022-10-06[GlobalISel] Add a m_SpecificReg matcherJessica Paquette1-0/+17
Similar to the specific matchers for constants. The intention here is to make it easier to write combines which check if a specific register is used more than once. e.g. matching patterns like: ``` (X + Y) == Y ``` Differential Revision: https://reviews.llvm.org/D135378
2022-05-16[GlobalISel] Handle constant splat in funnel shift combineAbinav Puthan Purayil1-0/+19
This change adds the constant splat versions of m_ICst() (by using getBuildVectorConstantSplat()) and uses it in matchOrShiftToFunnelShift(). The getBuildVectorConstantSplat() name is shortened to getIConstantSplatVal() so that the *SExtVal() version would have a more compact name. Differential Revision: https://reviews.llvm.org/D125516
2021-11-30[GlobalISel] Add matchers for constant splat.Abinav Puthan Purayil1-0/+61
This change exposes isBuildVectorConstantSplat() to the llvm namespace and uses it to implement the constant splat versions of m_SpecificICst(). CombinerHelper::matchOrShiftToFunnelShift() can now work with vector types and CombinerHelper::matchMulOBy2()'s match for a constant splat is simplified. Differential Revision: https://reviews.llvm.org/D114625
2021-10-08Move TargetRegistry.(h|cpp) from Support to MCReid Kleckner1-1/+1
This moves the registry higher in the LLVM library dependency stack. Every client of the target registry needs to link against MC anyway to actually use the target, so we might as well move this out of Support. This allows us to ensure that Support doesn't have includes from MC/*. Differential Revision: https://reviews.llvm.org/D111454
2021-10-07[MachineInstr] Move MIParser's DBG_VALUE RegState::Debug invariant into ↵Jack Andersen1-2/+2
MachineInstr::addOperand Based on the reasoning of D53903, register operands of DBG_VALUE are invariably treated as RegState::Debug operands. This change enforces this invariant as part of MachineInstr::addOperand so that all passes emit this flag consistently. RegState::Debug is inconsistently set on DBG_VALUE registers throughout LLVM. This runs the risk of a filtering iterator like MachineRegisterInfo::reg_nodbg_iterator to process these operands erroneously when not parsed from MIR sources. This issue was observed in the development of the llvm-mos fork which adds a backend that relies on physical register operands much more than existing targets. Physical RegUnit 0 has the same numeric encoding as $noreg (indicating an undef for DBG_VALUE). Allowing debug operands into the machine scheduler correlates $noreg with RegUnit 0 (i.e. a collision of register numbers with different zero semantics). Eventually, this causes an assert where DBG_VALUE instructions are prohibited from participating in live register ranges. Reviewed By: MatzeB, StephenTozer Differential Revision: https://reviews.llvm.org/D110105
2021-09-21GlobalISel/Utils: Refactor constant splat match functionsPetar Avramovic1-0/+51
Add generic helper function that matches constant splat. It has option to match constant splat with undef (some elements can be undef but not all). Add util function and matcher for G_FCONSTANT splat. Differential Revision: https://reviews.llvm.org/D104410
2021-09-17GlobalISel/Utils: Refactor integer/float constant match functionsPetar Avramovic1-3/+22
Rework getConstantstVRegValWithLookThrough in order to make it clear if we are matching integer/float constant only or any constant(default). Add helper functions that get DefVReg and APInt/APFloat from constant instr getIConstantVRegValWithLookThrough: integer constant, only G_CONSTANT getFConstantVRegValWithLookThrough: float constant, only G_FCONSTANT getAnyConstantVRegValWithLookThrough: either G_CONSTANT or G_FCONSTANT Rename getConstantVRegVal and getConstantVRegSExtVal to getIConstantVRegVal and getIConstantVRegSExtVal. These now only match G_CONSTANT as described in comment. Relevant matchers now return both DefVReg and APInt/APFloat. Replace existing uses of getConstantstVRegValWithLookThrough and getConstantVRegVal with new helper functions. Any constant match is only required in: ConstantFoldBinOp: for constant argument that was bit-cast of float to int getAArch64VectorSplat: AArch64::G_DUP operands can be any constant amdgpu select for G_BUILD_VECTOR_TRUNC: operands can be any constant In other places use integer only constant match. Differential Revision: https://reviews.llvm.org/D104409
2021-06-24[GlobalISel] NFC: Change LLT::vector to take ElementCount.Sander de Smalen1-1/+1
This also adds new interfaces for the fixed- and scalable case: * LLT::fixed_vector * LLT::scalable_vector The strategy for migrating to the new interfaces was as follows: * If the new LLT is a (modified) clone of another LLT, taking the same number of elements, then use LLT::vector(OtherTy.getElementCount()) or if the number of elements is halfed/doubled, it uses .divideCoefficientBy(2) or operator*. That is because there is no reason to specifically restrict the types to 'fixed_vector'. * If the algorithm works on the number of elements (as unsigned), then just use fixed_vector. This will need to be fixed up in the future when modifying the algorithm to also work for scalable vectors, and will need then need additional tests to confirm the behaviour works the same for scalable vectors. * If the test used the '/*Scalable=*/true` flag of LLT::vector, then this is replaced by LLT::scalable_vector. Reviewed By: aemerson Differential Revision: https://reviews.llvm.org/D104451
2021-04-27[MIPatternMatch]: Add matchers for binary instructionsPetar Avramovic1-0/+58
Add matchers that support commutative and non-commutative binary opcodes. Differential Revision: https://reviews.llvm.org/D99736
2021-04-27[MIPatternMatch]: Add mi_match for MachineInstrPetar Avramovic1-0/+31
This utility allows more efficient start of pattern match. Often MachineInstr(MI) is available and instead of using mi_match(MI.getOperand(0).getReg(), MRI, ...) followed by MRI.getVRegDef(Reg) that gives back MI we now use mi_match(MI, MRI, ...). Differential Revision: https://reviews.llvm.org/D99735
2021-04-27[MIPatternMatch]: Add ICstRegMatchPetar Avramovic1-0/+11
Matches G_CONSTANT and returns its def register. Differential Revision: https://reviews.llvm.org/D99734
2021-04-23[GlobalISel] Remove ConstantFoldingMIRBuilderJay Foad1-1/+0
ConstantFoldingMIRBuilder was an experiment which is not used for anything. The constant folding functionality is now part of CSEMIRBuilder. Differential Revision: https://reviews.llvm.org/D101050
2021-04-01Revert "[globalisel][unittests] Rename setUp() to avoid potential mix up ↵Daniel Sanders1-14/+14
with SetUp() from gtest" Forgot to apply commit message changes from phabricator This reverts commit 3a016e31ecef7eeb876b540c928a25a7c5d2e07a.
2021-04-01[globalisel][unittests] Rename setUp() to avoid potential mix up with ↵Daniel Sanders1-14/+14
SetUp() from gtest Also, make it structurally required so it can't be forgotten and re-introduce the bug that led to the rotten green tests. Differential Revision: https://reviews.llvm.org/D99692
2021-01-15[MIPatternMatch] Add m_OneNonDBGUseJessica Paquette1-5/+16
Add a matcher that checks if the given subpattern has only one non-debug use. Also improve existing m_OneUse testcase. Differential Revision: https://reviews.llvm.org/D94705
2021-01-12[MIPatternMatch] Add matcher for G_PTR_ADDJessica Paquette1-0/+8
Add a matcher which recognizes G_PTR_ADD and add a test. Differential Revision: https://reviews.llvm.org/D94348
2020-11-13[GlobalISel] Add convenience matchers for nots and all-ones constantsJessica Paquette1-0/+44
Add a convenience matcher which handles ``` G_XOR %not_reg, -1 ``` And a convenience matcher which returns true if an integer constant is all-ones. Differential Revision: https://reviews.llvm.org/D91459
2020-11-13[GlobalISel] Add matchers for specific constants and a matcher for negationsJessica Paquette1-0/+65
It's fairly common to need matchers for a specific constant value, or for common idioms like finding a negated register. Add - `m_SpecificICst`, which returns true when matching a specific value.. - `m_ZeroInt`, which returns true when an integer 0 is matched. - `m_Neg`, which returns when a register is negated. Also update a few places which use idioms related to the new matchers. Differential Revision: https://reviews.llvm.org/D91397
2020-03-29GlobalISel: Add matcher for G_SHLMatt Arsenault1-0/+8
2020-03-23GlobalISel: Prepare to allow other target unit testsMatt Arsenault1-9/+9
Currently all GlobalISel unittests use a hardcoded AArch64 target machine. Factor this so I can write some for AMDGPU specific known bits unittests.
2020-02-17GlobalISel: Add matcher for G_LSHRMatt Arsenault1-0/+10
2020-01-23GlobalISel: Add MIPatternMatch for G_ICMP/G_FCMPMatt Arsenault1-0/+50
2020-01-23[CodeGen] Make use of MachineInstrBuilder::getRegJay Foad1-40/+40
Reviewers: arsenm Subscribers: wdng, hiraditya, Petar.Avramovic, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73262
2019-10-09[GISel] Refactor and split PatternMatchTest. NFCMarcello Maggioni1-256/+55
Split the ConstantFold part into a separate file and make it use the fixture GISelMITest. llvm-svn: 374245
2019-08-15[llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-1/+1
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. llvm-svn: 369013
2019-08-09[globalisel] Add G_SEXT_INREGDaniel Sanders1-0/+16
Summary: Targets often have instructions that can sign-extend certain cases faster than the equivalent shift-left/arithmetic-shift-right. Such cases can be identified by matching a shift-left/shift-right pair but there are some issues with this in the context of combines. For example, suppose you can sign-extend 8-bit up to 32-bit with a target extend instruction. %1:_(s32) = G_SHL %0:_(s32), i32 24 # (I've inlined the G_CONSTANT for brevity) %2:_(s32) = G_ASHR %1:_(s32), i32 24 %3:_(s32) = G_ASHR %2:_(s32), i32 1 would reasonably combine to: %1:_(s32) = G_SHL %0:_(s32), i32 24 %2:_(s32) = G_ASHR %1:_(s32), i32 25 which no longer matches the special case. If your shifts and extend are equal cost, this would break even as a pair of shifts but if your shift is more expensive than the extend then it's cheaper as: %2:_(s32) = G_SEXT_INREG %0:_(s32), i32 8 %3:_(s32) = G_ASHR %2:_(s32), i32 1 It's possible to match the shift-pair in ISel and emit an extend and ashr. However, this is far from the only way to break this shift pair and make it hard to match the extends. Another example is that with the right known-zeros, this: %1:_(s32) = G_SHL %0:_(s32), i32 24 %2:_(s32) = G_ASHR %1:_(s32), i32 24 %3:_(s32) = G_MUL %2:_(s32), i32 2 can become: %1:_(s32) = G_SHL %0:_(s32), i32 24 %2:_(s32) = G_ASHR %1:_(s32), i32 23 All upstream targets have been configured to lower it to the current G_SHL,G_ASHR pair but will likely want to make it legal in some cases to handle their faster cases. To follow-up: Provide a way to legalize based on the constant. At the moment, I'm thinking that the best way to achieve this is to provide the MI in LegalityQuery but that opens the door to breaking core principles of the legalizer (legality is not context sensitive). That said, it's worth noting that looking at other instructions and acting on that information doesn't violate this principle in itself. It's only a violation if, at the end of legalization, a pass that checks legality without being able to see the context would say an instruction might not be legal. That's a fairly subtle distinction so to give a concrete example, saying %2 in: %1 = G_CONSTANT 16 %2 = G_SEXT_INREG %0, %1 is legal is in violation of that principle if the legality of %2 depends on %1 being constant and/or being 16. However, legalizing to either: %2 = G_SEXT_INREG %0, 16 or: %1 = G_CONSTANT 16 %2:_(s32) = G_SHL %0, %1 %3:_(s32) = G_ASHR %2, %1 depending on whether %1 is constant and 16 does not violate that principle since both outputs are genuinely legal. Reviewers: bogner, aditya_nandakumar, volkan, aemerson, paquette, arsenm Subscribers: sdardis, jvesely, wdng, nhaehnle, rovka, kristof.beyls, javed.absar, hiraditya, jrtc27, atanasyan, Petar.Avramovic, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61289 llvm-svn: 368487
2019-06-24GlobalISel: Remove unsigned variant of SrcOpMatt Arsenault1-8/+8
Force using Register. One downside is the generated register enums require explicit conversion. llvm-svn: 364194
2019-06-24CodeGen: Introduce a class for registersMatt Arsenault1-5/+5
Avoids using a plain unsigned for registers throughoug codegen. Doesn't attempt to change every register use, just something a little more than the set needed to build after changing the return type of MachineOperand::getReg(). llvm-svn: 364191
2019-06-14[GISel]: Fix pattern matcher for m_OneUseAditya Nandakumar1-0/+25
https://reviews.llvm.org/D63302 llvm-svn: 363424
2019-02-04GlobalISel: Improve gtest usageMatt Arsenault1-79/+79
Don't unnecessarily use ASSERT_*, and print the MachineFunction on failure. llvm-svn: 353072
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-12-11[GISel]: Refactor MachineIRBuilder to allow passing additional parameters to ↵Aditya Nandakumar1-10/+10
build Instrs https://reviews.llvm.org/D55294 Previously MachineIRBuilder::buildInstr used to accept variadic arguments for sources (which were either unsigned or MachineInstrBuilder). While this worked well in common cases, it doesn't allow us to build instructions that have multiple destinations. Additionally passing in other optional parameters in the end (such as flags) is not possible trivially. Also a trivial call such as B.buildInstr(Opc, Reg1, Reg2, Reg3) can be interpreted differently based on the opcode (2defs + 1 src for unmerge vs 1 def + 2srcs). This patch refactors the buildInstr to buildInstr(Opc, ArrayRef<DstOps>, ArrayRef<SrcOps>) where DstOps and SrcOps are typed unions that know how to add itself to MachineInstrBuilder. After this patch, most invocations would look like B.buildInstr(Opc, {s32, DstReg}, {SrcRegs..., SrcMIBs..}); Now all the other calls (such as buildAdd, buildSub etc) forward to buildInstr. It also makes it possible to build instructions with multiple defs. Additionally in a subsequent patch, we should make it possible to add flags directly while building instructions. Additionally, the main buildInstr method is now virtual and other builders now only have to override buildInstr (for say constant folding/cseing) is straightforward. Also attached here (https://reviews.llvm.org/F7675680) is a clang-tidy patch that should upgrade the API calls if necessary. llvm-svn: 348815
2018-11-05MachineModuleInfo: Store more specific reference to LLVMTargetMachine; NFCMatthias Braun1-10/+11
MachineModuleInfo can only be used in code using lib/CodeGen, hence we can keep a more specific reference to LLVMTargetMachine rather than just TargetMachine around. llvm-svn: 346182
2018-05-31[GISel]: Pattern matchers for GFSUB, GFNEGAditya Nandakumar1-0/+14
https://reviews.llvm.org/D47547 Add matching templates for G_FSUB, and G_FNEG. Reviewed by: aemerson. llvm-svn: 333685
2018-04-09[GISel] Refactor MachineIRBuilder to allow transformations whileAditya Nandakumar1-0/+30
building. https://reviews.llvm.org/D45067 This change attempts to do two things: 1) It separates out the state that is stored in the MachineIRBuilder(InsertionPt, MF, MRI, InsertFunction etc) into a separate object called MachineIRBuilderState. 2) Add the ability to constant fold operations while building instructions (optionally). MachineIRBuilder is now refactored into a MachineIRBuilderBase which contains lots of non foldable build methods and their implementation. Instructions which can be constant folded/transformed are now in a class called FoldableInstructionBuilder which uses CRTP to use the implementation of the derived class for buildBinaryOps. Additionally buildInstr in the derived class can be used to implement other kinds of transformations. Also because of separation of state, given a MachineIRBuilder in an API, if one wishes to use another MachineIRBuilder, a new one can be constructed from the state locally. For eg, void doFoo(MachineIRBuilder &B) { MyCustomBuilder CustomB(B.getState()); // Use CustomB for building. } reviewed by : aemerson llvm-svn: 329596
2018-03-13[GISel]: Fix incorrect type used in Pattern Match for ICstAditya Nandakumar1-5/+5
getConstantVRegVal() returns int64_t but we use uint64_t. llvm-svn: 327461
2018-03-09[GISel]: Add helpers for easy building G_FCONSTANT along with matchersAditya Nandakumar1-0/+36
Added helpers to build G_FCONSTANT, along with matching ConstantFP and unit tests for the same. Sample usage. auto MIB = Builder.buildFConstant(s32, 0.5); // Build IEEESingle For Matching the above const ConstantFP* Tmp; mi_match(DstReg, MRI, m_GFCst(Tmp)); https://reviews.llvm.org/D44128 reviewed by: volkan llvm-svn: 327152
2018-03-05GlobalISel: IRTranslate llvm.fabs.* intrinsicVolkan Keles1-0/+29
Summary: Fabs is a common floating-point operation, especially for some expansions. This patch adds a new generic opcode for llvm.fabs.* intrinsic in order to avoid building/matching this intrinsic. Reviewers: qcolombet, aditya_nandakumar, dsanders, rovka Reviewed By: aditya_nandakumar Subscribers: kristof.beyls, javed.absar, llvm-commits Differential Revision: https://reviews.llvm.org/D43864 llvm-svn: 326749