summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
AgeCommit message (Collapse)Author
2025-06-23[IRTranslator] Remove unnecessary isIntrinsic() check (NFC)Nikita Popov
Directly call getIntrinsicID(), there is no need to check for isIntrinsic() first.
2025-05-22[LLVM][CodeGen] Add convenience accessors for MachineFunctionProperties ↵users/pcc/spr/main.elf-add-branch-to-branch-optimizationRahul Joshi
(#140002) Add per-property has<Prop>/set<Prop>/reset<Prop> functions to MachineFunctionProperties.
2025-05-22[CodeGen] Add SSID & Atomic Ordering to IntrinsicInfo (#140896)Pierre van Houtryve
getTgtMemIntrinsic should be able to propagate such information to the MMO
2025-05-08GlobalISel: Translate minimumnum and maximumnum (#139106)Matt Arsenault
2025-05-05[IntrinsicInst] Remove MemCpyInlineInst and MemSetInlineInst [nfc] (#138568)Philip Reames
I'm looking for ways to simplify the Mem*Inst class structure, and these two seem to have fairly minimal justification, so let's remove them.
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] Use range-based for loops (NFC) (#138434)Kazu Hirata
2025-05-02[llvm] Remove redundant control flow (NFC) (#138304)Kazu Hirata
2025-04-30Reland [llvm] Add support for llvm IR atomicrmw fminimum/fmaximum ↵Jonathan Thackray
instructions (#137701) This patch adds support for LLVM IR atomicrmw `fmaximum` and `fminimum` instructions. These mirror the `llvm.maximum.*` and `llvm.minimum.*` instructions, but are atomic and use IEEE754 2019 handling for NaNs, which is different to `fmax` and `fmin`. See: https://llvm.org/docs/LangRef.html#llvm-minimum-intrinsic for more details. Future changes will allow this LLVM IR to be lowered to specialised assembler instructions on suitable targets, such as AArch64.
2025-04-28Revert "[llvm] Add support for llvm IR atomicrmw fminimum/fmaximum ↵Jonathan Thackray
instructions" (#137657) Reverts llvm/llvm-project#136759 due to bad interaction with c792b25e4
2025-04-28[llvm] Add support for llvm IR atomicrmw fminimum/fmaximum instructions ↵Jonathan Thackray
(#136759) This patch adds support for LLVM IR atomicrmw `fmaximum` and `fminimum` instructions. These mirror the `llvm.maximum.*` and `llvm.minimum.*` instructions, but are atomic and use IEEE754 2019 handling for NaNs, which is different to `fmax` and `fmin`. See: https://llvm.org/docs/LangRef.html#llvm-minimum-intrinsic for more details. Future changes will allow this LLVM IR to be lowered to specialised assembler instructions on suitable targets, such as AArch64.
2025-04-28[LLVM][GlobalISel] Ensure G_{F}CONSTANT only store references to scalar ↵Paul Walker
Constant{Int,FP}. (#137319)
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-03-29[CodeGen] Use llvm::append_range (NFC) (#133603)Kazu Hirata
2025-03-20[SelectionDAG] Not issue TRAP node if naked function (#132147)yonghong-song
In [1], Nikita Popov suggested that during lowering 'unreachable' insn should not generate extra code for naked functions, and this applies to all architectures. Note that for naked functions, 'unreachable' insn is necessary in IR since the basic block needs a terminator to end. This patch checked whether a function is naked function or not. If it is a naked function, 'unreachable' insn will not generate ISD::TRAP. [1] https://github.com/llvm/llvm-project/pull/131731 Co-authored-by: Yonghong Song <yonghong.song@linux.dev>
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-04[GlobalISel] Avoid repeated hash lookups (NFC) (#129653)Kazu Hirata
2025-02-10[NFC][LLVM] Remove unused `TargetIntrinsicInfo` class (#126003)Rahul Joshi
Remove `TargetIntrinsicInfo` class as its practically unused (its pure virtual with no subclasses) and its references in the code.
2025-02-04GlobalISel: Fix defined register of invariant.start (#125664)Robert Imschweiler
In contrast to SelectionDAG, GlobalISel created a new virtual register for the return value of invariant.start, leaving subsequent users of the invariant.start value with an undefined reference. A minimal example: ``` %tmp = alloca i32, align 4, addrspace(5) %tmpI = call ptr @llvm.invariant.start.p5(i64 4, ptr addrspace(5) %tmp) #3 call void @llvm.invariant.end.p5(ptr %tmpI, i64 4, ptr addrspace(5) %tmp) #3 store i32 %i, ptr %tmpI, align 4 ``` Although the return value of invariant.start might not be intended for any use beyond invariant.end (the fuzzer might not have created a sensible situation here), an implicit definition of the corresponding virtual register avoids a segfault in the target instruction selector later. This LLVM defect was identified via the AMD Fuzzing project.
2025-01-27[GISel] Explicitly disable BF16 tablegen patterns. (#124113)David Green
We currently have an issue where bf16 patters can be used to match fp16 types, as GISel does not know about the difference between the two. This patch explicitly disables them to make sure that they are never used. The opposite can also happen too, where fp16 patterns are used for operators that should be bf16. So this also changes any operations with bf16 types to now cause a fallback to SDAG. The pass setup for GISel has been slightly adjusted to make sure that a verify pass does not get added between AMD-SDAG and SIFixSGPRCopiesPass, which otherwise can cause verifier issues when falling back.
2025-01-24[NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites ↵Jeremy Morse
(#123737) As part of the "RemoveDIs" project, BasicBlock::iterator now carries a debug-info bit that's needed when getFirstNonPHI and similar feed into instruction insertion positions. Call-sites where that's necessary were updated a year ago; but to ensure some type safety however, we'd like to have all calls to getFirstNonPHI use the iterator-returning version. This patch changes a bunch of call-sites calling getFirstNonPHI to use getFirstNonPHIIt, which returns an iterator. All these call sites are where it's obviously safe to fetch the iterator then dereference it. A follow-up patch will contain less-obviously-safe changes. We'll eventually deprecate and remove the instruction-pointer getFirstNonPHI, but not before adding concise documentation of what considerations are needed (very few). --------- Co-authored-by: Stephen Tozer <Melamoto@gmail.com>
2024-11-29[GISel] Add generic implementation for @llvm.expect.with.probability when ↵antangelo
optimizations are disabled (#117835) Handle @llvm.expect.with.probability in GlobalISel in the same way @llvm.expect is handled, passing the value through as-is. This can be encountered if the intrinsic is used without optimizations, which would otherwise transform it out. Fixes #115411 for GlobalISel
2024-11-12[llvm] Remove redundant control flow statements (NFC) (#115831)Kazu Hirata
Identified with readability-redundant-control-flow.
2024-11-11[GlobalISel] Import llvm.stepvector (#115721)Thorsten Schütt
2024-11-11[AArch64][GlobalISel] Do not create LIFETIME instructions in functions. ↵David Green
(#115669) For the same reason that we do not translate lifetime markers in a -O0, we should not translate them for optnone functions too.
2024-11-08[GlobalISel] Remove unused includes (NFC) (#115429)Kazu Hirata
Identified with misc-include-cleaner.
2024-11-08[GlobalISel][AArch64] Legalize G_EXTRACT_VECTOR_ELT for SVE (#115161)Thorsten Schütt
AArch64InstrGISel.td defines: def : GINodeEquiv<G_EXTRACT_VECTOR_ELT, vector_extract>; There are many patterns for SVE. Let's exploit that fact.
2024-10-30[GlobalISel] Import samesign flag (#114267)Thorsten Schütt
Credits: https://github.com/llvm/llvm-project/pull/111419 Fixes icmp-flags.mir First attempt: https://github.com/llvm/llvm-project/pull/113090 Revert: https://github.com/llvm/llvm-project/pull/114256
2024-10-30Revert "[GlobalISel] Import samesign flag" (#114256)Thorsten Schütt
Reverts llvm/llvm-project#113090
2024-10-30[GlobalISel] Import samesign flag (#113090)Thorsten Schütt
Credits: https://github.com/llvm/llvm-project/pull/111419
2024-10-29[IR] Add `llvm.sincos` intrinsic (#109825)Benjamin Maxwell
This adds the `llvm.sincos` intrinsic, legalization, and lowering. The `llvm.sincos` intrinsic takes a floating-point value and returns both the sine and cosine (as a struct). ``` declare { float, float } @llvm.sincos.f32(float %Val) declare { double, double } @llvm.sincos.f64(double %Val) declare { x86_fp80, x86_fp80 } @llvm.sincos.f80(x86_fp80 %Val) declare { fp128, fp128 } @llvm.sincos.f128(fp128 %Val) declare { ppc_fp128, ppc_fp128 } @llvm.sincos.ppcf128(ppc_fp128 %Val) declare { <4 x float>, <4 x float> } @llvm.sincos.v4f32(<4 x float> %Val) ``` The lowering is built on top of the existing FSINCOS ISD node, with additional type legalization to allow for f16, f128, and vector values.
2024-10-17[PowerPC][ISelLowering] Support -mstack-protector-guard=tls (#110928)Keith Packard
Add support for using a thread-local variable with a specified offset for holding the stack guard canary value. This supports both 32- and 64- bit PowerPC targets. This mirrors changes from #108942 but targeting PowerPC instead of RISCV. Because both of these PRs modify the same driver functions, this series is stack on top of the RISC-V one. --------- Signed-off-by: Keith Packard <keithp@keithp.com>
2024-10-12[CodeGen] Generalize trap emission after SP check fail (#109744)duk
Generalize and improve some target-specific code that emits traps after stack protector failure in SelectionDAG & GlobalIsel.
2024-10-04[LLVM] Add HasFakeUses to MachineFunction (#110097)Stephen Tozer
Following the addition of the llvm.fake.use intrinsic and corresponding MIR instruction, two further changes are planned: to add an -fextend-lifetimes flag to Clang that emits these intrinsics, and to have -Og enable this flag by default. Currently, some logic for handling fake uses is gated by the optdebug attribute, which is intended to be switched on by -fextend-lifetimes (and by extension -Og later on). However, the decision was made that a general optdebug attribute should be incompatible with other opt_ attributes (e.g. optsize, optnone), since they all express different intents for how to optimize the program. We would still like to allow -fextend-lifetimes with optsize however (i.e. -Os -fextend-lifetimes should be legal), since it may be a useful configuration and there is no technical reason to not allow it. This patch resolves this by tracking MachineFunctions that have fake uses, allowing us to run passes that interact with them and skip passes that clash with them.
2024-09-30[GlobalISel] Import extract/insert subvector (#110287)Thorsten Schütt
Test: AArch64/GlobalISel/irtranslator-subvector.ll Reference: https://llvm.org/docs/LangRef.html#llvm-vector-extract-intrinsic https://llvm.org/docs/LangRef.html#llvm-vector-insert-intrinsic
2024-09-26[SPIRV] Add atan2 function lowering (p2) (#110037)Tex Riddell
This change is part of this proposal: https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294 - Add generic opcode for atan2 - Add SPIRV lowering for atan2 Part 2 for Implement the atan2 HLSL Function #70096.
2024-09-19[LLVM] Use {} instead of std::nullopt to initialize empty ArrayRef (#109133)Jay Foad
It is almost always simpler to use {} instead of std::nullopt to initialize an empty ArrayRef. This patch changes all occurrences I could find in LLVM itself. In future the ArrayRef(std::nullopt_t) constructor could be deprecated or removed.
2024-09-18[CodeGen] Use Register in SwitchLoweringUtils. NFC (#109092)Craig Topper
Use an empty Register() instead of -1U.
2024-09-16[GlobalISel][AArch64] Add G_FPTOSI_SAT/G_FPTOUI_SAT (#96297)David Green
This is an implementation of the saturating fp to int conversions for GlobalISel. On AArch64 the converstion instrctions work this way, producing saturating results. LegalizerHelper::lowerFPTOINT_SAT is ported from SDAG. AArch64 has a lot of existing tests for fptosi_sat, covering a wide range of types. I have tried to make most of them work all at once, but a few fall back due to other missing features such as f128 handling for min/max.
2024-09-14[IRTranslator][RISCV] Support scalable vector zeroinitializer. (#108666)Craig Topper
2024-09-13[IRTranslator] Simplify fixed vector ConstantAggregateZero handling. NFC ↵Craig Topper
(#108667) We don't need to loop through the elements, they're all the same zero. We can get the first element and create a splat build_vector.
2024-09-06[GISel] Use Function::getFunctionType() instead of getType() in some ↵Craig Topper
remarks. (#107651) getType() on a Function is always 'ptr'. We should use getFunctionType() so we get the function signature.
2024-09-06Add usub_cond and usub_sat operations to atomicrmw (#105568)anjenner
These both perform conditional subtraction, returning the minuend and zero respectively, if the difference is negative.
2024-08-29[GISel][RISCV] Correctly handle scalable vector shuffles of pointer vectors ↵Craig Topper
in IRTranslator. (#106580)
2024-08-29[ExtendLifetimes] Implement llvm.fake.use to extend variable lifetimes (#86149)Stephen Tozer
This patch is part of a set of patches that add an `-fextend-lifetimes` flag to clang, which extends the lifetimes of local variables and parameters for improved debuggability. In addition to that flag, the patch series adds a pragma to selectively disable `-fextend-lifetimes`, and an `-fextend-this-ptr` flag which functions as `-fextend-lifetimes` for this pointers only. All changes and tests in these patches were written by Wolfgang Pieb (@wolfy1961), while Stephen Tozer (@SLTozer) has handled review and merging. The extend lifetimes flag is intended to eventually be set on by `-Og`, as discussed in the RFC here: https://discourse.llvm.org/t/rfc-redefine-og-o1-and-add-a-new-level-of-og/72850 This patch implements a new intrinsic instruction in LLVM, `llvm.fake.use` in IR and `FAKE_USE` in MIR, that takes a single operand and has no effect other than "using" its operand, to ensure that its operand remains live until after the fake use. This patch does not emit fake uses anywhere; the next patch in this sequence causes them to be emitted from the clang frontend, such that for each variable (or this) a fake.use operand is inserted at the end of that variable's scope, using that variable's value. This patch covers everything post-frontend, which is largely just the basic plumbing for a new intrinsic/instruction, along with a few steps to preserve the fake uses through optimizations (such as moving them ahead of a tail call or translating them through SROA). Co-authored-by: Stephen Tozer <stephen.tozer@sony.com>
2024-08-19[GlobalISel] Bail out early for big-endian (#103310)David Green
If we continue through the function we can currently hit crashes. We can bail out early and fall back to SDAG. Fixes #103032
2024-08-16[CodeGen] Use range-based for loops (NFC) (#104536)Kazu Hirata
2024-08-13[GlobalISel] IRTranslator: Use RAIIMFObsDelInstaller (#102379)Tobias Stadler
Similar to #102156. runOnMachineFunction() installs the Observer correctly manually. finishPendingPhis() doesn't install into the MF, but this currently can't cause issues because DILocationVerifier doesn't care about changed instructions. Switch to RAIIMFObsDelInstaller in both places for consistency.
2024-08-06[CodeGen] Use BasicBlock numbers to map to MBBs (#101883)Alexis Engelke
Now that basic blocks have numbers, we can replace the BB-to-MBB maps and the visited set during ISel with vectors for faster lookup.