aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/Mips/MipsISelLowering.cpp
AgeCommit message (Collapse)AuthorFilesLines
4 days[llvm] Extract and propagate callee_type metadataPrabhu Rajasekaran1-1/+5
Update MachineFunction::CallSiteInfo to extract numeric CalleeTypeIds from callee_type metadata attached to indirect call instructions. Reviewers: nikic, ilovepi Reviewed By: ilovepi Pull Request: https://github.com/llvm/llvm-project/pull/87575
7 daysRevert "[MIPS]Fix QNaNs in the MIPS legacy NaN encodings" (#150773)Nikita Popov1-29/+0
Reverts llvm/llvm-project#139829. We can't just randomly change the value of constants during lowering. Fixes https://github.com/llvm/llvm-project/issues/149295.
2025-07-10[TargetLowering] Change getOptimalMemOpType and findOptimalMemOpLowering to ↵Boyao Wang1-1/+2
take LLVM Context (#147664) Add LLVM Context to getOptimalMemOpType and findOptimalMemOpLowering. So that we can use EVT::getVectorVT to generate EVT type in getOptimalMemOpType. Related to [#146673](https://github.com/llvm/llvm-project/pull/146673).
2025-07-08[DAG] Add generic expansion for ISD::FCANONICALIZE nodes (#142105)Dominik Steenken1-0/+2
This PR takes the work previously done by @pawan-nirpal-031 on X86 in #106370, and makes it available in common code. This should enable all targets to use `__builtin_canonicalize` for all `f(16|32|64|128)` data types. Canonicalization is implemented here as multiplication by `1.0`, as suggested in [the docs](https://llvm.org/docs/LangRef.html#llvm-canonicalize-intrinsic).
2025-07-07DAG: Remove verifyReturnAddressArgumentIsConstant (#147240)Matt Arsenault1-3/+0
The intrinsic argument is already marked with immarg so non-constant values are rejected by the IR verifier.
2025-06-23CodeGen: Emit error if getRegisterByName fails (#145194)Matt Arsenault1-10/+7
This avoids using report_fatal_error and standardizes the error message in a subset of the error conditions.
2025-05-14[MIPS]Fix QNaNs in the MIPS legacy NaN encodings (#139829)anbbna1-0/+29
The MSB of the mantissa should be zero for QNaNs in the MIPS legacy NaN encodings, and one for sNaNs. Fix #100495
2025-05-09MIPSr6: Set FMAXNUM and FMINNUM as Legal (#139009)YunQiang Su1-4/+4
Now we define FMAXNUM and FMINNUM as IEEE754-2008 with +0.0>-0.0. MIPSr6's fmax/fmin just follow this rules full. FMAXNUM_IEEE and FMINNUM_IEEE will be removed in future once: 1. Fixes FMAXNUM/FMINNUM for all targets 2. The use of FMAXNUM_IEEE/FMINNUM_IEEE are not used by middle end anymore.
2025-05-07[MIPS]Remove unnecessary SLL instructions on MIPS64el (#109386)anbbna1-1/+35
Optimize ((signext (xor (trunc X), imm)) to (xor (X, imm)). Fix https://github.com/llvm/llvm-project/issues/99783
2025-04-16[Mips] Fix clang crashes when compiling a variadic function while targeting ↵yingopq1-2/+1
mips3 (#130558) issue reason: Because mips3 has the feature 'FeatureGP64Bit', when target mips3 process function `writeVarArgRegs`, the result of `getGPRSizeInBytes` is 8 and the result of `GetVarArgRegs` is `Mips::A0, Mips::A1, Mips::A2, Mips::A3`. This would generate `gpr64 = COPY $a1` which should be `gpr64 = COPY $a1_64`. Also when process `CC_Mips_FixedArg`, mips would CCDelegateTo `CC_MipsO32_FP`. In fact, it should CCDelegateTo `CC_MipsN`. Fix #98716.
2025-03-28MIPS: Support isLegalICmpImmediate and isLegalAddImmediate (#133400)YunQiang Su1-0/+8
Set it to true only if isInt<16>. By default implemention defines them to true always. For most cases, MIPS uses 16bit IMM, and for microMIPS, ICMP and ADDiu have 16bit IMM flavors.
2025-03-02Move MIPS-specific GPRel32Directive and EK_GPRel32BlockAddress from generic ↵Fangrui Song1-4/+10
code to Mips/ Follow-up to 60486292b79885b7800b082754153202bef5b1f0 gprel/gprel64 functions can now be moved from MCTargetStreamer to MipsTargetStreamer.
2025-02-18[Mips] Support llvm.readcyclecounter intrinsic (#127553)yingopq1-0/+44
The llvm.readcyclecounter intrinsic can be implemented via the `rdhwr $2, $hwr_cc` instruction. $hwr_cc: High-resolution cycle counter. This register provides read access to the coprocessor 0 Count Register. Fix #106318.
2025-02-11Revert "[Mips] Support llvm.readcyclecounter intrinsic (#114953)"YunQiang Su1-44/+0
This reverts commit 9cc7ee16e3bb849fb3c0155a843bfe349a2d2175.
2025-02-11[Mips] Support llvm.readcyclecounter intrinsic (#114953)yingopq1-0/+44
The llvm.readcyclecounter intrinsic can be implemented via the `rdhwr $3, $hwr_cc` instruction. $hwr_cc: High-resolution cycle counter. This register provides read access to the coprocessor 0 Count Register. Fix #106318.
2025-02-06[Mips] Use getSignedConstant() in or combineNikita Popov1-1/+1
Fixes https://github.com/llvm/llvm-project/issues/125954.
2025-01-31[LegalizeDAG] Use Base+Offset instead of Offset+Base for jump tablesAlexander Richardson1-6/+13
This is needed for architectures that actually use strict pointer arithmetic instead of integers such as AArch64 with FEAT_CPA (see https://github.com/llvm/llvm-project/pull/105669) or CHERI. Using an index as the first operand of pointer arithmetic may result in an invalid output. While there are quite a few codegen changes here, these only change the order of registers in add instructions. One MIPS combine had to be updated to handle the new node order. Reviewed By: topperc Pull Request: https://github.com/llvm/llvm-project/pull/125279
2025-01-21[Mips] Handle declspec(dllimport) on mipsel-windows-* triples (#120912)Hervé Poussineau1-1/+16
On Windows, imported symbols must be searched with '__imp_' prefix. Support imported global variables and imported functions.
2025-01-20[Mips] Fix compiler crash when returning fp128 after calling a functi… ↵yingopq1-2/+2
(#117525) …on returning { i8, i128 } Fixes https://github.com/llvm/llvm-project/issues/96432.
2024-12-09[Mips] Fix result type of MAdd/MSub nodes (#117455)Sergei Barannikov1-2/+1
They have one "untyped" result in `MipsInstrInfo.td`, and this type is used in DAG patterns.
2024-12-03[TargetLowering] Use Type* instead of EVT in shouldSignExtendTypeInLibCall. ↵Craig Topper1-3/+3
(#118587) I want to use this function for GISel too so Type * is a better common interface. All of the callers already convert EVT to Type * as needed by calling lowering anyway.
2024-11-18[Mips] Use getSignedConstant() for signed values (#116405)Nikita Popov1-7/+7
This also adds a getSignedTargetConstant() helper, as these seem to be fairly common in general.
2024-11-16[Mips] Remove unused includes (NFC) (#116499)Kazu Hirata1-2/+0
Identified with misc-include-cleaner.
2024-09-24[MIPS] Fix failing to legalize load+call with vector of non-p2 integer (#109625)yingopq1-1/+1
Add a condition to check whether the vector element type is a power of 2. Fixes #102870.
2024-09-13[Mips] Optimize `or (and $src1, mask), (shl $src2, shift)` to `ins` (#103017)yingopq1-18/+61
Optimize `$dst = or (and $src1, (2**size0 - 1)), (shl $src2, size0)` to `ins $src1, $src2, pos, size`, where `pos = size0, size = 32 - pos`. Fix #90325
2024-09-11MIPSr6: Add llvm.is.fpclasss intrinsic support (#107857)YunQiang Su1-2/+3
MIPSr6 has class.s/class.d instructions. Let's use them for llvm.is.fpclass intrinsic.
2024-08-27MIPS: Add fcanonicalize for pre-R6 (#104554)YunQiang Su1-0/+19
MIPSr6 has max.s/max.d/min.s/min.d instructions, which can be used as fcanonicalize. For pre-R6, we have no instructions that can fcanonicalize an float, so let's use `fadd Y,X,X` to quiet it if it is NaN. IEEE754-2008 requires that the result of general-computational and quiet-computational operation shouldn't be signal NaN.
2024-08-26[CodeGen] Use MCRegister for CCState::AllocateReg and CCValAssign::getReg. ↵Craig Topper1-1/+1
NFC (#106032)
2024-07-20Reapply "[LLVM][LTO] Factor out RTLib calls and allow them to be dropped ↵Joseph Huber1-1/+1
(#98512)" This reverts commit 740161a9b98c9920dedf1852b5f1c94d0a683af5. I moved the `ISD` dependencies into the CodeGen portion of the handling, it's a little awkward but it's the easiest solution I can think of for now.
2024-07-20Revert "[LLVM][LTO] Factor out RTLib calls and allow them to be dropped ↵NAKAMURA Takumi1-1/+1
(#98512)" This reverts commit c05126bdfc3b02daa37d11056fa43db1a6cdef69. (llvmorg-19-init-17714-gc05126bdfc3b) See #99610
2024-07-17[AArch64] Don't tail call memset if it would convert to a bzero. (#98969)Amara Emerson1-1/+1
Well, not quite that simple. We can tc memset since it returns the first argument but bzero doesn't do that and therefore we can end up miscompiling. This patch also refactors the logic out of isInTailCallPosition() into the callers. As a result memcpy and memmove are also modified to do the same thing for consistency. rdar://131419786
2024-07-16[LLVM][LTO] Factor out RTLib calls and allow them to be dropped (#98512)Joseph Huber1-1/+1
Summary: The LTO pass and LLD linker have logic in them that forces extraction and prevent internalization of needed runtime calls. However, these currently take all RTLibcalls into account, even if the target does not support them. The target opts-out of a libcall if it sets its name to nullptr. This patch pulls this logic out into a class in the header so that LTO / lld can use it to determine if a symbol actually needs to be kept. This is important for targets like AMDGPU that want to be able to use `lld` to perform the final link step, but does not want the overhead of uncalled functions. (This adds like a second to the link time trivially)
2024-07-11[LLVM] Factor disabled Libcalls into the initializer (#98421)Joseph Huber1-10/+0
Summary: These Libcalls represent which functions are available to the backend. If a runtime call is not available, the target sets the the name to `nullptr`. Currently, this logic is spread around the various targets. This patch pulls all of the locations that disable libcalls into the intializer. This patch is effectively NFC. The motivation behind this patch is that currently the LTO handling uses the list of all runtime calls to determine which functions cannot be internalized and must be extracted from static libraries. We do not want this to happen for libcalls that are not emitted by the backend. A follow-up patch will move out this logic so the LTO pass can know which rtlib calls are actually used by the backend.
2024-06-28[IR] Don't include Module.h in Analysis.h (NFC) (#97023)Nikita Popov1-0/+1
Replace it with a forward declaration instead. Analysis.h is pulled in by all passes, but not all passes need to access the module.
2024-05-23MIPS: Fix llvm.{min,max}num for R6 (#93125)YunQiang Su1-5/+9
MIPS max.fmt/min.fmt instructions is IEEE2008 compatiable. If either argument is sNaN, the result will be NaN. So we define fminnum_ieee instead of fminnum in Mips32r6InstrInfo.td. We also should define fcanonicalize. So that we can define fminnum as expand to fcanonicalize and fminnum_ieee.
2024-05-16[llvm] Drop explicit conversions of string literals to StringRef (NFC)Kazu Hirata1-2/+1
We routinely rely on implicit conversions of string literals to StringRef so that we can use operator==(StringRef, StringRef).
2024-04-27[MIPS] match llvm.{min,max}num with {min,max}.fmt for R6 (#89021)Cinhi Young1-0/+9
- The behavior is similar to UCOMISD on x86, which is also used to compare two fp values, specifically on handling of NaNs. - Update related tests regarding this change. - The further goal is to implement `llvm.minimum` and `llvm.maximum` intrinsics for MIPS R6 and Pre-R6. Part of https://github.com/llvm/llvm-project/issues/64207
2024-04-02[CallSiteInfo][NFC] CallSiteInfo -> CallSiteInfo.ArgRegPairs (#86842)Prabhuk1-1/+1
CallSiteInfo is originally used only for argument - register pairs. Make it struct, in which we can store additional data for call sites. Also, the variables/methods used for CallSiteInfo are named for its original use case, e.g., CallFwdRegsInfo. Refactor these for the upcoming use, e.g. addCallArgsForwardingRegs() -> addCallSiteInfo(). An upcoming patch will add type ids for indirect calls to propogate them from middle-end to the back-end. The type ids will be then used to emit the call graph section. Original RFC: https://lists.llvm.org/pipermail/llvm-dev/2021-June/151044.html Updated RFC: https://lists.llvm.org/pipermail/llvm-dev/2021-July/151739.html Differential Revision: https://reviews.llvm.org/D107109?id=362888 Co-authored-by: Necip Fazil Yildiran <necip@google.com>
2024-04-02[MIPS][CallSiteInfo][NFC] Fill CallSiteInfo only when needed (#86847)Prabhuk1-1/+1
Argument-register pairs in CallSiteInfo is only needed when EmitCallSiteInfo is on. Currently, the pairs are always pushed to the vector but only used when EmitCallSiteInfo is on. Don't fill the CallSiteInfo vector unless used. Differential Revision: https://reviews.llvm.org/D107108?id=362887 Co-authored-by: Necip Fazil Yildiran <necip@google.com>
2024-03-20MIPS: Support -m(no-)unaligned-access for r6 (#85174)YunQiang Su1-3/+13
MIPSr6 ISA requires normal load/store instructions support misunaligned memory access, while it is not always do so by hardware. On some microarchitectures or some corner cases it may need support by OS. Don't confuse with pre-R6's lwl/lwr famlily: MIPSr6 doesn't support them, instead, r6 requires lw instruction support misunaligned memory access. So, if -mstrict-align is used for pre-R6, lwl/lwr won't be disabled. If -mstrict-align is used for r6 and the access is not well aligned, some lb/lh instructions will be used to replace lw. This is useful for OS kernels. To be back-compatible with GCC, -m(no-)unaligned-access are also added as Neg-Alias of -m(no-)strict-align.
2024-03-13[llvm][Mips] Use a Target ISD opcode for PseudoD_SELECT (#84294)Roger Ferrer Ibáñez1-2/+4
The Mips target uses two TargetOpcode enumerators called `PseudoD_SELECT_I` and `PseudoD_SELECT_I64`. A SDAG node is created using these enumerators which is manually selected in `MipsSEISelDAGToDAG.cpp` and ultimately expanded in `EmitInstrWithCustomInserter` in `MipsISelLowering.cpp`. This is not causing any upstream build to fail at the moment but it is not guaranteed that these enumerators do not clash with Target ISD nodes (i.e. those in the `MipsISD` namespace). We have seen this happening in our downstream builds in which `Mips::PseudoD_SELECT_I` ends having the same integer value as `MipsISD::VEXTRACT_ZEXT_ELT`. This confuses the function `trySelect` in `MipsSEISelDAGToDAG.cpp` and causes a crash in 3 tests. This change adds a new Target ISD opcode for these two cases and uses them for the SDAG nodes. No test is included because this is a potential error in the future not one that can be demonstrated in the current codebase.
2024-02-26MIPS: Fix asm constraints "f" and "r" for softfloat (#79116)YunQiang Su1-3/+7
This include 2 fixes: 1. Disallow 'f' for softfloat. 2. Allow 'r' for softfloat. Currently, 'f' is accpeted by clang, then LLVM meets an internal error. 'r' is rejected by LLVM by: couldn't allocate input reg for constraint 'r'. Fixes: #64241, #63632 --------- Co-authored-by: Fangrui Song <i@maskray.me>
2024-01-25[llvm] Move CodeGenTypes library to its own directory (#79444)Nico Weber1-1/+1
Finally addresses https://reviews.llvm.org/D148769#4311232 :) No behavior change.
2024-01-09[RFC][SelectionDAG] Add and use SDNode::getAsZExtVal() helper (#76710)Alex Bradbury1-2/+1
This follows on from #76708, allowing `cast<ConstantSDNode>(N)->getZExtValue()` to be replaced with just `N->getAsZextVal();` Introduced via `git grep -l "cast<ConstantSDNode>\(.*\).*getZExtValue" | xargs sed -E -i 's/cast<ConstantSDNode>\((.*)\)->getZExtValue/\1->getAsZExtVal/'` and then using `git clang-format` on the result.
2024-01-02[llvm][NFC] Use SDValue::getConstantOperandVal(i) where possible (#76708)Alex Bradbury1-2/+2
This helper function shortens examples like `cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();` to `Node->getConstantOperandVal(1);`. Implemented with: `git grep -l "cast<ConstantSDNode>\(.*->getOperand\(.*\)\)->getZExtValue\(\)" | xargs sed -E -i 's/cast<ConstantSDNode>\((.*)->getOperand\((.*)\)\)->getZExtValue\(\)/\1->getConstantOperandVal(\2)/` and `git grep -l "cast<ConstantSDNode>\(.*\.getOperand\(.*\)\)->getZExtValue\(\)" | xargs sed -E -i 's/cast<ConstantSDNode>\((.*)\.getOperand\((.*)\)\)->getZExtValue\(\)/\1.getConstantOperandVal(\2)/'`. With a couple of simple manual fixes needed. Result then processed by `git clang-format`.
2023-12-11[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)Kazu Hirata1-1/+1
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-11-03[Mips] In LowerShift*Parts, xor with bits-1 instead of -1. (#71149)Craig Topper1-6/+8
If we start with an i128 shift, the initial shift amount would usually have zeros in bit 8 and above. xoring the shift amount with -1 will set those upper bits to 1. If DAGCombiner is able to prove those bits are now 1, then the shift that uses the xor will be replaced with undef. Which we don't want. Reduce the xor constant to VT.bits-1 where VT is half the size of the larger shift type. This avoids toggling the upper bits. The hardware shift instruction only uses the lower bits of the shift amount. I assume the code used NOT because the hardware doesn't use the upper bits, but that isn't compatible with the LLVM poison semantics. Fixes #71142.
2023-10-25[Mips][GISel] Fix a couple issues with passing f64 in 32-bit GPRs. (#69131)Craig Topper1-11/+2
MipsIncomingValueHandler::assignCustomValue should return 1 instead of 2. The return value is the number of additional ArgLocs being consumed. It's assumed that at least 1 is consumed. Correct the LocVT used for the spill when there are no registers left. It should be f64 instead of i32. This allows a workaround to be removed in the SelectionDAG path.
2023-09-25[TargetLowering] Deduplicate choosing InlineAsm constraint between ISels ↵Nick Desaulniers1-4/+5
(#67057) Given a list of constraints for InlineAsm (ex. "imr") I'm looking to modify the order in which they are chosen. Before doing so, I noticed a fair amount of logic is duplicated between SelectionDAGISel and GlobalISel for this. That is because SelectionDAGISel is also trying to lower immediates during selection. If we detangle these concerns into: 1. choose the preferred constraint 2. attempt to lower that constraint Then we can slide down the list of constraints until we find one that can be lowered. That allows the implementation to be shared between instruction selection frameworks. This makes it so that later I might only need to adjust the priority of constraints in one place, and have both selectors behave the same.
2023-07-24[Mips] Fix argument lowering for illegal vector types (PR63608)Nikita Popov1-12/+20
The Mips MSA ABI requires that legal vector types are passed in scalar registers in packed representation. E.g. a type like v16i8 would be passed as two i64 registers. The implementation attempts to do the same for illegal vectors with non-power-of-two element counts or non-power-of-two element types. However, the SDAG argument lowering code doesn't support this, and it is not easy to extend it to support this (we would have to deal with situations like passing v7i18 as two i64 values). This patch instead opts to restrict the special argument lowering to only vectors with power-of-two elements and round element types. Everything else is lowered naively, that is by passing each element in promoted registers. Fixes https://github.com/llvm/llvm-project/issues/63608. Differential Revision: https://reviews.llvm.org/D154445