aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
AgeCommit message (Collapse)AuthorFilesLines
2 days[SDAG] Constant fold frexp in signed way (#161015)Hongyu Chen1-2/+2
Fixes #160981 The exponential part of a floating-point number is signed. This patch prevents treating it as unsigned.
8 days[DAG] Add ISD::VECTOR_COMPRESS handling in ↵Kavin Gnanapandithan1-0/+22
computeKnownBits/ComputeNumSignBits (#159692) Resolves #158332
10 days[KnownBits] Add setAllConflict to set all bits in Zero and One. NFC (#159815)Craig Topper1-10/+7
This is a common pattern to initialize Knownbits that occurs before loops that call intersectWith.
11 days[PowerPC] using milicode call for strlen instead of lib call (#153600)zhijian lin1-0/+27
AIX has "millicode" routines, which are functions loaded at boot time into fixed addresses in kernel memory. This allows them to be customized for the processor. The __strlen routine is a millicode implementation; we use millicode for the strlen function instead of a library call to improve performance.
11 days[AMDGPU][SDAG] Handle ISD::PTRADD in various special cases (#145330)Fabian Ritter1-1/+1
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-10/+73
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
13 days[DAG] getNode() - reuse result type instead of calling getValueType again. ↵Simon Pilgrim1-2/+2
NFC. (#159381) We have assertions above confirming VT == N1.getValueType() for INSERT_VECTOR_ELT nodes.
14 days[NFC ]Add a helper function isTailCall for getting libcall in SelectionDAG ↵zhijian lin1-12/+16
(#155256) Based on comment of https://github.com/llvm/llvm-project/pull/153600#discussion_r2285729269, Add a helper function isTailCall for getting libcall in SelectionDAG.
2025-09-05[DAG] SelectionDAG::canCreateUndefOrPoison - AVGFLOOR/AVGCEIL don't create ↵Simon Pilgrim1-0/+4
undef/poison (#157056) AVGFLOORS: https://alive2.llvm.org/ce/z/6TdoQ_ AVGFLOORU: https://alive2.llvm.org/ce/z/4pfi4i AVGCEILS: https://alive2.llvm.org/ce/z/nWu8WM AVGCEILU: https://alive2.llvm.org/ce/z/CGvWiA Fixes #147696
2025-08-31[SelectionDAG] Return std::optional<unsigned> from getValidShiftAmount and ↵Craig Topper1-13/+13
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-30[SelectionDAG] Add computeKnownBits for ISD::ROTL/ROTR. (#156142)Craig Topper1-0/+16
2025-08-28[KnownBits] Add operator<<=(unsigned) and operator>>=(unsigned). NFC (#155751)Craig Topper1-8/+4
Add operators to shift left or right and insert unknown bits.
2025-08-26[DAG] ComputeNumSignBits - ISD::EXTRACT_ELEMENT needs to return at least 1 ↵Miguel Saldivar1-1/+1
(#155455) When going through the ISD::EXTRACT_ELEMENT case, `KnownSign - rIndex * BitWidth` could produce a negative. When a negative is produced, the lower bound of the `std::clamp` is returned. Change that lower bound to one to avoid potential underflows, because the expectation is that `ComputeNumSignBits` should always return at least 1. Fixes #155452.
2025-08-23[DAG] Constant fold ISD::FSHL/FSHR nodes (#154480)XChy1-27/+52
Fixes #153612. This patch handles trinary scalar integers for FSHL/R in `FoldConstantArithmetic`. Pending until #153790 is merged.
2025-08-20DAG: Add assert to getNode for EXTRACT_SUBVECTOR indexes (#154099)Matt Arsenault1-0/+2
Verify it's a multiple of the result vector element count instead of asserting this in random combines. The testcase in #153808 fails in the wrong point. Add an assert to getNode so the invalid extract asserts at construction instead of use.
2025-08-19[DAG] SelectionDAG::canCreateUndefOrPoison - add ISD::SCMP/UCMP handling + ↵Temperz871-0/+2
tests (#154127) This pr aims to resolve #152144 In SelectionDAG::canCreateUndefOrPoison the ISD::SCMP/UCMP cases are added to always return false as they cannot generate poison or undef The `freeze-binary.ll` file is now testing the SCMP/UCMP cases --------- Co-authored-by: Temperz87 <= temperz871@gmail.com> Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-08-19[DAG] Add ISD::FP_TO_SINT_SAT/FP_TO_UINT_SAT handling to ↵Ye Tian1-0/+2
SelectionDAG::canCreateUndefOrPoison (#154244) Related to https://github.com/llvm/llvm-project/issues/153366
2025-08-15[CodeGen] Give ArgListEntry a proper constructor (NFC) (#153817)Nikita Popov1-84/+31
This ensures that the required fields are set, and also makes the construction more convenient.
2025-08-14[SelectionDAG] Handle more opcodes in isGuaranteedNotToBeUndefOrPoison (#147019)Björn Pettersson1-0/+123
Add special handling of EXTRACT_SUBVECTOR, INSERT_SUBVECTOR, EXTRACT_VECTOR_ELT, INSERT_VECTOR_ELT and SCALAR_TO_VECTOR in isGuaranteedNotToBeUndefOrPoison. Make use of DemandedElts to improve the analysis and only check relevant elements for each operand. Also start using DemandedElts in the recursive calls that check isGuaranteedNotToBeUndefOrPoison for all operands for operations that do not create undef/poison. We can do that for a number of elementwise operations for which the DemandedElts can be applied to every operand (e.g. ADD, OR, BITREVERSE, TRUNCATE).
2025-08-12[DAG] SelectionDAG::canCreateUndefOrPoison - add ISD::FMA/FMAD + tests (#152187)Seraphimt1-0/+2
In SelectionDAG::canCreateUndefOrPoison add case ISD::FMA/FMAD + tests. Fixing #147693 --------- Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-08-08Revert "[AMDGPU] SelectionDAG divergence tracking should take into account ↵David Stuttard1-14/+4
Target divergency. (#147560)" (#152548) This reverts commit 9293b65a616b8de432a654d046e802540b146372.
2025-08-07[PowerPC][AIX] Using milicode for memcmp instead of libcall (#147093)zhijian lin1-0/+38
AIX has "millicode" routines, which are functions loaded at boot time into fixed addresses in kernel memory. This allows them to be customized for the processor. The __memcmp routine is a millicode implementation; we use millicode for the memcmp function instead of a library call to improve performance.
2025-08-07[DAG] canCreateUndefOrPoison - add FP_EXTEND (#152249)Chaitanya Koparkar1-0/+1
Fixes https://github.com/llvm/llvm-project/issues/152141
2025-08-06[DAG] getNode - fold (sext (trunc x)) -> x iff the upper bits are already ↵Simon Pilgrim1-0/+14
signbits (#151945) Similar to what we already do for ZERO_EXTEND/ANY_EXTEND patterns.
2025-08-05[VP][RISCV] Add a vp.load.ff intrinsic for fault only first load. (#128593)Craig Topper1-0/+36
There's been some interest in supporting early-exit loops recently. https://discourse.llvm.org/t/rfc-supporting-more-early-exit-loops/84690 This patch was extracted from our downstream where we've been using it in our vectorizer.
2025-08-05[DAG] Remove Depth=1 hack from isGuaranteedNotToBeUndefOrPoison checks (#152127)Simon Pilgrim1-2/+1
Now that #146490 removed the assertion in visitFreeze to assert that the node was still isGuaranteedNotToBeUndefOrPoison we no longer need this reduced depth hack (which had to account for the difference in depth of freeze(op()) vs op(freeze()) Helps with some of the minor regressions in #150017
2025-07-31[SelectionDAG] Improve the doxygen description for SDValue::isOperandOf. NFC ↵Craig Topper1-1/+1
(#151244) SDValue::isOperandOf checks the result number in addition to the SDNode*. SDNode::isOperandOf only checks the SDNode*.
2025-07-30[LLVM][SelectionDAG] Align poison/undef binop folds with IR. (#149334)Paul Walker1-20/+61
The "at construction" binop folds in SelectionDAG::getNode() has different behaviour when compared to the equivalent LLVM IR. This PR makes the behaviour consistent while also extending the coverage to include signed/unsigned max/min operations.
2025-07-29[IR][SDAG] Remove lifetime size handling from SDAG (#150944)Nikita Popov1-9/+3
Split out from https://github.com/llvm/llvm-project/pull/150248: Specify that the argument of lifetime.start/lifetime.end is ignored and will be removed in the future. Remove lifetime size handling from SDAG. The size was previously discarded during isel, so was always ignored for stack coloring anyway. Where necessary, obtain the size of the full frame index.
2025-07-22[SelectionDAG] Remove FIXME and commented out code from 20 years ago. NFC ↵Craig Topper1-20/+0
(#150055)
2025-07-22[SelectionDAG] Use SDUse::get() instead of a static_cast to SDValue. NFC ↵Craig Topper1-1/+1
(#150043)
2025-07-22[SelectionDAG] Pass SDNodeFlags through getNode instead of setFlags. (#149852)Craig Topper1-1/+10
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[CodeGen] Remove handling for lifetime.start/end on non-alloca (#149838)Nikita Popov1-8/+4
After https://github.com/llvm/llvm-project/pull/149310 we are guaranteed that the argument is an alloca, so we don't need to look at underlying objects (which was not a correct thing to do anyway). This also drops the offset argument for lifetime nodes in SDAG. The offset is fixed to zero now. (Peculiarly, while SDAG pretended to have an offset, it just gets silently dropped during selection.)
2025-07-21[SelectionDAG] Fix incorrect indentation. NFCCraig Topper1-1/+1
2025-07-18[DAG] Adding abdu/abds to canCreateUndefOrPoison (#149017)Annu Singh1-0/+2
Fixes #147695 - [Alive2 test - freeze abdu](https://alive2.llvm.org/ce/z/aafeJs) - [Alive 2 test - freeze abds](https://alive2.llvm.org/ce/z/XrSmP4) --------- Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-07-18[AMDGPU][SDAG] Add target-specific ISD::PTRADD combines (#143673)Fabian Ritter1-1/+3
This patch adds several (AMDGPU-)target-specific DAG combines for ISD::PTRADD nodes that reproduce existing similar transforms for ISD::ADD nodes. There is no functional change intended for the existing target-specific PTRADD combine. For SWDEV-516125.
2025-07-18Add FABS to canCreateUndefOrPoison (#149440)Shoreshen1-0/+1
FABS will not create undef/poison, add it into canCreateUndefOrPoison return false
2025-07-17[SelectionDAG] Fix copyExtraInfo where new node has entry as operand (#149307)Marco Elver1-1/+8
Add special case handling where a new replacement node has the entry node as an operand i.e. does not depend on any other nodes. This can be observed with the existing X86/pcsections-atomics.ll test case when targeting Haswell, where certain 128-bit atomics are transformed into arch-specific instructions, with some operands having no other dependencies.
2025-07-15[DAG] canCreateUndefOrPoison - add handling for ISD::ABS nodes (#148791)Simon Pilgrim1-0/+5
Unlike the abs intrinsic, the ISD::ABS node defines ABS(INT_MIN) -> INT_MIN, so no undef/poison is created by the node itself
2025-07-14[DAG] SelectionDAG::canCreateUndefOrPoison - add ISD::FCOPYSIGN (#148617)woruyu1-0/+1
### Summary This PR resolves https://github.com/llvm/llvm-project/issues/147694
2025-07-10[DAG] Handle truncated splat in isBoolConstant (#145473)David Green1-5/+6
This allows truncated splat / buildvector in isBoolConstant, to allow certain not instructions to be recognized post-legalization, and allow vselect to optimize. An override for x86 avx512 predicated vectors is required to avoid an infinite recursion from the code that detects zero vectors. From: ``` // Check if the first operand is all zeros and Cond type is vXi1. // If this an avx512 target we can improve the use of zero masking by // swapping the operands and inverting the condition. ```
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-09[AMDGPU] SelectionDAG divergence tracking should take into account Target ↵alex-t1-4/+14
divergency. (#147560) This is the next attempt to upstream this: https://github.com/llvm/llvm-project/pull/144947 The las one caused build errors in AArch64. Issue was resolved.
2025-07-07[DAG] SDPatternMatch m_Zero/m_One/m_AllOnes have inconsistent undef h… ↵woruyu1-0/+12
(#147044) ### Summary This PR resolves https://github.com/llvm/llvm-project/issues/146871 This PR resolves https://github.com/llvm/llvm-project/issues/140745 Refactor m_Zero/m_One/m_AllOnes all use struct template function to match and AllowUndefs=false as default.
2025-07-07[SDAG] Remove invalid check (NFC) (#146899)Benjamin Maxwell1-1/+4
It does not make sense to do !LC. LC is an RTLIB::Libcall enum, and zero is a valid value.
2025-07-07[DAG] Replace DAGCombiner::ConstantFoldBITCASTofBUILD_VECTOR with ↵Simon Pilgrim1-0/+72
SelectionDAG::FoldConstantBuildVector (#147037) DAGCombiner can already constant fold build vectors of constants/undefs to a new vector type, but it has to be incredibly careful after legalization to not affect a target's canonicalized constants. This patch proposes we move the implementation inside SelectionDAG to make it easier for targets to manually use the constant folding whenever it deems it safe to do so. I've also altered the method to take the BuildVectorSDNode input directly and consistently use the same SDLoc.
2025-07-04[llvm] Use llvm::fill instead of std::fill(NFC) (#146911)Austin1-2/+2
Use llvm::fill instead of std::fill
2025-07-03Revert "[AMDGPU] SelectionDAG divergence tracking should take into account ↵Florian Hahn1-14/+4
Target divergency. (#144947)" This reverts commit 8ac7210b7f0ad49ae7809bf6a9faf2f7433384b0. This breaks the building the AArch64 backend, e.g. see https://github.com/llvm/llvm-project/pull/144947 Revert to unbreak the build. Also reverts follow-up commits 1e76f012db3ccfaa05e238812e572b5b6d12c17e.
2025-07-03[AMDGPU] SelectionDAG divergence tracking should take into account Target ↵alex-t1-4/+14
divergency. (#144947) If a kernel is known to be executing only a single lane, IR UniformityAnalysis will take note of that (via GCNTTIImpl::hasBranchDivergence) and report that all values are uniform. SelectionDAG's built-in divergence tracking should do the same.
2025-07-01[DAG] canCreateUndefOrPoison - remove isGuaranteedNotToBeUndefOrPoison check ↵Simon Pilgrim1-6/+2
for insert/extract vector element indices (#146514) No longer necessary now that #146490 has landed