summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
AgeCommit message (Collapse)Author
2025-06-18AMDGPU: Directly select minimumnum/maximumnum with ieee_mode=0 (#141903)Matt Arsenault
The hardware min/max follow the IR rules with IEEE mode disabled, so we can avoid the canonicalizes of the input. We lose the quieting of a signaling nan if both inputs are nans, but we only require that with strictfp.
2025-06-08[llvm] Compare std::optional<T> to values directly (NFC) (#143340)Kazu Hirata
This patch transforms: X && *X == Y to: X == Y where X is of std::optional<T>, and Y is of T or similar.
2025-06-06AMDGPU: Custom lower fptrunc vectors for f32 -> f16 (#141883)Changpeng Fang
The latest asics support v_cvt_pk_f16_f32 instruction. However current implementation of vector fptrunc lowering fully scalarizes the vectors, and the scalar conversions may not always be combined to generate the packed one. We made v2f32 -> v2f16 legal in https://github.com/llvm/llvm-project/pull/139956. This work is an extension to handle wider vectors. Instead of fully scalarization, we split the vector to packs (v2f32 -> v2f16) to ensure the packed conversion can always been generated.
2025-05-28Warn on misuse of DiagnosticInfo classes that hold Twines (#137397)Justin Bogner
This annotates the `Twine` passed to the constructors of the various DiagnosticInfo subclasses with `[[clang::lifetimebound]]`, which causes us to warn when we would try to print the twine after it had already been destructed. We also update `DiagnosticInfoUnsupported` to hold a `const Twine &` like all of the other DiagnosticInfo classes, since this warning allows us to clean up all of the places where it was being used incorrectly.
2025-05-23[AMDGPU] Correct bitshift legality transformation for small vectors (#140940)zGoldthorpe
Fix for a bug found by the AMD fuzzing project. The legaliser would originally try to widen a small vector such as `<4 x i1>` to a single `i16` during the legalisation of bitshifts, as it was not originally written with consideration for vector operands. This patch simply adds a guard to prohibit this transformation and allow other legalisation transformations to step in.
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-08[GlobalISel][AMDGPU] Fix handling of v2i128 type for AND, OR, XOR (#138574)Chinmay Deshpande
Current behavior crashes the compiler. This bug was found using the AMDGPU Fuzzing project. Fixes SWDEV-508816.
2025-05-07[AMDGPU][Legalizer] Widen i16 G_SEXT_INREG (#131308)Pierre van Houtryve
It's better to widen them to avoid it being lowered into a G_ASHR + G_SHL. With this change we just extend to i32 then trunc the result.
2025-05-05[AMDGPU] Support arbitrary types in amdgcn.dead (#134841)Diana Picus
Legalize the amdgcn.dead intrinsic to work with types other than i32. It still generates IMPLICIT_DEFs. Remove some of the previous code for selecting/reg bank mapping it for 32-bit types, since everything is done in the legalizer now.
2025-04-17AMDGPU: Fix the double rounding issue in v2f64 -> v2f16 conversion (#135659)Changpeng Fang
On targets that support v_cvt_pk_f16_f32 instruction, if we make v2f64 -> v2f16 Legal, we will generate the following sequence of instructions: v_cvt_f32_f64_e32 v1, s[6:7] v_cvt_f32_f64_e32 v2, s[4:5] v_cvt_pk_f16_f32 v1, v2, v1 It possibly returns imprecise results due to double rounding. This patch fixes the issue by not setting the conversion Legal. While we may still expect the above sequence of code when unsafe fpmath is set, I hope https://github.com/llvm/llvm-project/pull/134738 can address that performance concern. Fixes: SWDEV-523856
2025-04-16Reapply "[AMDGPU][GlobalISel] Properly handle lane op lowering for larger ↵Vikram Hegde
vector types (#132358)" (#135758) reapply https://github.com/llvm/llvm-project/pull/132358, tests updated.
2025-04-14Revert "[AMDGPU][GlobalISel] Properly handle lane op lowering for larger ↵Kazu Hirata
vector types (#132358)" This reverts commit 62ef10a0f62c668e1fa7e357f56052f3364544c5. Multiple buildbot failures have been reported: https://github.com/llvm/llvm-project/pull/132358
2025-04-15[AMDGPU][GlobalISel] Properly handle lane op lowering for larger vector ↵Vikram Hegde
types (#132358) Fixes https://github.com/llvm/llvm-project/issues/128650 Also adds few previously existing permlane64 tests which somehow got removed in between.
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-19[AMDGPU] Support image_bvh8_intersect_ray instruction and intrinsic. (#130041)Mariusz Sikora
Co-authored-by: Ivan Kosarev <ivan.kosarev@amd.com>
2025-03-19[AMDGPU] Add intrinsic and MI for image_bvh_dual_intersect_ray (#130038)Mariusz Sikora
- Add llvm.amdgcn.image.bvh.dual.intersect.ray intrinsic and image_bvh_dual_intersect_ray machine instruction. - Add llvm_v10i32_ty and llvm_v10f32_ty --------- Co-authored-by: Mateja Marjanovic <mateja.marjanovic@amd.com>
2025-03-18[NFC][AMDGPU][GlobalISel] Make LLTs constexpr (#131673)Tim Gymnich
- static const -> constexpr
2025-03-17[AMDGPU][GlobalISel] Enable vector reductions (#131413)Tim Gymnich
- Enable llvm vector reductions for AMDGPU. fixes https://github.com/llvm/llvm-project/issues/114816
2025-03-06[AMDGPU][NFC] Update name for BVH Intersect Ray (#130036)Mariusz Sikora
Co-authored-by: Ivan Kosarev <ivan.kosarev@amd.com>
2025-03-04[AMDGPU] Don't store an immediate in a Register. NFCCraig Topper
2025-02-25[AMDGPU][True16][CodeGen] uaddsat/usubsat true16 selection in gisel (#128233)Brox Chen
Enable gisel selection for uaddsat and usubsat in true16 flow This patch includes: 1. Added VGPR_16_Lo128/VGPR_16 to register bank and update register info for recognizing 16bit regclass id and bit width 2. uaddsat/usubsat test update
2025-02-25AMDGPU: Drop legacy r600.read.global.size intrinsics from amdgcn (#128700)Matt Arsenault
These ancient intrinsics were still consumed by the backend for libclc, which no longer uses them.
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-17AMDGPU: Stop emitting an error on illegal addrspacecasts (#127487)Matt Arsenault
These cannot be static compile errors, and should be treated as poison. Invalid casts may be introduced which are dynamically dead. For example: ``` void foo(volatile generic int* x) { __builtin_assume(is_shared(x)); *x = 4; } void bar() { private int y; foo(&y); // violation, wrong address space } ``` This could produce a compile time backend error or not depending on the optimization level. Similarly, the new test demonstrates a failure on a lowered atomicrmw which required inserting runtime address space checks. The invalid cases are dynamically dead, we should not error, and the AtomicExpand pass shouldn't have to consider the details of the incoming pointer to produce valid IR. This should go to the release branch. This fixes broken -O0 compiles with 64-bit atomics which would have started failing in 1d0370872f28ec9965448f33db1b105addaf64ae.
2025-02-11[AMDGPU][NFC] Remove an unneeded return value. (#126739)Ivan Kosarev
And rename the function to disassociate it from the one where generating loading of the input value may actually fail.
2025-01-18[CodeGen] Use Register/MCRegister::isPhysical. NFCCraig Topper
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-08Revert "[amdgpu][lds] Simplify error diag path - lds variable names are no ↵Jon Chesterfield
longer special" Test case didn't run locally, investigating This reverts commit 7bad469182ff2f6423ea209d5a1e81acca600568.
2024-12-08[amdgpu][lds] Simplify error diag path - lds variable names are no longer ↵Jon Chesterfield
special
2024-12-02AMDGPU: Add support for V_CVT_PK_F16_F32 instruction for gfx950 (#118300)Matt Arsenault
Co-authored-by: Shilei Tian <shilei.tian@amd.com>
2024-11-13[AMDGPU] Remove unused includes (NFC) (#116154)Kazu Hirata
Identified with misc-include-cleaner.
2024-11-06[AMDGPU] modify named barrier builtins and intrinsics (#114550)Gang Chen
Use a local pointer type to represent the named barrier in builtin and intrinsic. This makes the definitions more user friendly bacause they do not need to worry about the hardware ID assignment. Also this approach is more like the other popular GPU programming language. Named barriers should be represented as global variables of addrspace(3) in LLVM-IR. Compiler assigns the special LDS offsets for those variables during AMDGPULowerModuleLDS pass. Those addresses are converted to hw barrier ID during instruction selection. The rest of the instruction-selection changes are primarily due to the intrinsic-definition changes.
2024-11-05[AMDGPU] Extend type support for update_dpp intrinsic (#114597)Stanislav Mekhanoshin
We can split 64-bit DPP as a post-RA pseudo if control values are supported, but cannot handle other types.
2024-11-01Reapply "[AMDGPU][GlobalISel] Fix load/store of pointer vectors, buffer.*.pN ↵Krzysztof Drewniak
(#110714)" v3 (#114443) This reverts commit 8a849a2a567d4e519b246a16936b6e7519936d4b. It seems I missed a spot when trying to ensure the code in the instruction selection tests were actually legalized MIR.
2024-10-31[AMDGPU] Extend mov_dpp8 intrinsic lowering for generic types (#114296)Stanislav Mekhanoshin
The int_amdgcn_mov_dpp8 is overloaded, but we can only select i32. To allow a corresponding builtin to be overloaded the same way as int_amdgcn_mov_dpp we need it to be able to split unsupported values.
2024-10-10Revert "Reapply "[AMDGPU][GlobalISel] Fix load/store of pointer vectors, ↵Mikhail Goncharov
buffer.*.pN (#110714)" v2 (#111708)" This reverts commit 4b4a0d419c81b8b12a7dbb33dae1f7e9be91a88f. New test fails on buildbots https://lab.llvm.org/buildbot/#/builders/63/builds/2039 https://lab.llvm.org/buildbot/#/builders/127/builds/1055
2024-10-09Reapply "[AMDGPU][GlobalISel] Fix load/store of pointer vectors, buffer.*.pN ↵Krzysztof Drewniak
(#110714)" v2 (#111708) This adds `-disable-gisel-legality-check` to some gfx6 and gfx7 test lines to prevent behavior mismatches between debug and release builds The first attempted reapply was #111059 This reverts commit e075dcf7d270fd52dc837163ff24e8c872dfeb49.
2024-10-08[AMDGPU] Adopt new lowering sequence for `fdiv16` (#109295)Shilei Tian
The current lowering of `fdiv16` can generate incorrectly rounded result in some cases. The new sequence was provided by the HW team, as shown below written in C++. ``` half fdiv(half a, half b) { float a32 = float(a); float b32 = float(b); float r32 = 1.0f / b32; float q32 = a32 * r32; float e32 = -b32 * q32 + a32; q32 = e32 * r32 + q32; e32 = -b32 * q32 + a32; float tmp = e32 * r32; uin32_t tmp32 = std::bit_cast<uint32_t>(tmp); tmp32 = tmp32 & 0xff800000; tmp = std::bit_cast<float>(tmp32); q32 = tmp + q32; half q16 = half(q32); q16 = div_fixup_f16(q16); return q16; } ``` Fixes SWDEV-477608.
2024-10-06Revert "Reapply "[AMDGPU][GlobalISel] Fix load/store of pointer vectors, ↵NAKAMURA Takumi
buffer.*.pN (#110714)" (#111059)" This reverts commit 98a15c7b0c6ec129d371f0c121dbe9396c4f5609. (llvmorg-20-init-8051-g98a15c7b0c6e)
2024-10-04Reapply "[AMDGPU][GlobalISel] Fix load/store of pointer vectors, buffer.*.pN ↵Krzysztof Drewniak
(#110714)" (#111059) This reverts commit 650c41aad2eb43c634a05b2b5799a0c13a73b92f. The test failures appear to be from conflicts with other PRs that landed around this time.
2024-10-03[AMDGPU] Qualify auto. NFC. (#110878)Jay Foad
Generated automatically with: $ clang-tidy -fix -checks=-*,llvm-qualified-auto $(find lib/Target/AMDGPU/ -type f)
2024-10-03Revert "[AMDGPU][GlobalISel] Fix load/store of pointer vectors, buffer.*.pN ↵NAKAMURA Takumi
(#110714)" Some builders has been failing tests. ``` Failed Tests (2): LLVM :: CodeGen/AMDGPU/GlobalISel/inst-select-load-global-old-legalization.mir LLVM :: CodeGen/AMDGPU/GlobalISel/inst-select-load-local.mir ``` This reverts commit ae5bd2a9f292037c605b2ec0ee31200581bd8701. (llvmorg-20-init-7805-gae5bd2a9f292)
2024-10-02[AMDGPU][GlobalISel] Fix load/store of pointer vectors, buffer.*.pN (#110714)Krzysztof Drewniak
Certain pointer address spaces were not being correctly handled by the GlobalISel lowering for buffer_load and buffer_store. 1. ptr addrspace(1) and addrspace(4) did not have rewrite patterns defined for them, while p0 did, since those pointer types weren't in the list of types that was iterated to form the patterns. 2. Vectors of pointers need to be bitcast to vectors of the corresponding scalars, since there doesn't seem to be a good way to define the rewrite patterns for buffer_load/store of those types The need to bitcast vectors of pointers was also revealed to affect ordinary `G_LOAD` and `G_STORE` in some cases, so `shouldBitcastLoadStore()` has been fixed to handle it properly.
2024-09-25Reland "[AMDGPU][GlobalIsel] Use isRegisterClassType for G_FREEZE and ↵sstipano
G_IMPLICIT_DEF (#101331)" (#109958) S192 type was missing from AllScalarTypes.
2024-09-25Revert "[AMDGPU][GlobalIsel] Use isRegisterClassType for G_FREEZE and ↵NAKAMURA Takumi
G_IMPLICIT_DEF (#101331)" This reverts commit 63b2595846b86b4e4eb9afba5e97dd64e8135c10. (llvmorg-20-init-6782-g63b2595846b8) A few bots have been failing on `inst-select-unmerge-values.mir`
2024-09-24[AMDGPU][GlobalIsel] Use isRegisterClassType for G_FREEZE and G_IMPLICIT_DEF ↵sstipano
(#101331) G_FREEZE was legal for <13 x S32> which caused an infinite loop in the combiner
2024-09-11[AMDGPU] Simplify and improve codegen for llvm.amdgcn.set.inactive (#107889)Jay Foad
Always generate v_cndmask_b32 instead of modifying exec around v_mov_b32. This is expected to be faster because modifying exec generally causes pipeline stalls.
2024-09-06[AMDGPU] Add target intrinsic for s_buffer_prefetch_data (#107293)Stanislav Mekhanoshin
2024-08-29AMDGPU: Use pattern to select instruction for intrinsic llvm.fptrunc.round ↵Changpeng Fang
(#105761) Use GCNPat instead of Custom Lowering to select instructions for intrinsic llvm.fptrunc.round. "SupportedRoundMode : TImmLeaf" is used as a predicate to select only when the rounding mode is supported. "as_hw_round_mode : SDNodeXForm" is developed to translate the round modes to the corresponding ones that hardware recognizes.