summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
AgeCommit message (Collapse)Author
2025-06-26[GlobalISel] Remove dead code. (NFC) (#145811)Pete Chou
LegalizerHelper::lowerMemCpyFamily only execpts G_MEMCPY, G_MEMMOVE, and G_MMSET.
2025-06-25[X86][GlobalISel] Enable SINCOS with libcall mapping (#142438)JaydeepChauhan14
2025-06-23PowerPC: Stop reporting memcpy as an alias of memmove on AIX (#143836)Matt Arsenault
Instead of reporting ___memmove as an implementation of memcpy, make it unavailable and let the lowering logic consider memmove as a fallback path. This avoids a special case 1:N mapping for libcall implementations.
2025-06-23CodeGen: Emit error if getRegisterByName fails (#145194)Matt Arsenault
This avoids using report_fatal_error and standardizes the error message in a subset of the error conditions.
2025-06-21[GlobalISel] Widen vector loads from aligned ptrs (#144309)David Green
If the pointer is aligned to more than the size of the vector, we can widen the load up to next power of 2 size, as SDAG performs. Some of the v3 tests are currently worse - those should be addressed in other issues.
2025-06-15[GlobalISel] Split Legalizer debug ouput into paragraphs. NFC (#143427)David Green
This helps keep the legalizer output easier to read, splitting each instructions legalization into a separate block.
2025-06-05[GlobalISel] support lowering of G_SHUFFLEVECTOR with pointer args (#141959)Stanley Gambarin
2025-05-21AMDGPU/GlobalISel: Start legalizing minimumnum and maximumnum (#140900)Matt Arsenault
This is the bare minimum to get the intrinsic to compile for AMDGPU, and it's not optimal. We need to follow along closer with the existing G_FMINNUM/G_FMAXNUM with custom lowering to handle the IEEE=0 case better. Just re-use the existing lowering for the old semantics for G_FMINNUM/G_FMAXNUM. This does not change G_FMINNUM/G_FMAXNUM's treatment, nor try to handle the general expansion without an underlying min/max variant (or with G_FMINIMUM/G_FMAXIMUM).
2025-05-13[GISel][AArch64] Added more efficient lowering of Bitreverse (#139233)jyli0116
GlobalISel was previously inefficient in handling bitreverses of vector types. This deals with i16, i32, i64 vector types and converts them into i8 bitreverses and rev instructions.
2025-05-06[GlobalISel][AArch64] Handles bitreverse to prevent falling back (#138150)jyli0116
Handles bitreverse for vector types which were previously falling back onto Selection DAG. Includes 8-bit element vectors greater than 128 bits and less than 64 bits: <32 x i8>, <4 x i8>, and odd vector types: <9 x i8>.
2025-05-05[CodeGen] Use range-based for loops (NFC) (#138488)Kazu Hirata
This is a reland of #138434 except that: - the bits for llvm/lib/CodeGen/RenameIndependentSubregs.cpp have been dropped because they caused a test failure under asan, and - the bits for llvm/lib/CodeGen/SelectionDAG/ScheduleDAGFast.cpp have been improved with structured bindings.
2025-05-04Revert "[CodeGen] Use range-based for loops (NFC) (#138434)"Nico Weber
This reverts commit a9699a334bc9666570418a3bed9520bcdc21518b. Breaks CodeGen/AMDGPU/collapse-endcf.ll in several configs (sanitizer builds; macOS; possibly more), see comments on https://github.com/llvm/llvm-project/pull/138434
2025-05-04[CodeGen] Remove unused local variables (NFC) (#138441)Kazu Hirata
2025-05-04[CodeGen] Use range-based for loops (NFC) (#138434)Kazu Hirata
2025-04-29[GlobalISel] Fix miscompile when narrowing vector loads/stores to ↵Tobias Stadler
non-byte-sized types (#136739) LegalizerHelper::reduceLoadStoreWidth does not work for non-byte-sized types, because this would require (un)packing of bits across byte boundaries. Precommit tests: #134904
2025-04-16[llvm] Use llvm::append_range (NFC) (#136066)Kazu Hirata
This patch replaces: llvm::copy(Src, std::back_inserter(Dst)); with: llvm::append_range(Dst, Src); for breavity. One side benefit is that llvm::append_range eventually calls llvm::SmallVector::reserve if Dst is of llvm::SmallVector.
2025-04-13[CodeGen] Use llvm::append_range (NFC) (#135567)Kazu Hirata
2025-03-29[CodeGen] Use llvm::append_range (NFC) (#133603)Kazu Hirata
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-22[llvm] Construct SmallVector with ArrayRef (NFC) (#132560)Kazu Hirata
2025-03-20[AArch64][GlobalISel] Legalize more CTPOP vector types. (#131513)David Green
Similar to other operations, s8, s16 s32 and s64 vector elements are clamped to legal vector sizes, odd number of elements are widened to the next power-2 and s128 is scalarized. This helps legalize cttz as well as ctpop.
2025-03-19[AArch64][GlobalISel] Clean up CTLZ vector type legalization. (#131514)David Green
Similar to other operations, s8, s16 and s32 vector elements are clamped to legal vector sizes, but in this case s64 are scalarized to use the gpr instructions. This allows vector types to split as opposed to scalarizing.
2025-03-18[CodeGen][GlobalISel] Add a getVectorIdxWidth and getVectorIdxLLT. (#131526)David Green
From #106446, this adds a variant of getVectorIdxTy that returns an LLT. Many uses only look at the width, so a getVectorIdxWidth was added as the common base.
2025-03-02[GlobalISel] Use Register. NFCCraig Topper
2025-02-20[GlobalISel][AArch64] Fix fptoi.sat lowering. (#127901)David Green
The SDAG version uses fminnum/fmaxnum, in converting it to fcmp+select it appears the order of the operands was chosen badly. This switches the conditions used to keep the constant on the RHS.
2025-02-20Revert "AMDGPU: Don't canonicalize fminnum/fmaxnum if targets support IEEE ↵Matt Arsenault
fminimum(maximum)_num (#127711)" This reverts commit 36eaf0daf5d6dd665d7c7a9ec38ea22f27709fed. This is not a sound approach to dealing with this instruction change. The new behavior is a different opcode pair, not a modifier on the existing opcode.
2025-02-19AMDGPU: Don't canonicalize fminnum/fmaxnum if targets support IEEE ↵Changpeng Fang
fminimum(maximum)_num (#127711) For targets that support IEEE fminimum_num/fmaximum_num, the corresponding *_min_num_fXY/*_max_num_fXY instructions themselves already did the canonicalization for the inputs. As a result, we do not need to explicitly canonicalize the inputs for fminnum/fmaxnum.
2025-02-03[X86][GlobalISel] Enable G_LROUND/G_LLROUND with libcall mapping (#125096)JaydeepChauhan14
2025-02-02[AArch64][GlobalISel] Add disjoint handling for add_and_or_is_add. (#123594)David Green
This allows us to easily detect, without known-bits, that the or in a fshl/fshr is disjoint allowing us to use usra under aarch64.
2025-01-30[AArch64][GlobalISel] Legalize more G_VECREDUCE_ADD operations. (#123392)David Green
Non-power-2 vectors will now be padded with zero elements, smaller vectors will be widened using anyext, which I believe will be better in many situations than padding with zeros, although some small types may prefer being scalarized depending on the code. Padding with zeros may not be best for all sizes (v5i8 being the worst), we can hopefully improve that in the future but they no longer fall back. We scalarize other types like i128.
2025-01-06[AArch64][GlobalISel] Fix legalization for <4 x i1> vector stores.Amara Emerson
This case is different from the earlier <8 x i1> case handled because it triggers a legalization failure in lowerStore() that's intended for scalar code. It also was triggering incorrect bitcast actions in the AArch64 rules that weren't expecting truncating stores. With these two fixed, more cases are handled. The code is still bad, including some missing load promotion in our combiners that result in dead stores hanging around at the end of codegen. Again, we can fix these in separate changes. Reviewers: davemgreen, madhur13490, topperc, arsenm Reviewed By: davemgreen Pull Request: https://github.com/llvm/llvm-project/pull/121185
2025-01-06[AArch64][GlobalISel] Add support for lowering trunc stores of vector bools.Amara Emerson
This is essentially a port of TargetLowering::scalarizeVectorStore(), which is used for the case where we have something like a store of <8 x s8> truncating to <8 x s1> in memory. The naive lowering is a sequence of extracts to compute a scalar value to store. AArch64's DAG implementation has some more smarts to improve this further which we can do later. Reviewers: topperc, davemgreen Pull Request: https://github.com/llvm/llvm-project/pull/121169
2025-01-05[AArch64][GlobalISel] Legalize vector boolean bitcasts to scalars by ↵Amara Emerson
lowering via stack. Reviewers: davemgreen, topperc, arsenm Reviewed By: arsenm Pull Request: https://github.com/llvm/llvm-project/pull/121171
2025-01-05[AArch64][GlobalISel] Add support for widening vector store elements to s8.Amara Emerson
Reviewers: topperc, arsenm, davemgreen Reviewed By: arsenm Pull Request: https://github.com/llvm/llvm-project/pull/121170
2024-12-15[GISel][RISCV] Use isSExtCheaperThanZExt when widening G_UMAX/G_UMIN. (#120041)Craig Topper
Similar to what we do for unsigned comparisons after #120032.
2024-12-15[GISel][RISCV] Use isSExtCheaperThanZExt when widening G_ICMP. (#120032)Craig Topper
Sign extending i32->i64 is more efficient than zero extend for RV64.
2024-12-15[GISel][RISCV][AArch64] Support legalizing G_SCMP/G_UCMP to sub(isgt,islt). ↵Craig Topper
(#119265) Convert the LLT to EVT and call TargetLowering::shouldExpandCmpUsingSelects to determine if we should do this. We don't have a getSetccResultType, so I'm boolean extending the compares to the result type and using that. If the compares legalize to the same type, these extends will get removed. Unfortunately, if the compares legalize to a different type, we end up with truncates or extends that might not be optimally placed.
2024-12-15[AArch64][GlobalISel] Scalarize i128 shufflevector instructions. (#119980)David Green
This, like other operations, scalarizes shuffle vector operations with types larger than 64bits. ImplicitDef and Freeze are also handled the same way, to allow them to legalize. The legalization of fewerElementsVectorShuffle is adjusted to handled scalarization.
2024-12-12[GISel] Support narrowing G_ICMP with more than 2 parts. (#119335)Craig Topper
This allows us to support i128 G_ICMP on RV32. I'm not sure how to test the "left over" part of this as RISC-V always widens to a power of 2 before narrowing.
2024-12-12[GlobalISel][NFC] Fix LLT Propagation (#119587)Tim Gymnich
Retain LLT type information by creating new LLTs from the original LLT instead of only using the original scalar size. This PR prepares for the [LLT FPInfo RFC](https://discourse.llvm.org/t/rfc-globalisel-adding-fp-type-information-to-llt/83349/24) where LLTs will carry additional floating point type information in addition to the scalar size.
2024-12-10[GISel][SDAG] Avoid push_back in loops for some shuffle mask handling. (#119434)Craig Topper
Each call to push_back contains a check to see if the vector needs to grow. Using resize or giving the size to the constructor can reduce the number of checks for growing.
2024-12-10[GISel] Use SmallVector::append instead of copying one element at a time. ↵Craig Topper
(#119321)
2024-12-09[GISel] Avoid creating a virtual register we don't need. (#119305)Craig Topper
narrowScalarAddSub was creating a virtual register and then overwriting the Register variable without using it. Add an else and only create it when needed.
2024-12-04[RISCV][GISel] Stop over promoting G_SITOFP/UITOFP libcalls on RV64. (#118597)Craig Topper
When we have legal instructions we want to promote to sXLen and let isel pattern matching removing the and/sext_inreg. When using a libcall we want to use a 'si' libcall for small types instead of 'di'. To match the RV64 ABI, we need to sign extend `unsigned int` arguments. We reuse the shouldSignExtendTypeInLibCall hook from SelectionDAG.
2024-12-02[RISCV][GISel] Support f32/f64 ldexp. (#117941)Craig Topper
The existing libcall lowering in LegalizerHelper.cpp did not account for one operand being integer. Reuse the G_FPOWI code to fix this.
2024-12-02[RISCV][GISel] Support f32/f64 powi. (#117937)Craig Topper
Need to force libcall legalization to treat the integer argument as signed so that it can be promoted to XLen in call lowering for RV64. Alternatively we could promote the operand before converting to libcall, but going through call lowering is closer to what SelectionDAG does.
2024-11-26[RISCV][GISel] Use libcalls for f32/f64 G_FCMP without F/D extensions. (#117660)Craig Topper
LegalizerHelp only supported f128 libcalls and incorrectly assumed that the destination register for the G_FCMP was s32.
2024-11-25[GISel] #undef macros when they are no longer needed. NFC (#117652)Craig Topper
These macros are created inside a function. They should be undefined before the end of the function.
2024-11-23[AArch64][GlobalISel] Legalize ptr shuffle vector to s64 (#116013)David Green
This converts all ptr element shuffle vectors to s64, so that the existing vector legalization handling can lower them as needed. This prevents a lot of fallbacks that currently try to generate things like `<2 x ptr> G_EXT`. I'm not sure if bitcast/inttoptr/ptrtoint is intended to be necessary for vectors of pointers, but it uses buildCast for the casts, which now generates a ptrtoint/inttoptr.
2024-10-24[aarch64] atan2 intrinsic lowering (p5) (#112611)Tex Riddell
This change is part of this proposal: https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294 - `VecFuncs.def`: define intrinsic to sleef/armpl mapping - `LegalizerHelper.cpp`: add missing fewerElementsVector handling for the new atan2 intrinsic - `AArch64ISelLowering.cpp`: Add arch64 specializations for lowering like neon instructions - `AArch64LegalizerInfo.cpp`: Legalize atan2. Part 5 for Implement the atan2 HLSL Function #70096.