summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
AgeCommit message (Collapse)Author
2025-07-02[GlobalISel] Allow expansion of urem by constant in prelegalizer (#145914)jyli0116
This patch allows urem by a constant to be expanded more efficiently to avoid the need for expensive udiv instructions. This is part of the resolution to issue #118090
2025-06-27[GlobalISel] Use-Vector-Truncate Opt Needs Elt Type Check (#146003)Daniel Man
In the pre-legalizer combiner, there exists a bug with UseVectorTruncate match-apply optimization. When the destinations' types do not match the vector element type of the G_UNMERGE_VALUES instruction, the resulting collapsed truncate does not preserve original functional behavior. This commit introduces a simple type check to ensure that the destination types match the vector element type.
2025-05-20[GISel] Fix ShuffleVector assert (#139769)Alan Li
Fixes issue: https://github.com/llvm/llvm-project/issues/139752 When G_SHUFFLE_VECTOR has only 1 element then it is possible the vector is decayed into a scalar.
2025-04-26[GlobalISel] Clear nsw flags when converting sub to add. (#137288)David Green
As shown in https://alive2.llvm.org/ce/z/PVwcTL we need to clear the nsw flags too when converting a sub to a add if the constant is INT_MIN. Fixes #137254
2025-04-18[CodeGen] Construct SmallVector with iterator ranges (NFC) (#136258)Kazu Hirata
2025-04-09[GISel][AMDGPU] Expand ShuffleVector (#124527)Alan Li
This patch dismantles G_SHUFFLE_VECTOR before lowering. The original lowering would emit extract vector element ops. We found that by using unmerged values the build vector op combine could find ways to fold. Only enabled on AMDGPU. This resolves #123631
2025-04-07[GlobalISel] Fix dangling reference in ↵Krisztian Rugasi
CombinerHelper::matchCombineExtractedVectorLoad
2025-03-29[GlobalISel][NFC] Rename GISelKnownBits to GISelValueTracking (#133466)Tim Gymnich
- rename `GISelKnownBits` to `GISelValueTracking` to analyze more than just `KnownBits` in the future
2025-03-17[AMDGPU] Add identity_combines to RegBankCombiner (#131305)Pierre van Houtryve
2025-02-10[GlobalISel] Check whether `G_CTLZ` is legal in `matchUMulHToLShr` (#126457)Shilei Tian
We need to check `G_CTLZ` because the combine uses `G_CTLZ` to get log base 2, and it is not always legal for on a target. Fixes SWDEV-512440.
2025-02-02[GlobalISel] Add brackets around || in assert. NFCDavid Green
2025-01-21[GISel] Fold shifts to constant result. (#123510)lialan
This resolves #123212
2025-01-02[GISel] Combine `(neg (min/max x, (neg x)))` into `(max/min x, (neg x))` ↵Min-Yih Hsu
(#120998) This is the GISel version of #120666. Also supports both unsigned and signed version of min & max.
2025-01-01[GlobalIsel] Add combine for select with constants (#121088)Vikash Gupta
The SelectionDAG Isel supports the both version of combines mentioned below : ``` select Cond, Pow2, 0 --> (zext Cond) << log2(Pow2) select Cond, 0, Pow2 --> (zext !Cond) << log2(Pow2) ``` The GlobalIsel for now only supports the first one defined in it's generic combinerHelper.cpp. This patch adds the missing second one.
2024-12-20Make CombinerHelper methods const (#119529)Paul Bowen-Huggett
There are a number of backends (specifically AArch64, AMDGPU, Mips, and RISCV) which contain a “TODO: make CombinerHelper methods const” comment. This PR does just that and makes all of the CombinerHelper methods const, removes the TODO comments and makes the associated instances const. This change makes some sense because the CombinerHelper class simply modifies the state of _other_ objects to which it holds pointers or references. Note that AMDGPU contains an identical comment for an instance of AMDGPUCombinerHelper (a subclass of CombinerHelper). I deliberately haven’t modified the methods of that class in order to limit the scope of the change. I’m happy to do so either now or as a follow-up.
2024-12-13[GISel] Remove unused DataLayout operand from getApproximateEVTForLLT (#119833)Craig Topper
2024-12-13[AArch64][GlobalISel] Guard against no operands in ↵David Green
matchHoistLogicOpWithSameOpcodeHands In case both LeftHandInst and RightHandInst are IMPLICIT_DEF with no input operands, this patch protects against the post-legalizer-combiner matchHoistLogicOpWithSameOpcodeHands with no operands. The prelegalizercombiner-hoist-same-hands.mir test was cleaned up a little in the process, and has a post-legalizer run line added so that the implicit_def do not get folded awwy.
2024-12-06[CGData][GlobalIsel][Legalizer][DAG][MC][AsmParser][X86][AMX] Use ↵abhishek-kaushik22
`std::move` to avoid copy (#118068)
2024-11-18[GlobalISel] Combine [S,U]SUBO (#116489)Thorsten Schütt
We import the llvm.ssub.with.overflow.* Intrinsics, but the Legalizer also builds them while legalizing other opcodes, see narrowScalarAddSub.
2024-11-14[GlobalISel] Turn shuffle a, b, mask -> shuffle undef, b, mask iff mask does ↵Konstantin Schwarz
not reference a (#115377)
2024-11-12[IR] Add helper for comparing KnownBits with IR predicate (NFC) (#115878)Nikita Popov
Add `ICmpInst::compare()` overload accepting `KnownBits`, similar to the existing one accepting `APInt`. This is not directly part of KnownBits (or APInt) for layering reasons.
2024-11-11[AArch64][GlobalISel] Protect against undef first element in ↵David Green
CombineShuffleConcat. In case the first element is undef, we need to look through to find a valid type for the inputs.
2024-11-08Recommit "[GISel][AArch64][AMDGPU][RISCV] Canonicalize (sub X, C) -> (add X, ↵Craig Topper
-C) (#114309)" The increase in fallbacks that was previously reported were not caused by this change. Original description: This matches InstCombine and DAGCombine. RISC-V only has an ADDI instruction so without this we need additional patterns to do the conversion. Some of the AMDGPU tests look like possible regressions. Maybe some patterns from isel aren't imported.
2024-11-06[GlobalISel] Remove references to rhs of shufflevector if rhs is undef (#115076)Konstantin Schwarz
2024-11-06Revert "[GISel][AArch64][AMDGPU][RISCV] Canonicalize (sub X, C) -> (add X, ↵Craig Topper
-C) (#114309)" This reverts commit 999dfb2067eb75609b735944af876279025ac171. I received a report that his may have increased fallbacks on AArch64.
2024-11-05[GlobalISel] Check the correct register in sextload OneUse check. (#114763)David Green
This fixes a bug that started triggering after #111730, where we could remove a load with multiple uses. It looks like the match should be checking the other register in a one-use check. %SrcReg = load.. %DstReg = sign_extend_inreg %SrcReg
2024-11-04[GISel][AArch64][AMDGPU][RISCV] Canonicalize (sub X, C) -> (add X, -C) (#114309)Craig Topper
This matches InstCombine and DAGCombine. RISC-V only has an ADDI instruction so without this we need additional patterns to do the conversion. Some of the AMDGPU tests look like possible regressions. Maybe some patterns from isel aren't imported.
2024-10-31GlobalISel: Fix combine duplicating atomic loads (#111730)Matt Arsenault
The sext_inreg (load) combine was not deleting the old load instruction, and it would never be deleted if volatile or atomic.
2024-10-19[GlobalISel] Combine G_UNMERGE_VALUES with anyext and build vector (#112370)Thorsten Schütt
G_UNMERGE_VALUES (G_ANYEXT (G_BUILD_VECTOR)) ag G_UNMERGE_VALUES llvm/test/CodeGen/AArch64/GlobalISel | grep ANYEXT [ANYEXT] is build vector or shuffle vector Prior art: https://reviews.llvm.org/D87117 https://reviews.llvm.org/D87166 https://reviews.llvm.org/D87174 https://reviews.llvm.org/D87427 ; CHECK-NEXT: [[BUILD_VECTOR2:%[0-9]+]]:_(<8 x s8>) = G_BUILD_VECTOR [[C2]](s8), [[C2]](s8), [[C2]](s8), [[C2]](s8), [[DEF1]](s8), [[DEF1]](s8), [[DEF1]](s8), [[DEF1]](s8) ; CHECK-NEXT: [[ANYEXT1:%[0-9]+]]:_(<8 x s16>) = G_ANYEXT [[BUILD_VECTOR2]](<8 x s8>) ; CHECK-NEXT: [[UV10:%[0-9]+]]:_(<4 x s16>), [[UV11:%[0-9]+]]:_(<4 x s16>) = G_UNMERGE_VALUES [[ANYEXT1]](<8 x s16>) Test: llvm/test/CodeGen/AArch64/GlobalISel/combine-unmerge.mir
2024-10-16AMDGPU/GlobalISel: Run redundant_and combine in RegBankCombiner (#112353)Petar Avramovic
Combine is needed to clear redundant ANDs with 1 that will be created by reg-bank-select to clean-up high bits in register. Fix replaceRegWith from CombinerHelper: If copy had to be inserted, first create copy then delete MI. If MI is deleted first insert point is not valid.
2024-10-05[GISel] Don't preserve NSW flag when converting G_MUL of INT_MIN to G_SHL. ↵Craig Topper
(#111230) mul and shl have different meanings for the nsw flag. We need to drop it when converting a multiply by the minimum negative value.
2024-09-23[AArch64][GlobalISel] Prefer to use Vector Truncate (#105692)chuongg3
Tries to combine scalarised truncates into vector truncate operations EXAMPLE: `%a(i32), %b(i32) = G_UNMERGE %src(<2 x i32>)` `%T_a(i16) = G_TRUNC %a(i32)` `%T_b(i16) = G_TRUNC %b(i32)` `%Imp(i16) = G_IMPLICIT_DEF(i16)` `%dst(v8i16) = G_MERGE_VALUES %T_a(i16), %T_b(i16), %Imp(i16), %Imp(i16)` ===> `%Imp(<2 x i32>) = G_IMPLICIT_DEF(<2 x i32>)` `%Mid(<4 x s16>) = G_CONCAT_VECTORS %src(<2 x i32>), %Imp(<2 x i32>)` `%dst(<4 x s16>) = G_TRUNC %Mid(<4 x s16>)`
2024-08-29[GlobalISel] Add bail outs for scalable vectors to some combines. (#106496)Craig Topper
These combines call getNumElements() which isn't valid for scalable vectors.
2024-08-16[GlobalIsel] Revisit ext of ext. (#102769)Thorsten Schütt
Credits: https://reviews.llvm.org/D86516 combine-ext.mir Notable semantic changes: InstCombine does not mix zero and sign extend, see CastInst::isEliminableCastPair. New version has legality checks. Folds sext/zext of anyext -> sext/zext Support for nneg Future work: nneg zext of sext -> sext sext of nneg zext -> sext
2024-08-09[GlobalIsel] Combine G_ADD and G_SUB with constants (#97771)Thorsten Schütt
2024-07-25[GlobalIsel] Push cast through select. (#100539)Thorsten Schütt
2024-07-24[GlobalIsel] Modernize truncate of ext. (#100338)Thorsten Schütt
Credits: https://github.com/llvm/llvm-project/pull/90964 https://reviews.llvm.org/D87050 combine-trunc.mir Functional changes intended.
2024-07-24[GlobalIsel][NFC] Move cast code (#100196)Thorsten Schütt
Preparation for more cast combines
2024-07-22[GlobalISel] Reorder code in CombinerHelper::buildUDivUsingMul. NFC (#99565)Craig Topper
Group the code for handling Exact udiv together above the code for non-Exact. Move the computeKnownBits call to after the Exact udiv handling.
2024-07-17[CodeGen] Emit more efficient magic numbers for exact udivs (#87161)AtariDreams
Have simpler lowering for exact udivs in both SelectionDAG and GlobalISel. The algorithm is the same between unsigned exact divs and signed divs save for arithmetic vs logical shift for even divisors, according to Hacker's Delight, 2nd Edition, page 242.
2024-07-03[AArch64][GlobalISel] Create copy rather than single-element concatDavid Green
The verifier does not accept single-element G_CONCAT_VECTORS, so if there is a single Op generate a COPY instead.
2024-07-03[GlobalIsel][NFC] Modernize UBFX combine (#97513)Thorsten Schütt
Credits: https://reviews.llvm.org/D99283
2024-07-02[CodeGen] Use range-based for loops (NFC) (#97467)Kazu Hirata
2024-06-28[GlobalISel][AArch64][AMDGPU] Expand FPOWI into series of multiplication ↵isuckatcs
(#95217) SelectionDAG already converts FPOWI into a series of optimized multiplications, this patch introduces the same optimization into GlobalISel.
2024-06-27[CodeGen] Use range-based for loops (NFC) (#96855)Kazu Hirata
2024-06-21Revert "Intrinsic: introduce minimumnum and maximumnum (#93841)"Nikita Popov
As far as I can tell, this pull request was not approved, and did not go through an RFC on discourse. This reverts commit 89881480030f48f83af668175b70a9798edca2fb. This reverts commit 225d8fc8eb24fb797154c1ef6dcbe5ba033142da.
2024-06-21Intrinsic: introduce minimumnum and maximumnum (#93841)YunQiang Su
Currently, on different platform, the behaivor of llvm.minnum is different if one operand is sNaN: When we compare sNaN vs NUM: ARM/AArch64/PowerPC: follow the IEEE754-2008's minNUM: return qNaN. RISC-V/Hexagon follow the IEEE754-2019's minimumNumber: return NUM. X86: Returns NUM but not same with IEEE754-2019's minimumNumber as +0.0 is not always greater than -0.0. MIPS/LoongArch/Generic: return NUM. LIBCALL: returns qNaN. So, let's introduce llvm.minmumnum/llvm.maximumnum, which always follow IEEE754-2019's minimumNumber/maximumNumber. Half-fix: #93033
2024-06-15[GISel] Unify multiple instances of getTypeForLLT (NFC) (#95577)Christudasan Devadasan
Multiple static instances of this utility function have been found in different GlobalISel files. Unifying them by adding an instance in utils.cpp.
2024-06-03[GISel][CombinerHelper] Combine op(trunc(x), trunc(y)) -> trunc(op(x, y)) ↵Dhruv Chawla
(#89023)
2024-06-01[GISel] Convert zext nneg to sext if it is cheaper (#93856)Yingwei Zheng
This patch converts `zext nneg` to `sext` on RISCV to use free sext. --------- Co-authored-by: Thorsten Schütt <schuett@gmail.com>