aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
AgeCommit message (Collapse)AuthorFilesLines
22 hours[TargetLowering] Remove NoSignedZerosFPMath uses (#160975)paperchalice1-7/+5
Remove NoSignedZerosFPMath in TargetLowering part, users should always use instruction level fast math flags.
4 days[SelectionDAG] Improve v2f16 maximumnum expansion (#160723)Lewis Crawford1-1/+3
On targets where f32 maximumnum is legal, but maximumnum on vectors of smaller types is not legal (e.g. v2f16), try unrolling the vector first as part of the expansion. Only fall back to expanding the full maximumnum computation into compares + selects if maximumnum on the scalar element type cannot be supported.
5 days[TargetLowering][ExpandABD] Prefer selects over usubo if we do the same for ↵AZero131-6/+8
ucmp (#159889) Same deal we use for determining ucmp vs scmp. Using selects on platforms that like selects is better than using usubo. Rename function to be more general fitting this new description.
10 days[KnownBits] Add setAllConflict to set all bits in Zero and One. NFC (#159815)Craig Topper1-6/+3
This is a common pattern to initialize Knownbits that occurs before loops that call intersectWith.
11 days[AMDGPU][SDAG] Handle ISD::PTRADD in various special cases (#145330)Fabian Ritter1-4/+15
There are more places in SIISelLowering.cpp and AMDGPUISelDAGToDAG.cpp that check for ISD::ADD in a pointer context, but as far as I can tell those are only relevant for 32-bit pointer arithmetic (like frame indices/scratch addresses and LDS), for which we don't enable PTRADD generation yet. For SWDEV-516125.
12 days[SelectionDAG] Deal with POISON for INSERT_VECTOR_ELT/INSERT_SUBVECTOR (#143102)Björn Pettersson1-2/+6
As reported in https://github.com/llvm/llvm-project/issues/141034 SelectionDAG::getNode had some unexpected behaviors when trying to create vectors with UNDEF elements. Since we treat both UNDEF and POISON as undefined (when using isUndef()) we can't just fold away INSERT_VECTOR_ELT/INSERT_SUBVECTOR based on isUndef(), as that could make the resulting vector more poisonous. Same kind of bug existed in DAGCombiner::visitINSERT_SUBVECTOR. Here are some examples: This fold was done even if vec[idx] was POISON: INSERT_VECTOR_ELT vec, UNDEF, idx -> vec This fold was done even if any of vec[idx..idx+size] was POISON: INSERT_SUBVECTOR vec, UNDEF, idx -> vec This fold was done even if the elements not extracted from vec could be POISON: sub = EXTRACT_SUBVECTOR vec, idx INSERT_SUBVECTOR UNDEF, sub, idx -> vec With this patch we avoid such folds unless we can prove that the result isn't more poisonous when eliminating the insert. Fixes https://github.com/llvm/llvm-project/issues/141034
2025-09-05[SelectionDAG] Clean up SCALAR_TO_VECTOR handling in ↵Björn Pettersson1-21/+0
SimplifyDemandedVectorElts (#157027) This patch reverts changes from commit 585e65d3307f5f0 (https://reviews.llvm.org/D104250), as it doesn't seem to be needed nowadays. The removed code was doing a recursive call to SimplifyDemandedVectorElts trying to simplify the vector %vec when finding things like (SCALAR_TO_VECTOR (EXTRACT_VECTOR_ELT %vec, 0)) I figure that (EXTRACT_VECTOR_ELT %vec, 0) would be simplified based on only demanding element zero regardless of being used in a SCALAR_TO_VECTOR operation or not. It had been different if the code tried to simplify the whole expression as %vec. That could also have motivate why to make element zero a special case. But it only simplified %vec without folding away the SCALAR_TO_VECTOR.
2025-08-31[SelectionDAG] Return std::optional<unsigned> from getValidShiftAmount and ↵Craig Topper1-14/+14
friends. NFC (#156224) Instead of std::optional<uint64_t>. Shift amounts must be less than or equal to our maximum supported bit widths which fit in unsigned. Most of the callers already assumed it fit in unsigned.
2025-08-31[TargetLowering] Only freeze LHS and RHS if they are used multiple times in ↵AZero131-10/+13
expandABD (#156193) Not all paths in expandABD are using LHS and RHS twice.
2025-08-28[ValueTracking][SelectionDAG] Use KnownBits::reverseBits/byteSwap. NFC (#155847)Craig Topper1-4/+2
2025-08-28[KnownBits] Add operator<<=(unsigned) and operator>>=(unsigned). NFC (#155751)Craig Topper1-10/+5
Add operators to shift left or right and insert unknown bits.
2025-08-18[CodeGen][Mips] Remove fp128 libcall list (#153798)Nikita Popov1-4/+11
Mips requires fp128 args/returns to be passed differently than i128. It handles this by inspecting the pre-legalization type. However, for soft float libcalls, the original type is currently not provided (it will look like a i128 call). To work around that, MIPS maintains a list of libcalls working on fp128. This patch removes that list by providing the original, pre-softening type to calling convention lowering. This is done by carrying additional information in CallLoweringInfo, as we unfortunately do need both types (we want the un-softened type for OrigTy, but we need the softened type for the actual register assignment etc.) This is in preparation for completely removing all the custom pre-analysis code in the Mips backend and replacing it with use of OrigTy.
2025-08-15[CodeGen] Give ArgListEntry a proper constructor (NFC) (#153817)Nikita Popov1-8/+4
This ensures that the required fields are set, and also makes the construction more convenient.
2025-08-14[CodeGen] Remove unnecessary setTypeListBeforeSoften() parameter (NFC)Nikita Popov1-1/+1
It does not make sense to set the softening type list without setting IsSoften=true.
2025-08-10[DAGCombine] Correctly extend the constant RHS in ↵Yingwei Zheng1-4/+5
`TargetLowering::SimplifySetCC` (#152862) In https://github.com/llvm/llvm-project/pull/150270, when the predicate is eq/ne and the trunc has only an nsw flag, the RHS is incorrectly zero-extended. Closes https://github.com/llvm/llvm-project/issues/152630.
2025-08-05[DAGCombiner] Fold setcc of trunc, generalizing some NVPTX isel logic (#150270)Alex MacLean1-0/+25
That change adds support for folding a SETCC when one or both of the operands is a TRUNCATE with the appropriate no-wrap flags. This pattern can occur when promoting i8 operations in NVPTX, and we currently have some ISel rules to try to handle it.
2025-08-05[DAG] visitFREEZE - replace multiple frozen/unfrozen uses of an SDValue with ↵Simon Pilgrim1-7/+0
just the frozen node (#150017) Similar to InstCombinerImpl::freezeOtherUses, attempt to ensure that we merge multiple frozen/unfrozen uses of a SDValue. This fixes a number of hasOneUse() problems when trying to push FREEZE nodes through the DAG. Remove SimplifyMultipleUseDemandedBits handling of FREEZE nodes as we now want to keep the common node, and not bypass for some nodes just because of DemandedElts. Fixes #149799
2025-08-04[TargetLowering][RISCV] Use sra for (X & -256) == 256 -> (X >> 8) == 1 if it ↵Craig Topper1-1/+16
yields a better icmp constant. (#151762) If using srl does not produce a legal constant for the RHS of the final compare, try to use sra instead. Because the AND constant is negative, the sign bits participate in the compare. Using an arithmetic shift right duplicates that bit.
2025-08-02[TargetLowering] Use getShiftAmountConstant in buildSDIVPow2WithCMov.Craig Topper1-2/+2
2025-07-29[TargetLowering] Use getShiftAmountConstant in CTTZTableLookup. NFCCraig Topper1-1/+1
2025-07-22[DAG] expandVECTOR_COMPRESS - remove superfluous getFreeze. NFC. (#150062)Simon Pilgrim1-2/+1
freeze(freeze(extract_vector_elt(x,i))) -> freeze(extract_vector_elt(x,i))
2025-07-22[SelectionDAG] Pass SDNodeFlags through getNode instead of setFlags. (#149852)Craig Topper1-3/+2
getNode updates flags correctly for CSE. Calling setFlags after getNode may set the flags where they don't apply. I've added a Flags argument to getSelectCC and the signature of getNode that takes an ArrayRef of EVTs.
2025-07-22[DAG] isNonZeroModBitWidthOrUndef - fix bugprone-argument-comment analyzer ↵Simon Pilgrim1-1/+1
warning. NFC. matchUnaryPredicate argument is AllowUndefs not AllowUndef
2025-07-20[DAG] Add missing Depth argument to isGuaranteedNotToBeUndefOrPoison calls ↵Simon Pilgrim1-2/+3
inside SimplifyDemanded methods (#149550) Ensure we don't exceed the maximum recursion depth
2025-07-11[NFC] Correct typo: invertion -> inversion (#147995)Fraser Cormack1-4/+4
2025-07-10[TargetLowering] Change getOptimalMemOpType and findOptimalMemOpLowering to ↵Boyao Wang1-3/+4
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-09RuntimeLibcalls: Remove table of soft float compare cond codes (#146082)Matt Arsenault1-2/+14
Previously we had a table of entries for every Libcall for the comparison to use against an integer 0 if it was a soft float compare function. This was only relevant to a handful of opcodes, so it was wasteful. Now that we can distinguish the abstract libcall for the compare with the concrete implementation, we can just directly hardcode the comparison against the libcall impl without this configuration system.
2025-07-07DAG: Remove verifyReturnAddressArgumentIsConstant (#147240)Matt Arsenault1-11/+0
The intrinsic argument is already marked with immarg so non-constant values are rejected by the IR verifier.
2025-07-07[TargetLowering] hasAndNotCompare should be checking for X, not Y (#146935)AZero131-1/+1
Y is the one being bitwise-not, so it should not be passed, as the other one should be passed instead.
2025-06-27[TargetLowering] Fold (a | b) ==/!= b -> (a & ~b) ==/!= 0 when and-not ↵AZero131-0/+41
exists (#145368) This is especially helpful for AArch64, which simplifies ands + cmp to tst. Alive2: https://alive2.llvm.org/ce/z/LLgcJJ --------- Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-06-27DAG: Check libcall function is supported before emission (#144314)Matt Arsenault1-4/+6
2025-06-25[SelectionDAG] Fold undemanded operand to UNDEF for VECTOR_SHUFFLE (#145524)Björn Pettersson1-0/+13
Always let SimplifyDemandedVectorElts fold either side of a VECTOR_SHUFFLE to UNDEF if no elements are demanded from that side. For a single use this could be done by SimplifyDemandedVectorElts already, but in case the operand had multiple uses we did not eliminate the use.
2025-06-22[SelectionDAG] Handle `fneg`/`fabs`/`fcopysign` in `SimplifyDemandedBits` ↵Iris Shi1-0/+71
(#139239)
2025-06-20[LLVM][CodeGen][SVE] Add isel for bfloat unordered reductions. (#143540)Paul Walker1-5/+10
The omissions are VECREDUCE_SEQ_* and MUL. The former goes down a different code path and the latter is unsupported across all element types.
2025-06-17DAG: Move soft float predicate management into RuntimeLibcalls (#142905)Matt Arsenault1-2/+3
Work towards making RuntimeLibcalls the centralized location for all libcall information. This requires changing the encoding from tracking the ISD::CondCode to using CmpInst::Predicate.
2025-06-10DAG: Assert fcmp uno runtime calls are boolean values (#142898)Matt Arsenault1-0/+8
This saves 2 instructions in the ARM soft float case for fcmp ueq. This code is written in an confusingly overly general way. The point of getCmpLibcallCC is to express that the compiler-rt implementations of the FP compares are different aliases around functions which may return -1 in some cases. This does not apply to the call for unordered, which returns a normal boolean. Also stop overriding the default value for the unordered compare for ARM. This was setting it to the same value as the default, which is now assumed.
2025-06-09[SDAG] Add partial_reduce_sumla node (#141267)Philip Reames1-5/+9
We have recently added the partial_reduce_smla and partial_reduce_umla nodes to represent Acc += ext(b) * ext(b) where the two extends have to have the same source type, and have the same extend kind. For riscv64 w/zvqdotq, we have the vqdot and vqdotu instructions which correspond to the existing nodes, but we also have vqdotsu which represents the case where the two extends are sign and zero respective (i.e. not the same type of extend). This patch adds a partial_reduce_sumla node which has sign extension for A, and zero extension for B. The addition is somewhat mechanical.
2025-06-04Revert "[SDAG] Fix fmaximum legalization errors (#142170)"Nikita Popov1-10/+8
This reverts commit 58cc1675ec7b4aa5bc2dab56180cb7af1b23ade5. I also made the incorrect assumption that we know both values are +/-0.0 here as well. Revert for now.
2025-06-04Revert "[SelectionDAG] Avoid one comparison when legalizing fmaximum (#142732)"Nikita Popov1-8/+11
This reverts commit 54da543a14da6dd0e594875241494949cb659b08. I made a logic error here with the assumption that both values are known to be +/-0.0.
2025-06-04[SelectionDAG] Avoid one comparison when legalizing fmaximum (#142732)Nikita Popov1-11/+8
When ordering signed zero, only check the sign of one of the values. We already know at this point that both values must be +/-0.0, so it is sufficient to check one of them to correctly order them. For example, for fmaximum, if we know LHS is `+0.0` then we can always select LHS, value of RHS does not matter. If LHS is `-0.0` we can always select RHS, value of RHS doesn't matter.
2025-06-04expandFMINIMUMNUM_FMAXIMUMNUM: Quiet is not needed for NaN vs NaN (#139237)YunQiang Su1-5/+2
New LangRef doesn't requires quieting for NaN vs NaN, aka the result may be sNaN for sNaN vs NaN. See: https://github.com/llvm/llvm-project/pull/139228
2025-06-02[SDAG] Fix fmaximum legalization errors (#142170)Nikita Popov1-8/+10
FMAXIMUM is currently legalized via IS_FPCLASS for the signed zero handling. This is problematic, because it assumes the equivalent integer type is legal. Many targets have legal fp128, but illegal i128, so this results in legalization failures. Fix this by replacing IS_FPCLASS with checking the bitcast to integer instead. In that case it is sufficient to use any legal integer type, as we're just interested in the sign bit. This can be obtained via a stack temporary cast. There is existing FloatSignAsInt functionality used for legalization of FABS and similar we can use for this purpose. Fixes https://github.com/llvm/llvm-project/issues/139380. Fixes https://github.com/llvm/llvm-project/issues/139381. Fixes https://github.com/llvm/llvm-project/issues/140445.
2025-05-23[GISel] Add KnownFPClass Analysis to GISelValueTrackingPass (#134611)Tim Gymnich1-0/+7
- add KnownFPClass analysis to GISelValueTrackingPass - add MI pattern for `m_GIsFPClass`
2025-05-21[TargetLowering] Use getExtractSubvector/getExtractVectorElt. NFCCraig Topper1-14/+7
2025-05-19[APInt] Added APInt::clearBits() method (#137098)Liam Semeria1-2/+2
Added APInt::clearBits(unsigned loBit, unsigned hiBit) that clears bits within a certain range. Fixes #136550 --------- Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-05-16[SelectionDAG] Rename MemSDNode::getOriginalAlign to getBaseAlign. NFC (#139930)Craig Topper1-24/+20
This matches the underlying function in MachineMemOperand and how it is printed when BaseAlign differs from Align.
2025-05-15[llvm] Use llvm::stable_sort (NFC) (#140067)Kazu Hirata1-4/+3
2025-05-13DAG: Stop forcibly adding nsz to expanded minnum/maxnum (#139615)Matt Arsenault1-3/+1
2025-05-12[SelectionDAG] Fix incorrect fold condition in foldSetCCWithFunnelShift. ↵Rux1241-2/+5
(#137637) Proposed by [2ed1598](https://github.com/llvm/llvm-project/commit/2ed15984b49a1af87be37ec8bd6ee3ab7f724767): `fshl X, (or X, Y), C ==/!= 0 --> or (srl Y, BW-C), X ==/!= 0` This transformation is valid when (C%Bitwidth) != 0 , as verified by [Alive2](https://alive2.llvm.org/ce/z/TQYM-m). Fixes #136746
2025-05-04[llvm] Remove unused local variables (NFC) (#138467)Kazu Hirata1-1/+0