1. Jun 23, 2022
  2. Jun 10, 2022
  3. Jun 09, 2022
    • Stephen Long's avatar
      [LoopIdiom] Merge TBAA of adjacent stores when creating memset · d350783a
      Stephen Long authored
      Factor in the TBAA of adjacent stores instead of just the head store
      when merging stores into a memset. We were seeing GVN remove a load that
      had a TBAA that matched the 2nd store because GVN determined it didn't
      match the TBAA of the memset. The memset had the TBAA of only the first
      store.
      
      i.e. Loading the field pi_ of shared_count after memset to create an
      array of shared_ptr
      
      template<class T>
      class shared_ptr {
        T *p;
        shared_count refcount;
      };
      
      class shared_count {
        sp_counted_base *pi_;
      };
      
      Differential Revision: https://reviews.llvm.org/D122205
      
      (cherry picked from commit e02f4976)
      d350783a
  4. Jun 08, 2022
    • Simon Dardis's avatar
      [MIPS] Address instruction selection failure for abs.[sd] · 198626ad
      Simon Dardis authored
      Previously, the choice between the instruction selection of ISD::FABS was
      decided at the point of setting the MIPS target lowering operation choice
      either `Custom` lowering or `Legal`. This lead to instruction selection
      failures as functions could be marked as having no NaNs.
      
      Changing the lowering to always be `Custom` and directly handling the
      the cases where MIPS selects the instructions for ISD::FABS resolves
      this crash.
      
      Thanks to kray for reporting the issue and to Simon Atanasyan for producing
      the reduced test case.
      
      This resolves PR/53722.
      
      Differential Revision: https://reviews.llvm.org/D124651
      
      (cherry picked from commit 938ed8ae)
      198626ad
    • Eli Friedman's avatar
      [LoopIdiom] Fix bailout for aliasing in memcpy transform. · b75bf750
      Eli Friedman authored
      Commit dd5991cc modified the aliasing checks here to allow transforming
      a memcpy where the source and destination point into the same object.
      However, the change accidentally made the code skip the alias check for
      other operations in the loop.
      
      Instead of completely skipping the alias check, just skip the check for
      whether the memcpy aliases itself.
      
      Differential Revision: https://reviews.llvm.org/D126486
      
      (cherry picked from commit abdf0da8)
      b75bf750
    • David Green's avatar
      [ARM] Fix MVE getShuffleCost legalized type check · 2e857fe6
      David Green authored
      The MVE shuffle costing for VREV instructions was making incorrect
      assumptions as to legalized vector types remaining as vectors. Add a
      quick check to ensure they are indeed vectors before attempting to get
      the number of elements.
      
      (cherry picked from commit 53be6ab2)
      2e857fe6
    • Sergei Trofimovich's avatar
      [Support] Add missing <cstdint> header to Base64.h · a517f343
      Sergei Trofimovich authored
      Without the change llvm build fails on this week's gcc-13 snapshot as:
      
          [ 91%] Building CXX object unittests/Support/CMakeFiles/SupportTests.dir/Base64Test.cpp.o
          In file included from llvm/unittests/Support/Base64Test.cpp:14:
          llvm/include/llvm/Support/Base64.h: In function 'std::string llvm::encodeBase64(const InputBytes&)':
          llvm/include/llvm/Support/Base64.h:29:5: error: 'uint32_t' was not declared in this scope
             29 |     uint32_t x = ((unsigned char)Bytes[i] << 16) |
                |     ^~~~~~~~
      
      (cherry picked from commit 5e9be935)
      a517f343
    • Sergei Trofimovich's avatar
      [Support] Add missing <cstdint> header to Signals.h · 4d039a7a
      Sergei Trofimovich authored
      Without the change llvm build fails on this week's gcc-13 snapshot as:
      
          [  0%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Signals.cpp.o
          In file included from llvm/lib/Support/Signals.cpp:14:
          llvm/include/llvm/Support/Signals.h:119:8: error: variable or field 'CleanupOnSignal' declared void
            119 |   void CleanupOnSignal(uintptr_t Context);
                |        ^~~~~~~~~~~~~~~
      
      (cherry picked from commit ff1681dd)
      4d039a7a
    • Brooks Davis's avatar
      compiler-rt: Allow build without __c11_atomic_fetch_nand · 483db58f
      Brooks Davis authored
      Don't build atomic fetch nand libcall functions when the required
      compiler builtin isn't available. Without this compiler-rt can't be
      built with LLVM 13 or earlier.
      
      Not building the libcall functions isn't optimal, but aligns with the
      usecase in FreeBSD where compiler-rt from LLVM 14 is built with an LLVM
      13 clang and no LLVM 14 clang is built.
      
      Reviewed By:	efriedma
      
      Differential Revision:	https://reviews.llvm.org/D126710
      
      (cherry picked from commit 18efa420)
      483db58f
  5. Jun 03, 2022
    • Salman Javed's avatar
      [clang-tidy] Fix #55134 (regression introduced by 5da7c040) · 576e5b39
      Salman Javed authored
      5da7c040 introduced a regression in the NOLINT macro checking loop, replacing the
      call to `getImmediateExpansionRange().getBegin()` with
      `getImmediateMacroCallerLoc()`, which has similar but subtly different
      behaviour.
      
      The consequence is that NOLINTs cannot suppress diagnostics when they are
      attached to a token that came from a macro **argument**, rather than elsewhere
      in the macro expansion.
      
      Revert to pre-patch behaviour and add test cases to cover this issue.
      
      Differential Revision: https://reviews.llvm.org/D126138
      
      (cherry picked from commit 9ff4f2df)
      576e5b39
    • Nikita Popov's avatar
      [Local] Don't remove invoke of non-willreturn function · 99b5eb2d
      Nikita Popov authored
      The code was only checking for memory side-effects, but not for
      divergence side-effects. Replace this with a generic check.
      
      (cherry picked from commit 2e101cca)
      99b5eb2d
    • Nikita Popov's avatar
      [SimplifyCFG] Add test for invoke of nounwind non-willreturn function (NFC) · 885724c6
      Nikita Popov authored
      Test both the case with and without willreturn attribute.
      
      (cherry picked from commit 1f1de061)
      885724c6
    • Michael Kruse's avatar
      [OpenMP] Fix partial unrolling off-by-one. · 2f0a69c3
      Michael Kruse authored
      Even though the comment description is ".unroll_inner.iv < NumIterations", the code emitted a BO_LE ('<=') operator for the inner loop that is to be unrolled. This lead to one additional copy of the body code in a partially unrolled. It only manifests when the unrolled loop is consumed by another loop-associated construct. Fix by using the BO_LT operator instead.
      
      The condition for the outer loop and the corresponding code for tiling correctly used BO_LT already.
      
      Fixes #55236
      2f0a69c3
    • Evgeny Mankov's avatar
      [clang][CUDA][Windows] Fix compilation error on Windows with `uint32_t __nvvm_get_smem_pointer` · 79147e47
      Evgeny Mankov authored
      The change fixes https://github.com/llvm/llvm-project/issues/54609 (the second reported issue) by eliminating a compilation error occurring only on Windows while trying to compile any CUDA source file by clang (-x cuda).
      
      [Repro]
      clang -x cuda <any_cu_source>
      
      [Error]
      
      __clang_cuda_runtime_wrapper.h:473:
      __clang_cuda_intrinsics.h(517,19): error GC871EEFB: unknown type name 'uint32_t'; did you mean 'cuuint32_t'?
      __device__ inline uint32_t __nvvm_get_smem_pointer(void *__ptr) {
                                ^
      C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/include\cuda.h:57:26: note: 'cuuint32_t' declared here
      typedef unsigned __int32 cuuint32_t;
      
      Reviewed By: tra
      
      Differential Revision: https://reviews.llvm.org/D122897
      
      (cherry picked from commit c2314710)
      79147e47
    • Arthur Eubanks's avatar
      [clang] Fix some clang->llvm type cache invalidation issues · ec033232
      Arthur Eubanks authored
      Take the following as an example
      
        struct z {
          z (*p)();
        };
      
        z f();
      
      When we attempt to get the LLVM type of f, we recurse into z. z itself
      has a function pointer with the same type as f. Given the recursion,
      Clang simply treats z::p as a pointer to an empty struct `{}*`. The
      LLVM type of f is as expected. So we have two different potential
      LLVM types for a given Clang type. If we store one of those into the
      cache, when we access the cache with a different context (e.g. we
      are/aren't recursing on z) we may get an incorrect result. There is some
      attempt to clear the cache in these cases, but it doesn't seem to handle
      all cases.
      
      This change makes it so we only use the cache when we are not in any
      sort of function context, i.e. `noRecordsBeingLaidOut() &&
      FunctionsBeingProcessed.empty()`, which are the cases where we may
      decide to choose a different LLVM type for a given Clang type. LLVM
      types for builtin types are never recursive so they're always ok.
      
      This allows us to clear the type cache less often (as seen with the
      removal of one of the calls to `TypeCache.clear()`). We
      still need to clear it when we use a placeholder type then replace it
      later with the final type and other dependent types need to be
      recalculated.
      
      I've added a check that the cached type matches what we compute. It
      triggered in this test case without the fix. It's currently not
      check-clang clean so it's not on by default for something like expensive
      checks builds.
      
      This change uncovered another issue where the LLVM types for an argument
      and its local temporary don't match. For example in type-cache-3, when
      expanding z::dc's argument into a temporary alloca, we ConvertType() the
      type of z::p which is `void ({}*)*`, which doesn't match the alloca GEP
      type of `{}*`.
      
      No noticeable compile time changes:
      https://llvm-compile-time-tracker.com/compare.php?from=3918dd6b8acf8c5886b9921138312d1c638b2937&to=50bdec9836ed40e38ece0657f3058e730adffc4c&stat=instructions
      
      Fixes #53465.
      
      Reviewed By: rnk
      
      Differential Revision: https://reviews.llvm.org/D118744
      
      (cherry picked from commit 45084eab)
      ec033232
    • Ben Shi's avatar
      [clang][AVR] Implement standard calling convention for AVR and AVRTiny · 10d44252
      Ben Shi authored
      This patch implements avr-gcc's calling convention:
      https://gcc.gnu.org/wiki/avr-gcc#Calling_Convention
      
      Reviewed By: aykevl
      
      Differential Revision: https://reviews.llvm.org/D120720
      
      (cherry picked from commit 51585aa2)
      10d44252
    • Qiu Chaofan's avatar
      [PowerPC] Treat llvm.fmuladd intrinsic as using CTR · 09ec80e1
      Qiu Chaofan authored
      This fixes bug 55463, similar to D78668. This is a temporary fix since
      we will switch to post-isel CTR loop determination in the future.
      
      Reviewed By: dim, shchenz
      
      Differential Revision: https://reviews.llvm.org/D125746
      
      (cherry picked from commit d9d15af7)
      09ec80e1
  6. May 25, 2022
    • Tom Stellard's avatar
      Bump version to 14.0.5 · b950bd2c
      Tom Stellard authored
      b950bd2c
    • Yaxun (Sam) Liu's avatar
      [CUDA][HIP] Externalize kernels with internal linkage · 29f1039a
      Yaxun (Sam) Liu authored
      This patch is a continuation of https://reviews.llvm.org/D123353.
      
      Not only kernels in anonymous namespace, but also template
      kernels with template arguments in anonymous namespace
      need to be externalized.
      
      To be more generic, this patch checks the linkage of a kernel
      assuming the kernel does not have __global__ attribute. If
      the linkage is internal then clang will externalize it.
      
      This patch also fixes the postfix for externalized symbol
      since nvptx does not allow '.' in symbol name.
      
      Reviewed by: Artem Belevich
      
      Differential Revision: https://reviews.llvm.org/D124189
      
      Fixes: https://github.com/llvm/llvm-project/issues/54560
      (cherry picked from commit 04fb8167)
      29f1039a
    • Yaxun (Sam) Liu's avatar
      [CUDA][HIP] Externalize kernels in anonymous name space · e6de9ed3
      Yaxun (Sam) Liu authored
      kernels in anonymous name space needs to have unique name
      to avoid duplicate symbols.
      
      Fixes: https://github.com/llvm/llvm-project/issues/54560
      
      Reviewed by: Artem Belevich
      
      Differential Revision: https://reviews.llvm.org/D123353
      
      (cherry picked from commit 4ea1d435)
      e6de9ed3
    • Peter Collingbourne's avatar
      AST: Move __va_list tag back to std conditionally on AArch64. · fecfc839
      Peter Collingbourne authored
      In post-commit feedback on D104830 Jessica Clarke pointed out that
      unconditionally adding __va_list to the std namespace caused namespace
      debug info to be emitted in C, which is not only inappropriate but
      turned out to confuse the dtrace tool. Therefore, move __va_list back
      to std only in C++ so that the correct debug info is generated. We
      also considered moving __va_list to the top level unconditionally
      but this would contradict the specification and be visible to AST
      matchers and such, so make it conditional on the language mode.
      
      To avoid breaking name mangling for __va_list, teach the Itanium
      name mangler to always mangle it as if it were in the std namespace
      when targeting ARM architectures. This logic is not needed for the
      Microsoft name mangler because Microsoft platforms define va_list as
      a typedef of char *.
      
      Depends on D116773
      
      Differential Revision: https://reviews.llvm.org/D116774
      fecfc839
    • Peter Collingbourne's avatar
      AST: Make getEffectiveDeclContext() a member function of ItaniumMangleContextImpl. NFCI. · 725d57c3
      Peter Collingbourne authored
      In an upcoming change we are going to need to access mangler state
      from the getEffectiveDeclContext() function. Therefore, make it a
      member function of ItaniumMangleContextImpl. Any callers that are
      not currently members of ItaniumMangleContextImpl or CXXNameMangler
      are made members of one or the other depending on where they are
      called from.
      
      Differential Revision: https://reviews.llvm.org/D116773
      725d57c3
    • Nathan Sidwell's avatar
      [clang][NFC] Remove IgnoreLinkageSpecDecls · 0009cdbd
      Nathan Sidwell authored
      The Itanium mangler uses IgnoreLinkageSpecDecls to strip linkage spec
      contexts.  It doesn't do this consistently, but there is no need for
      it to do it at all.  getEffectiveDeclContext never returns a linkage
      spec, as it either recurses, uses getRedeclContext (which itself
      removes the specs), or gets the decl context of non-namespace entities.
      
      This patch removes the function and all calls to it.  For safety I add
      a couple of asserts to make sure we never get them.
      
      Reviewed By: ChuanqiXu
      
      Differential Revision: https://reviews.llvm.org/D119748
      0009cdbd
    • Nathan Sidwell's avatar
      [clang][NFC] Standard substitution checking cleanup · 53eaee6b
      Nathan Sidwell authored
      In preparing for module mangling changes I noticed some issues with
      the way we check for std::basic_string instantiations and friends.
      
      *) there's a single routine for std::basic_{i,o,io}stream but it is
       templatized on the length of the name.  Really?  just use a
       StringRef, rather than clone the entire routine just for
       'basic_iostream'.
      
      *) We have a helper routine to check for char type, and call it from
       several places.  But given all the instantiations are of the form
       TPL<char, Other<char> ...> we could just check the first arg is char
       and the later templated args are instantiating that same type.  A
       simpler type comparison.
      
      *) Because basic_string has a third allocator parameter, it is open
       coded, which I found a little confusing.  But otherwise it's exactly
       the same pattern as the iostream ones.  Just tell that checker about
       whether there's an expected allocator argument.[*]
      
      *) We may as well return in each block of mangleStandardSubstitution
       once we determine it is not one of the entities of interest -- it
       certainly cannot be one of the other kinds of entities.
      
      FWIW this shaves about 500 bytes off the executable.
      
      [*] I suppose we could also have this routine a tri-value, with one to
      indicat 'it is this name, but it's not the one you're looking for', to
      avoid later calls trying different names?
      
      Reviewd By: ChuanqiXu
      
      Differential Revision: https://reviews.llvm.org/D119333
      53eaee6b
    • Ben Shi's avatar
      [AVR] Generate 'rcall' instead of 'call' on avr2 and avr25 · c81f3d00
      Ben Shi authored
      The 'call' (long call) instruction is available on avr3 and above,
      and devices in avr2 and avr25 should use the 'rcall' (short call)
      instruction for function calls.
      
      Reviewed By: aykevl, dylanmckay
      
      Differential Revision: https://reviews.llvm.org/D121539
      
      (cherry picked from commit 45638931)
      c81f3d00
    • Ben Shi's avatar
      [AVR] Fix incorrect calling convention for varargs functions · 5f6fe6b9
      Ben Shi authored
      An i8 argument should only cost 1 byte on the stack. This is
      compatible with avr-gcc.
      
      There are also more test cases (of calling convention) are added.
      
      Reviewed By: aykevl, dylanmckay
      
      Differential Revision: https://reviews.llvm.org/D121767
      
      (cherry picked from commit 3fd9a320)
      5f6fe6b9
    • Jonas Paulsson's avatar
      [SystemZ] Bugfix for symbolic displacements. · 42fe7ccb
      Jonas Paulsson authored
      Properly handle the case where only the second operand of e.g. an MVC
      instruction uses a fixup for the displacement.
      
      Reviewed By: Ulrich Weigand
      
      Differential Revision: https://reviews.llvm.org/D125982
      
      (cherry picked from commit e547b04d)
      42fe7ccb
  7. May 24, 2022
  8. May 20, 2022
    • Fangrui Song's avatar
      [ELF][ARM] Fix unneeded thunk for branches to hidden undefined weak · 5f66e721
      Fangrui Song authored
      Similar to D123750 for AArch64.
      
      (cherry picked from commit b483ce12)
      5f66e721
    • Tom Eccles's avatar
      Fix crash getting name of a template decl · 3bfae781
      Tom Eccles authored
      NamedDecl::getIdentifier can return a nullptr when
      DeclarationName::isIdentifier is false, which leads to a null pointer
      dereference when TypePrinter::printTemplateId calls ->getName().
      
      NamedDecl::getName does the same thing in the successful case and
      returns an empty string in the failure case.
      
      This crash affects the llvm 14 packages on llvm.org.
      
      (cherry picked from commit 225b91e6)
      3bfae781
    • Joseph Huber's avatar
      [OpenMP] Fix library path missing when using OpenMP · 76c1c1dd
      Joseph Huber authored
      The changes in D122444 caused OpenMP programs built with the
      LLVM_ENABLE_RUNTIMES options to stop finding the libraries. We generally
      expect to link against the libraries associated with the clang
      installation itself but we no longer implicitly included that directory.
      This patch adds in the include path of the clang installations library
      to ensure we can find them.
      
      Reviewed By: jdoerfert, MaskRay
      
      Differential Revision: https://reviews.llvm.org/D122592
      
      (cherry picked from commit fceea4e1)
      76c1c1dd
    • Fangrui Song's avatar
      [ELF][AArch64] Fix unneeded thunk for branches to hidden undefined weak · 588b95a2
      Fangrui Song authored
      Similar to D119787 for PPC64.
      
      A hidden undefined weak may change its binding to local before some
      `isUndefinedWeak` code, so some `isUndefinedWeak` code needs to be changed to
      `isUndefined`. The undefined non-weak case has been errored, so just using
      `isUndefined` is fine.
      
      The Linux kernel recently has a usage that a branch from 0xffff800008491ee0
      references a hidden undefined weak symbol `vfio_group_set_kvm`.
      It relies on the behavior that a branch to undefined weak resolving to the next
      instruction, otherwise it'd see spurious relocation out of range errors.
      
      Fixes https://github.com/ClangBuiltLinux/linux/issues/1624
      
      Differential Revision: https://reviews.llvm.org/D123750
      
      (cherry picked from commit 02eab528)
      588b95a2