1. Mar 12, 2024
  2. Mar 11, 2024
    • Matthias Springer's avatar
      [mlir][IR] Fix overload resolution on MSVC build (#84589) · f1aa7837
      Matthias Springer authored
      #82629 added additional overloads to `replaceAllUsesWith` and
      `replaceUsesWithIf`. This caused a build breakage with MSVC when called
      with ops that can implicitly convert to `Value`.
      
      ```
      external/llvm-project/mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp(881): error C2666: 'mlir::RewriterBase::replaceAllUsesWith': 2 overloads have similar conversions
      external/llvm-project/mlir/include\mlir/IR/PatternMatch.h(631): note: could be 'void mlir::RewriterBase::replaceAllUsesWith(mlir::Operation *,mlir::ValueRange)'
      external/llvm-project/mlir/include\mlir/IR/PatternMatch.h(626): note: or       'void mlir::RewriterBase::replaceAllUsesWith(mlir::ValueRange,mlir::ValueRange)'
      external/llvm-project/mlir/include\mlir/IR/PatternMatch.h(616): note: or       'void mlir::RewriterBase::replaceAllUsesWith(mlir::Value,mlir::Value)'
      external/llvm-project/mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp(882): note: while trying to match the argument list '(mlir::tensor::ExtractSliceOp, T)'
              with
              [
                  T=mlir::Value
              ]
      ```
      
      Note: The LLVM build bots (Linux and Windows) did not break, this seems
      to be an issue with `Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe`.
      
      This change renames the newly added overloads to `replaceAllOpUsesWith`
      and `replaceOpUsesWithIf`.
      f1aa7837
    • Pierre van Houtryve's avatar
      [AMDGPU] Let LowerModuleLDS run twice on the same module (#81729) · d4569d42
      Pierre van Houtryve authored
      If all variables in the module are absolute, this means we're running
      the pass again on an already lowered module, and that works.
      If none of them are absolute, lowering can proceed as usual.
      Only diagnose cases where we have a mix of absolute/non-absolute GVs,
      which means we added LDS GVs after lowering, which is broken.
      
      See #81491
      Split from #75333
      d4569d42
    • Nathan Ridge's avatar
      [clangd] Avoid libFormat's objective-c guessing heuristic where possible (#84133) · 3093d731
      Nathan Ridge authored
      This avoids a known libFormat bug where the heuristic can OOM on certain
      large files (particularly single-header libraries such as miniaudio.h).
      
      The OOM will still happen on affected files if you actually try to
      format them (this is harder to avoid since the underlyting issue affects
      the actual formatting logic, not just the language-guessing heuristic),
      but at least it's avoided during non-modifying operations like hover,
      and modifying operations that do local formatting like code completion.
      
      Fixes https://github.com/clangd/clangd/issues/719
      Fixes https://github.com/clangd/clangd/issues/1384
      Fixes https://github.com/llvm/llvm-project/issues/70945
      3093d731
    • Craig Topper's avatar
      Revert "[TypePromotion] Support positive addition amounts in isSafeWrap. (#81690)" · 561ddb16
      Craig Topper authored
      This reverts commit 0813b90f.
      
      Fixes miscompile reported in #84718.
      561ddb16
    • AtariDreams's avatar
      4e0e9b17
    • Pavel Labath's avatar
      [compiler-rt] Mark more calls as blocking (#77789) · cf1319f9
      Pavel Labath authored
      If we're in a blocking call, we need to run the signal immediately, as
      the call may not return for a very long time (if ever). Not running the
      handler can cause deadlocks if the rest of the program waits (in one way
      or another) for the signal handler to execute.
      
      I've gone through the list of functions in
      sanitizer_common_interceptors and marked as blocking those that I know
      can block, but I don't claim the list to be exhaustive. In particular, I
      did not mark libc FILE* functions as blocking, because these can end up
      calling user functions. To do that correctly, /I think/ it would be
      necessary to clear the "is in blocking call" flag inside the fopencookie
      wrappers.
      
      The test for the bug (deadlock) uses the read call (which is the one
      that I ran into originally), but the same kind of test could be written
      for any other blocking syscall.
      cf1319f9
    • Carl Ritson's avatar
      [LiveIntervals] repairIntervalsInRange: recompute width changes (#78564) · 4a21e3af
      Carl Ritson authored
      Extend repairIntervalsInRange to completely recompute the interva for a
      register if subregister defs exist without precise subrange matches
      (LaneMask exactly matching subregister).
      This occurs when register sequences are lowered to copies such that the
      size of the copies do not match any uses of the subregisters formed
      (i.e. during twoaddressinstruction).
      
      The subranges without this change are probably legal, but do not match
      those generated by live interval computation. This creates problems with
      other code that assumes subranges precisely cover all subregisters
      defined, e.g. shrinkToUses().
      4a21e3af
    • Fangrui Song's avatar
      [ELF] Move getSymbol/getRelocTargetSym from ObjFile<ELFT> to InputFile. NFC · f6455606
      Fangrui Song authored
      This removes lots of unneeded `template getFile<ELFT>()`.
      f6455606
    • Kito Cheng's avatar
      [RISCV] Place mergeable small read only data into srodata section (#82214) · b7f97d36
      Kito Cheng authored
      Small mergeable read only data was place on the sdata before, but it
      also means it lose the mergeable property, which means lose some code
      size optimization opportunity during link time.
      b7f97d36
    • Carl Ritson's avatar
      [AMDGPU] Update LiveInterval def index for early-clobber (#79285) · d9e6aa70
      Carl Ritson authored
      On converting an instruction to an early-clobber definition in
      convertToThreeAddress, we must also update live intervals for the
      register to start at the early-clobber index.
      d9e6aa70
    • Craig Topper's avatar
      [RISCV] Handle FP riscv_masked_strided_load with 0 stride. (#84576) · d8d2dea7
      Craig Topper authored
      Previously, we tried to create an integer extending load. We need to a
      non-extending FP load instead.
      
      Fixes #84541.
      d8d2dea7
    • Chuanqi Xu's avatar
      [C++20] [Moduls] Avoid computing odr hash for functions from comparing constraint expression · 3f6bc1ad
      Chuanqi Xu authored
      Previously we disabled to compute ODR hash for declarations from the
      global module fragment. However, we missed the case that the functions
      lives in the concept requiments (see the attached the test files for
      example). And the mismatch causes the potential crashment.
      
      Due to we will set the function body as lazy after we deserialize it and
      we will only take its body when needed. However, we don't allow to take
      the body during deserializing. So it is actually potentially problematic
      if we set the body as lazy first and computing the hash value of the
      function, which requires to deserialize its body. So we will meet a
      crash here.
      
      This patch tries to solve the issue by not taking the body of the
      function from GMF. Note that we can't skip comparing the constraint
      expression from the GMF directly since it is an key part of the
      function selecting and it may be the reason why we can't return 0
      directly for `FunctionDecl::getODRHash()` from the GMF.
      3f6bc1ad
    • Justin Lebar's avatar
    • Amirreza Ashouri's avatar
      [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (#77092) · 7dfa8398
      Amirreza Ashouri authored
      Consistent with `__is_trivially_copyable(volatile int) == true` and
      `__is_trivially_relocatable(volatile Trivial) == true`,
      `__is_trivially_relocatable(volatile int)` should also be `true`.
      
      Fixes https://github.com/llvm/llvm-project/issues/77091
      
      [clang] [test] New tests for __is_trivially_relocatable(cv-qualified
      type)
      7dfa8398
    • Justin Lebar's avatar
      Add llvm::min/max_element and use it in llvm/ and mlir/ directories. (#84678) · fab2bb8b
      Justin Lebar authored
      For some reason this was missing from STLExtras.
      fab2bb8b
    • lntue's avatar
      [libc] Fix flag parsing bugs. (#84706) · 6bec4fc7
      lntue authored
      6bec4fc7
    • fpasserby's avatar
      [coroutine] Implement llvm.coro.await.suspend intrinsic (#79712) · f7868813
      fpasserby authored
      Implement `llvm.coro.await.suspend` intrinsics, to deal with performance
      regression after prohibiting `.await_suspend` inlining, as suggested in
      #64945.
      Actually, there are three new intrinsics, which directly correspond to
      each of three forms of `await_suspend`:
      ```
      void llvm.coro.await.suspend.void(ptr %awaiter, ptr %frame, ptr @wrapperFunction)
      i1 llvm.coro.await.suspend.bool(ptr %awaiter, ptr %frame, ptr @wrapperFunction)
      ptr llvm.coro.await.suspend.handle(ptr %awaiter, ptr %frame, ptr @wrapperFunction)
      ```
      There are three different versions instead of one, because in `bool`
      case it's result is used for resuming via a branch, and in
      `coroutine_handle` case exceptions from `await_suspend` are handled in
      the coroutine, and exceptions from the subsequent `.resume()` are
      propagated to the caller.
      
      Await-suspend block is simplified down to intrinsic calls only, for
      example for symmetric transfer:
      ```
      %id = call token @llvm.coro.save(ptr null)
      %handle = call ptr @llvm.coro.await.suspend.handle(ptr %awaiter, ptr %frame, ptr @wrapperFunction)
      call void @llvm.coro.resume(%handle)
      %result = call i8 @llvm.coro.suspend(token %id, i1 false)
      switch i8 %result, ...
      ```
      All await-suspend logic is moved out into a wrapper function, generated
      for each suspension point.
      The signature of the function is `<type> wrapperFunction(ptr %awaiter,
      ptr %frame)` where `<type>` is one of `void` `i1` or `ptr`, depending on
      the return type of `await_suspend`.
      Intrinsic calls are lowered during `CoroSplit` pass, right after the
      split.
      
      Because I'm new to LLVM, I'm not sure if the helper function generation,
      calls to them and lowering are implemented in the right way, especially
      with regard to various metadata and attributes, i. e. for TBAA. All
      things that seemed questionable are marked with `FIXME` comments.
      
      There is another detail: in case of symmetric transfer raw pointer to
      the frame of coroutine, that should be resumed, is returned from the
      helper function and a direct call to `@llvm.coro.resume` is generated.
      C++ standard demands, that `.resume()` method is evaluated. Not sure how
      important is this, because code has been generated in the same way
      before, sans helper function.
      f7868813
    • wanglei's avatar
      [LoongArch] Make sure that the LoongArchISD::BSTRINS node uses the correct `MSB` value (#84454) · edd4c6c6
      wanglei authored
      The `MSB` must not be greater than `GRLen`. Without this patch, newly
      added test cases will crash with LoongArch32, resulting in a 'cannot
      select' error.
      edd4c6c6
    • Noah Goldstein's avatar
    • Noah Goldstein's avatar
      [InstCombine] Tests for `(icmp eq/ne (and (shl -1, X), Y), 0)` -> `(icmp eq/ne... · cef862e0
      Noah Goldstein authored
      [InstCombine] Tests for `(icmp eq/ne (and (shl -1, X), Y), 0)` -> `(icmp eq/ne (lshr Y, X), 0)`; NFC
      cef862e0
    • Jacek Caban's avatar
      [LLD][COFF] Add support for IMPORT_NAME_EXPORTAS import library names. (#83211) · 7b275aa2
      Jacek Caban authored
      This allows handling importlibs produced by llvm-dlltool in #78772.
      ARM64EC import libraries use it by default, but it's supported by MSVC
      link.exe on other platforms too.
      
      This also avoids assuming null-terminated input, like in #78769.
      7b275aa2
    • Schrodinger ZHU Yifan's avatar
    • Joseph Huber's avatar
      [libc][NFC] Move GPU allocator implementation to common header (#84690) · ea697dcc
      Joseph Huber authored
      Summary:
      This is a NFC move preceding more radical functional changes to the
      allocator implementation. We just move it to a common utility so it will
      be easier to write these in tandem.
      ea697dcc
    • alx32's avatar
      [lld-macho][NFC] Refactor ObjCSelRefsSection out of ObjCStubsSection (#83878) · a53401e9
      alx32 authored
      
      
      Currently ObjCStubsSection is handling both the logic for the
      "__objc_stubs" section, as well as the logic for the "__objc_selrefs"
      section.
      While this is OK for now, it will be an issue for other features that
      want to interact with the "__objc_selrefs" section, such as upcoming
      relative method lists feature - which will also want to create /
      reference entries in the "__objc_selrefs" section.
      In this PR we split the logic relating to handling the "__objc_selrefs"
      section into a new SyntheticSection (ObjCSelRefsSection). Non-functional
      change - neither the behavior nor implementation changes, the interface
      is just made more friendly to not have "__objc_selrefs" so bound to
      "__objc_stubs".
      
      ---------
      
      Co-authored-by: default avatarAlex B <alexborcan@meta.com>
      a53401e9
    • Noah Goldstein's avatar
      [InstCombine] Recognize `(icmp eq/ne (and X, ~Mask), 0)` pattern in `foldICmpWithLowBitMaskedVal` · 193b3d67
      Noah Goldstein authored
      `(icmp eq/ne (and X, ~Mask), 0)` is equivilent to `(icmp eq/ne (and X,
      Mask), X` and we sometimes generate the former pattern intentionally
      to reduce number of uses of `X`.
      Proof: https://alive2.llvm.org/ce/z/3u-usC
      
      Differential Revision: https://reviews.llvm.org/D159329
      
      Closes #81562
      193b3d67
    • Noah Goldstein's avatar
      [InstCombine] Improve mask detection in `foldICmpWithLowBitMaskedVal` · d77eb9ea
      Noah Goldstein authored
      Make recursive matcher that is able to detect a lot more patterns.
      Proofs for all supported patterns: https://alive2.llvm.org/ce/z/fSQ3nZ
      
      Differential Revision: https://reviews.llvm.org/D159058
      d77eb9ea
    • Noah Goldstein's avatar
    • Noah Goldstein's avatar
    • Joseph Huber's avatar
      [libc] Move RPC opcodes include out of the header · 8a790033
      Joseph Huber authored
      Summary:
      This header isn't strictly necessary, and is currently broken because we
      install these to separate locations.
      8a790033
    • Michael Flanders's avatar
      [libc][stdbit] Fix truncation err in CPP bit_ceil (#84683) · a066f71e
      Michael Flanders authored
      After #84657 was merged,
      [buildbot](https://lab.llvm.org/buildbot/#/builders/250/builds/19808) is
      reporting two errors for libc-x86_64-debian-gcc-fullbuild-dbg. This PR
      addresses the truncation error for `CPP::bit_ceil<unsigned char>` and
      `CPP::bit_ceil<unsigned short>`.
      
      The errors are:
      
      ```
      FAILED: projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_uc.dir/stdc_bit_ceil_uc.cpp.o
      /usr/bin/g++ -DLIBC_NAMESPACE=__llvm_libc_19_0_0_git -D_DEBUG -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/src/stdbit -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc -isystem /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-vir!
       tual-dtor
        -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -fpie -ffreestanding -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -DLIBC_COPT_PUBLIC_PACKAGING -std=c++17 -MD -MT projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_uc.dir/stdc_bit_ceil_uc.cpp.o -MF projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_uc.dir/stdc_bit_ceil_uc.cpp.o.d -o projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_uc.dir/stdc_bit_ceil_uc.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit/stdc_bit_ceil_uc.cpp
      In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit/stdc_bit_ceil_uc.cpp:11:
      /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/CPP/bit.h: In instantiation of ‘constexpr __llvm_libc_19_0_0_git::cpp::enable_if_t<is_unsigned_v<T>, T> __llvm_libc_19_0_0_git::cpp::bit_ceil(T) [with T = unsigned char; enable_if_t<is_unsigned_v<T>, T> = unsigned char]’:
      /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit/stdc_bit_ceil_uc.cpp:17:23:   required from here
      /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/CPP/bit.h:196:57: error: conversion from ‘unsigned int’ to ‘unsigned char’ may change value [-Werror=conversion]
        196 |   return static_cast<T>(T(1) << cpp::bit_width<T>(value - 1u));
            |                                                   ~~~~~~^~~~
      cc1plus: all warnings being treated as errors
      [138/466] Building CXX object projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_us.dir/stdc_bit_ceil_us.cpp.o
      FAILED: projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_us.dir/stdc_bit_ceil_us.cpp.o
      /usr/bin/g++ -DLIBC_NAMESPACE=__llvm_libc_19_0_0_git -D_DEBUG -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/src/stdbit -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc -isystem /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-vir!
       tual-dtor
        -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -fpie -ffreestanding -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -DLIBC_COPT_PUBLIC_PACKAGING -std=c++17 -MD -MT projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_us.dir/stdc_bit_ceil_us.cpp.o -MF projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_us.dir/stdc_bit_ceil_us.cpp.o.d -o projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_us.dir/stdc_bit_ceil_us.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit/stdc_bit_ceil_us.cpp
      In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit/stdc_bit_ceil_us.cpp:11:
      /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/CPP/bit.h: In instantiation of ‘constexpr __llvm_libc_19_0_0_git::cpp::enable_if_t<is_unsigned_v<T>, T> __llvm_libc_19_0_0_git::cpp::bit_ceil(T) [with T = short unsigned int; enable_if_t<is_unsigned_v<T>, T> = short unsigned int]’:
      /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit/stdc_bit_ceil_us.cpp:17:23:   required from here
      /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/CPP/bit.h:196:57: error: conversion from ‘unsigned int’ to ‘short unsigned int’ may change value [-Werror=conversion]
        196 |   return static_cast<T>(T(1) << cpp::bit_width<T>(value - 1u));
            |                                                   ~~~~~~^~~~
      cc1plus: all warnings being treated as errors
      ```
      a066f71e
    • Michael Flanders's avatar
      [libc][stdbit][c23] adds implementation of `stdc_bit_ceil` functions (#84657) · 75b0d384
      Michael Flanders authored
      Closes #84652.
      
      Based on #84233.
      75b0d384
    • Simon Pilgrim's avatar
  3. Mar 10, 2024