platform/upstream/llvm.git
2 years ago[ASan] Fixed asan_mapping.h format.
Kirill Stoimenov [Thu, 2 Dec 2021 20:19:29 +0000 (20:19 +0000)]
[ASan] Fixed asan_mapping.h format.

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D114987

2 years agoxfail: reduction_implicit_map.cpp after reapply of Start calling setTargetAttributes
Ron Lieberman [Thu, 2 Dec 2021 20:22:11 +0000 (20:22 +0000)]
xfail: reduction_implicit_map.cpp after reapply of Start calling setTargetAttributes

2 years ago[libc++][NFC] Update namespace comments in include/
Nikolas Klauser [Thu, 2 Dec 2021 13:12:51 +0000 (14:12 +0100)]
[libc++][NFC] Update namespace comments in include/

update the namspace comments in include/

Reviewed By: ldionne, #libc

Spies: smeenai, libcxx-commits

Differential Revision: https://reviews.llvm.org/D114947

2 years agoprofi - a flow-based profile inference algorithm: Part III (out of 3)
spupyrev [Thu, 2 Dec 2021 19:59:33 +0000 (11:59 -0800)]
profi - a flow-based profile inference algorithm: Part III (out of 3)

This is a continuation of D109860 and D109903.

An important challenge for profile inference is caused by the fact that the
sample profile is collected on a fully optimized binary, while the block and
edge frequencies are consumed on an early stage of the compilation that operates
with a non-optimized IR. As a result, some of the basic blocks may not have
associated sample counts, and it is up to the algorithm to deduce missing
frequencies. The problem is illustrated in the figure where three basic
blocks are not present in the optimized binary and hence, receive no samples
during profiling.

We found that it is beneficial to treat all such blocks equally. Otherwise the
compiler may decide that some blocks are “cold” and apply undesirable
optimizations (e.g., hot-cold splitting) regressing the performance. Therefore,
we want to distribute the counts evenly along the blocks with missing samples.
This is achieved by a post-processing step that identifies "dangling" subgraphs
consisting of basic blocks with no sampled counts; once the subgraphs are
found, we rebalance the flow so as every branch probability is 50:50 within the
subgraphs.

Our experiments indicate up to 1% performance win using the optimization on
some binaries and a significant improvement in the quality of profile counts
(when compared to ground-truth instrumentation-based counts)

{F19093045}

Reviewed By: hoy

Differential Revision: https://reviews.llvm.org/D109980

2 years ago[gn build] (manually) port 9e3552523ebd (no more old mach-o lld)
Nico Weber [Thu, 2 Dec 2021 20:00:40 +0000 (15:00 -0500)]
[gn build] (manually) port 9e3552523ebd (no more old mach-o lld)

2 years ago[ELF] Hint -z nostart-stop-gc for __start_ undefined references
Fangrui Song [Thu, 2 Dec 2021 19:58:25 +0000 (11:58 -0800)]
[ELF] Hint -z nostart-stop-gc for __start_ undefined references

Make users aware what to do with ld.lld 13.0.0 / GNU ld<2015-10 --gc-sections
behavior.

Differential Revision: https://reviews.llvm.org/D114830

2 years agoReapply "OpenMP: Start calling setTargetAttributes for generated kernels"
Matt Arsenault [Mon, 29 Nov 2021 20:47:42 +0000 (15:47 -0500)]
Reapply "OpenMP: Start calling setTargetAttributes for generated kernels"

This reverts commit 25eb7fa01d7ebbe67648ea03841cda55b4239ab2.

Previous buildbot failures appear to have been a fluke from a dirty
build.

2 years ago[NFC][sanitizer] Use more bytes of sanitizer_stack_store_test pointers
Vitaly Buka [Thu, 2 Dec 2021 02:41:54 +0000 (18:41 -0800)]
[NFC][sanitizer] Use more bytes of sanitizer_stack_store_test pointers

2 years ago[compiler-rt] Fix incorrect variable names used
Leonard Chan [Thu, 2 Dec 2021 19:45:41 +0000 (11:45 -0800)]
[compiler-rt] Fix incorrect variable names used

2 years ago[sanitizer] Start background thread once
Vitaly Buka [Thu, 2 Dec 2021 08:41:41 +0000 (00:41 -0800)]
[sanitizer] Start background thread once

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D114933

2 years ago[Bazel] Remove old macho lld port
Keith Smiley [Thu, 2 Dec 2021 19:24:08 +0000 (11:24 -0800)]
[Bazel] Remove old macho lld port

This code and cmake was removed in https://reviews.llvm.org/D114842

Differential Revision: https://reviews.llvm.org/D114976

2 years ago[asan] Remove confusing workaround
Vitaly Buka [Thu, 2 Dec 2021 08:53:02 +0000 (00:53 -0800)]
[asan] Remove confusing workaround

The goal is to identify the bot and try to fix it.

SetSoftRssLimitExceededCallback is AsanInitInternal as I assume
that only MaybeStartBackgroudThread needs to be delayed to constructors.
Later I want to move MaybeStartBackgroudThread call into sanitizer_common.

If it needs to be reverted please provide to more info, like bot, or details about setup.

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D114934

2 years agoSimplify the libcxx std::string_view gdb pretty printer
David Blaikie [Fri, 5 Nov 2021 05:45:55 +0000 (22:45 -0700)]
Simplify the libcxx std::string_view gdb pretty printer

Seems better to rely on the existing formatting, makes the output
smaller/simpler - this is consistent with libstdc++'s std::string_view
pretty printing too.

Differential Revision: https://reviews.llvm.org/D113244

2 years ago[Bazel] Remove old MachO LLD from the Bazel build
Reid Kleckner [Thu, 2 Dec 2021 19:30:26 +0000 (11:30 -0800)]
[Bazel] Remove old MachO LLD from the Bazel build

Updates Bazel files for 9e3552523ebd3385487e01e3e7af37b8c0efaf57

2 years ago[lld-macho] Remove old macho darwin lld
Keith Smiley [Wed, 1 Dec 2021 06:01:07 +0000 (22:01 -0800)]
[lld-macho] Remove old macho darwin lld

During the llvm round table it was generally agreed that the newer macho
lld implementation is feature complete enough to replace the old
implementation entirely. This will reduce confusion for new users who
aren't aware of the history.

Differential Revision: https://reviews.llvm.org/D114842

2 years agoprofi - a flow-based profile inference algorithm: Part II (out of 3)
spupyrev [Thu, 2 Dec 2021 18:19:32 +0000 (10:19 -0800)]
profi - a flow-based profile inference algorithm: Part II (out of 3)

This is a continuation of D109860.

Traditional flow-based algorithms cannot guarantee that the resulting edge
frequencies correspond to a *connected* flow in the control-flow graph. For
example, for an instance in the attached figure, a flow-based (or any other)
inference algorithm may produce an output in which the hot loop is disconnected
from the entry block (refer to the rightmost graph in the figure). Furthermore,
creating a connected minimum-cost maximum flow is a computationally NP-hard
problem. Hence, we apply a post-processing adjustments to the computed flow
by connecting all isolated flow components ("islands").

This feature helps to keep all blocks with sample counts connected and results
in significant performance wins for some binaries.
{F19077343}

Reviewed By: hoy

Differential Revision: https://reviews.llvm.org/D109903

2 years ago[mlir][bufferization] fixed typo in to_memref doc
Aart Bik [Tue, 30 Nov 2021 23:34:23 +0000 (15:34 -0800)]
[mlir][bufferization] fixed typo in to_memref doc

Reviewed By: pifon2a

Differential Revision: https://reviews.llvm.org/D114824

2 years ago[SLP]Fix reused extracts cost.
Alexey Bataev [Thu, 2 Dec 2021 12:22:55 +0000 (04:22 -0800)]
[SLP]Fix reused extracts cost.

If the extractelement instruction is used multiple times in the
different tree entries (either vectorized, or gathered), need to
compensate the scalar cost of such instructions. They are completely
removed if all users are part of the tree but we need to compensate the
cost only once for each instruction.

Differential Revision: https://reviews.llvm.org/D114958

2 years ago[sanitizer] Add delta compression stack depot
Vitaly Buka [Mon, 22 Nov 2021 05:54:08 +0000 (21:54 -0800)]
[sanitizer] Add delta compression stack depot

Compress by factor 4x, takes about 10ms per 8 MiB block.

Depends on D114498.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D114503

2 years ago[sanitizer] Add compress_stack_depot flag
Vitaly Buka [Wed, 24 Nov 2021 00:31:26 +0000 (16:31 -0800)]
[sanitizer] Add compress_stack_depot flag

Depends on D114494.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D114495

2 years ago[ELF] Fix driver.test after 8c3641d0 when cwd is readonly
Reid Kleckner [Thu, 2 Dec 2021 18:19:54 +0000 (10:19 -0800)]
[ELF] Fix driver.test after 8c3641d0 when cwd is readonly

2 years ago[sanitizer] DEFINE_REAL_PTHREAD_FUNCTIONS for hwasan, lsan, msan
Vitaly Buka [Thu, 2 Dec 2021 07:52:31 +0000 (23:52 -0800)]
[sanitizer] DEFINE_REAL_PTHREAD_FUNCTIONS for hwasan, lsan, msan

It should be NFC, as they already intercept pthread_create.

This will let us to fix BackgroundThread for these sanitizerts.
In in followup patches I will fix MaybeStartBackgroudThread for them
and corresponding tests.

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D114935

2 years ago[lldb] Skip two lldb tests on Windows because they are flaky
Stella Stamenova [Thu, 2 Dec 2021 17:53:28 +0000 (09:53 -0800)]
[lldb] Skip two lldb tests on Windows because they are flaky

These tests work fine with VS2017, but become more flaky with VS2019 and the buildbot is about to get upgraded.

Differential Revision: https://reviews.llvm.org/D114907

2 years ago[bazel][mlgo] Remove the mlgo-related build excludes
Mircea Trofin [Thu, 2 Dec 2021 17:50:09 +0000 (09:50 -0800)]
[bazel][mlgo] Remove the mlgo-related build excludes

They aren't needed anymore, we handle conditional compilation in those
files.

Reviewed By: GMNGeoffrey

Differential Revision: https://reviews.llvm.org/D114970

2 years ago[BasicAA] Add tests for strcat/strncat/strcpy.
Florian Hahn [Thu, 2 Dec 2021 17:38:07 +0000 (17:38 +0000)]
[BasicAA] Add tests for strcat/strncat/strcpy.

2 years ago[DSE] Read after strcpy test.
Florian Hahn [Thu, 2 Dec 2021 17:37:59 +0000 (17:37 +0000)]
[DSE] Read after strcpy test.

2 years ago[OpenMP] Remove the new runtime default for AMDGPU
Joseph Huber [Thu, 2 Dec 2021 17:28:21 +0000 (12:28 -0500)]
[OpenMP] Remove the new runtime default for AMDGPU

The new runtime is currently broken for AMD offloading. This patch makes
the default the old runtime only for the AMD target.

Reviewed By: ronlieb

Differential Revision: https://reviews.llvm.org/D114965

2 years ago[llvm] Use range-based for loops (NFC)
Kazu Hirata [Thu, 2 Dec 2021 17:27:47 +0000 (09:27 -0800)]
[llvm] Use range-based for loops (NFC)

2 years ago[llvm] Fix "unused variable" warnings
Kazu Hirata [Thu, 2 Dec 2021 17:20:17 +0000 (09:20 -0800)]
[llvm] Fix "unused variable" warnings

2 years ago[SLP]Outline and fix code for finding common insertelement vectors.
Alexey Bataev [Wed, 1 Dec 2021 18:01:56 +0000 (10:01 -0800)]
[SLP]Outline and fix code for finding common insertelement vectors.

Need to outline the code for finding common vectors in insertelement
instructions into a separate function for future patches. It also
improves the process by adding some extra checks for early exit and
fixes a bug where it always finds the match because of erroneous compare
of the same values.

Differential Revision: https://reviews.llvm.org/D114909

2 years ago[ARM] Introduce i8neg and i8pos addressing modes
David Green [Thu, 2 Dec 2021 17:10:26 +0000 (17:10 +0000)]
[ARM] Introduce i8neg and i8pos addressing modes

Some instructions with i8 immediate ranges can only hold negative values
(like t2LDRHi8), only hold positive values (like t2STRT) or hold +/-
depending on the U bit (like the pre/post inc instructions. e.g
t2LDRH_POST). This patch splits the AddrModeT2_i8 into AddrModeT2_i8,
AddrModeT2_i8pos and AddrModeT2_i8neg to make this clear.

This allows us to get the offset ranges of t2LDRHi8 correct in the
load/store optimizer, fixing issues where we could end up creating
instructions with positive offsets (which may then be encoded as ldrht).

Differential Revision: https://reviews.llvm.org/D114638

2 years ago[clang-cl] Define _MSVC_LANG for -std=c++2b
Nico Weber [Thu, 2 Dec 2021 14:12:50 +0000 (09:12 -0500)]
[clang-cl] Define _MSVC_LANG for -std=c++2b

This matches the value that msvc v19.29 VS16.11 uses for
_MSVC_LANG with /std:c++latest.

Differential Revision: https://reviews.llvm.org/D114952

2 years agoReapply "[TLI checker] Add more tests"
Paul Robinson [Thu, 2 Dec 2021 16:34:16 +0000 (08:34 -0800)]
Reapply "[TLI checker] Add more tests"

This reverts commit 8cd61aac0030b8add686a98b8902ea49ec9c1deb.
I had missed one place in a test that needed updating; it passed on my
dirty build tree but not on a clean one.

Original commit message:

D114478 identified testing gaps; this patch fills them.

Differential Revision: https://reviews.llvm.org/D114913

2 years agotsan: tolerate munmap with invalid arguments
Dmitry Vyukov [Thu, 2 Dec 2021 12:35:04 +0000 (13:35 +0100)]
tsan: tolerate munmap with invalid arguments

We call UnmapShadow before the actual munmap, at that point we don't yet
know if the provided address/size are sane. We can't call UnmapShadow
after the actual munmap becuase at that point the memory range can
already be reused for something else, so we can't rely on the munmap
return value to understand is the values are sane.
While calling munmap with insane values (non-canonical address, negative
size, etc) is an error, the kernel won't crash. We must also try to not
crash as the failure mode is very confusing (paging fault inside of the
runtime on some derived shadow address).

Such invalid arguments are observed on Chromium tests:
https://bugs.chromium.org/p/chromium/issues/detail?id=1275581

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D114944

2 years ago[SLP]Improve registering and merging of compatible shuffles.
Alexey Bataev [Mon, 15 Nov 2021 17:18:27 +0000 (09:18 -0800)]
[SLP]Improve registering and merging of compatible shuffles.

If several shuffle instructions are emitted, some of them might
same/compatible (less defined) with the previously emitted ones. Such
shuffles can be removed safely, improving the total cost of the
vectorized code.

Differential Revision: https://reviews.llvm.org/D114087

2 years agotsan: fix false positives in dynamic libs with static tls
Dmitry Vyukov [Thu, 2 Dec 2021 14:15:14 +0000 (15:15 +0100)]
tsan: fix false positives in dynamic libs with static tls

The added test demonstrates  loading a dynamic library with static TLS.
Such static TLS is a hack that allows a dynamic library to have faster TLS,
but it can be loaded only iff all threads happened to allocate some excess
of static TLS space for whatever reason. If it's not the case loading fails with:

dlopen: cannot load any more object with static TLS

We used to produce a false positive because dlopen will write into TLS
of all existing threads to initialize/zero TLS region for the loaded library.
And this appears to be racing with initialization of TLS in the thread
since we model a write into the whole static TLS region (we don't what part
of it is currently unused):

WARNING: ThreadSanitizer: data race (pid=2317365)
  Write of size 1 at 0x7f1fa9bfcdd7 by main thread:
    0 memset
    1 init_one_static_tls
    2 __pthread_init_static_tls
    [[ this is where main calls dlopen ]]
    3 main
  Previous write of size 8 at 0x7f1fa9bfcdd0 by thread T1:
    0 __tsan_tls_initialization

Fix this by ignoring accesses during dlopen.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D114953

2 years ago[lld][WebAssembly] Fix for debug relocations against undefined function symbols
Sam Clegg [Thu, 2 Dec 2021 02:10:37 +0000 (18:10 -0800)]
[lld][WebAssembly] Fix for debug relocations against undefined function symbols

This is very similar to https://reviews.llvm.org/D103557 but applies to
symbols which are undefined at link time rather than compile time.

We already have code that handles symbols which were defined at link
time but dead stripped by `--gc-sections` (See
`test/wasm/debug-removed-fn.ll`). In that case the symbols are not live
(!isLive()).  However, we can also have live symbols (which are
references by the program) but which are undefined at link time and are
imported by the linker.

In the test case here the symbol `undef` is used but is not defined
in the program but is imported by the linker due to the
`--import-undefined` flag.

Fixes: https://github.com/emscripten-core/emscripten/issues/15528

Differential Revision: https://reviews.llvm.org/D114921

2 years agoRevert "[TLI checker] Add more tests"
Paul Robinson [Thu, 2 Dec 2021 16:30:47 +0000 (08:30 -0800)]
Revert "[TLI checker] Add more tests"

This reverts commit 2778554971dada8ef7df9ee6954c52a753d90c22.

Some bots are failing on the updated tests.

2 years ago[clang] Do not duplicate "EnableSplitLTOUnit" module flag
David Greene [Wed, 6 Oct 2021 19:10:08 +0000 (12:10 -0700)]
[clang] Do not duplicate "EnableSplitLTOUnit" module flag

If clang's output is set to bitcode and LTO is enabled, clang would
unconditionally add the flag to the module.  Unfortunately, if the input were a
bitcode or IR file and had the flag set, this would result in two copies of the
flag, which is illegal IR.  Guard the setting of the flag by checking whether it
already exists.  This follows existing practice for the related "ThinLTO" module
flag.

Differential Revision: https://reviews.llvm.org/D112177

2 years ago[TLI checker] Add more tests
Paul Robinson [Wed, 1 Dec 2021 22:56:00 +0000 (14:56 -0800)]
[TLI checker] Add more tests

D114478 identified testing gaps; this patch fills them.

Differential Revision: https://reviews.llvm.org/D114913

2 years ago[OpenMP] Make the new device runtime the default
Joseph Huber [Wed, 1 Dec 2021 18:14:40 +0000 (13:14 -0500)]
[OpenMP] Make the new device runtime the default

This patch changes the `-fopenmp-target-new-runtime` option which controls if
the new or old device runtime is used to be true by default.  Disabling this to
use the old runtime now requires using `-fno-openmp-target-new-runtime`.

Reviewed By: JonChesterfield, tianshilei1992, gregrodgers, ronlieb

Differential Revision: https://reviews.llvm.org/D114890

2 years ago[InstCombine] add tests for icmp with mul op; NFC
Sanjay Patel [Thu, 2 Dec 2021 15:30:06 +0000 (10:30 -0500)]
[InstCombine] add tests for icmp with mul op; NFC

2 years ago[clangd] cleanup of header guard names
Christian Kühnel [Thu, 2 Dec 2021 13:43:13 +0000 (13:43 +0000)]
[clangd] cleanup of header guard names

Renaming header guards to match the LLVM convention.
This patch was created by automatically applying the fixes from
clang-tidy.

I've removed the [NFC]  tag from the title, as we're adding header guards in some files and thus might trigger behavior changes.

Differential Revision: https://reviews.llvm.org/D113896

2 years ago[Clang] Fix LTO pipeline test after 770a50b28c00211f9a.
Florian Hahn [Thu, 2 Dec 2021 15:41:31 +0000 (15:41 +0000)]
[Clang] Fix LTO pipeline test after 770a50b28c00211f9a.

2 years ago[AnnotationRemarks] Support generating annotation remarks with -O0.
Florian Hahn [Thu, 2 Dec 2021 14:50:14 +0000 (14:50 +0000)]
[AnnotationRemarks] Support generating annotation remarks with -O0.

This matches the legacy pass manager behavior. If remarks are not
enabled the pass is effectively a no-op.

2 years ago[clang-tidy] Fix build broken by commit 6a9487df73e917c4faf5e060f2bb33c6ade3f967...
Yitzhak Mandelbaum [Thu, 2 Dec 2021 14:41:00 +0000 (14:41 +0000)]
[clang-tidy] Fix build broken by commit 6a9487df73e917c4faf5e060f2bb33c6ade3f967 (D113148)

2 years ago[SLP][NFC]Add a test for extractelements with many uses vectorization, NFC.
Alexey Bataev [Thu, 2 Dec 2021 14:29:27 +0000 (06:29 -0800)]
[SLP][NFC]Add a test for extractelements with many uses vectorization, NFC.

2 years ago[AMDGPU] Add support for in-order bvh in waitcnt pass
David Stuttard [Tue, 30 Nov 2021 09:29:14 +0000 (09:29 +0000)]
[AMDGPU] Add support for in-order bvh in waitcnt pass

bvh should be handled separately from vmem and vmem with sampler instructions
for waitcnt handling.

Differential Revision: https://reviews.llvm.org/D114794

2 years ago[AMDGPU] Test for in-order waitcnt insertion for bvh instructions
David Stuttard [Tue, 30 Nov 2021 09:29:14 +0000 (09:29 +0000)]
[AMDGPU] Test for in-order waitcnt insertion for bvh instructions

In-order bvh instructions don't require a waitcnt as order is
guaranteed.

However, waitcnt IS required for other image instruction types vs
bvh.

Pre-commit test for new functionality in https://reviews.llvm.org/D114794

Differential Revision: https://reviews.llvm.org/D114792

2 years ago[VE][NFC] Cleanup redundant namespace wrapper
Simon Moll [Thu, 2 Dec 2021 12:59:24 +0000 (13:59 +0100)]
[VE][NFC] Cleanup redundant namespace wrapper

2 years ago[MemoryLocation] Support strncpy in getForArgument.
Florian Hahn [Thu, 2 Dec 2021 14:18:04 +0000 (14:18 +0000)]
[MemoryLocation] Support strncpy in getForArgument.

The size argument of strncpy can be used as bound for the size of
its pointer arguments.

strncpy is guaranteed to write N bytes and reads up to N bytes.

Reviewed By: xbolva00

Differential Revision: https://reviews.llvm.org/D114871

2 years ago[libc] Fix a bug in MPFRUtils making ULP values off by 2^(-mantissaWidth).
Tue Ly [Wed, 1 Dec 2021 15:24:57 +0000 (10:24 -0500)]
[libc] Fix a bug in MPFRUtils making ULP values off by 2^(-mantissaWidth).

Fix a bug in MPFRUtils making ULP values off by 2^(-mantissaWidth) and incorrect eps for denormal numbers.

Differential Revision: https://reviews.llvm.org/D114878

2 years ago[PatternMatch] create and use matcher for 'not' that excludes undef elements
Sanjay Patel [Wed, 1 Dec 2021 22:21:19 +0000 (17:21 -0500)]
[PatternMatch] create and use matcher for 'not' that excludes undef elements

We needed a stricter version of m_Not for D114462, but I wasn't
sure if that was going to be required anywhere else, so I didn't bother
to make that reusable.

It turns out we have one more existing simplification that needs
this (currently miscompiles):
https://alive2.llvm.org/ce/z/9-nTKi

And there's at least one more fold in that family that we could add.

Differential Revision: https://reviews.llvm.org/D114882

2 years ago[MemoryLocation] Support memset_chk in getForArgument.
Florian Hahn [Thu, 2 Dec 2021 13:45:58 +0000 (13:45 +0000)]
[MemoryLocation] Support memset_chk in getForArgument.

The size argument for memset_chk is an upper bound for the size of the
pointer argument. memset_chk may write less than the specified length,
if it exceeds the specified max size and aborts.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D114870

2 years ago[gn build] Port 6a9487df73e9
LLVM GN Syncbot [Thu, 2 Dec 2021 13:40:22 +0000 (13:40 +0000)]
[gn build] Port 6a9487df73e9

2 years ago[flang] GettingInvolved: update LLVM Alias Analysis Technical Call info
Jeroen Dobbelaere [Thu, 2 Dec 2021 13:36:11 +0000 (14:36 +0100)]
[flang] GettingInvolved: update LLVM Alias Analysis Technical Call info

The google doc was changed and the calls are now using teams.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D114145

2 years ago[HIPSPV] Add CUDA->SPIR-V address space mapping
Anastasia Stulova [Thu, 2 Dec 2021 13:30:05 +0000 (13:30 +0000)]
[HIPSPV] Add CUDA->SPIR-V address space mapping

Add mapping for CUDA address spaces for HIP to SPIR-V
translation. This change allows HIP device code to be
emitted as valid SPIR-V by mapping unqualified pointers
to generic address space and by mapping __device__ and
__shared__ AS to their equivalent AS in SPIR-V
(CrossWorkgroup and Workgroup, respectively).

Cuda's __constant__ AS is handled specially. In HIP
unqualified pointers (aka "flat" pointers) can point to
__constant__ objects. Mapping this AS to ConstantMemory
would produce to illegal address space casts to
generic AS. Therefore, __constant__ AS is mapped to
CrossWorkgroup.

Patch by linjamaki (Henry Linjamäki)!

Differential Revision: https://reviews.llvm.org/D108621

2 years agoFix documentation for `forEachLambdaCapture` and `hasAnyCapture`
James King [Thu, 2 Dec 2021 13:27:33 +0000 (13:27 +0000)]
Fix documentation for `forEachLambdaCapture` and `hasAnyCapture`

Updates the return types of these matchers' definitions to use
`internal::Matcher<LambdaCapture>` instead of `LambdaCaptureMatcher`. This
ensures that they are categorized as traversal matchers, instead of narrowing
matchers.

Reviewed By: ymandel, tdl-g, aaron.ballman

Differential Revision: https://reviews.llvm.org/D114809

2 years agoAdd new clang-tidy check for string_view(nullptr)
CJ Johnson [Thu, 2 Dec 2021 13:17:12 +0000 (13:17 +0000)]
Add new clang-tidy check for string_view(nullptr)

Checks for various ways that the `const CharT*` constructor of `std::basic_string_view` can be passed a null argument and replaces them with the default constructor in most cases. For the comparison operators, braced initializer list does not compile so instead a call to `.empty()` or the empty string literal are used, where appropriate.

This prevents code from invoking behavior which is unconditionally undefined. The single-argument `const CharT*` constructor does not check for the null case before dereferencing its input. The standard is slated to add an explicitly-deleted overload to catch some of these cases: wg21.link/p2166

https://reviews.llvm.org/D114823 is a companion change to prevent duplicate warnings from the `bugprone-string-constructor` check.

Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D113148

2 years ago[fir] Declare test function inline
Valentin Clement [Thu, 2 Dec 2021 13:17:28 +0000 (14:17 +0100)]
[fir] Declare test function inline

Declare functions checkCallOp and checkCallOpFromResultBox inline due to buildbot failure flang-aarch64-latest-clang

2 years agoExpand testing of necessary features for print-changed=dot-cfg.
Jamie Schmeiser [Thu, 2 Dec 2021 13:16:18 +0000 (08:16 -0500)]
Expand testing of necessary features for print-changed=dot-cfg.

Summary:
Expand the testing for whether the lit tests for print-changed=dot-cfg
are supported to include checking whether dot supports pdf output.

Author: Jamie Schmeiser <schmeise@ca.ibm.com>
Reviewed By: hvdijk (Harald van Dijk)
Differential Revision: https://reviews.llvm.org/D113187

2 years ago[AArch64][SVE] Enable bf16 vector.insert
Matt Devereau [Tue, 30 Nov 2021 15:10:06 +0000 (15:10 +0000)]
[AArch64][SVE] Enable bf16 vector.insert

Allow passthrough bf16 registers for vector.insert

Differential revision: https://reviews.llvm.org/D114858

2 years ago[VE][Clang][NFC] Disable VE toolchain tests on Windows
Simon Moll [Thu, 2 Dec 2021 12:33:46 +0000 (13:33 +0100)]
[VE][Clang][NFC] Disable VE toolchain tests on Windows

VE hardware is unsupported under Windows. Disable the clang VE toolchain
tests here. Tests breaking because of non-POSIX path separators.

2 years agoReland "[LICM] Hoist LOAD without sinking the STORE"
Djordje Todorovic [Thu, 2 Dec 2021 11:40:00 +0000 (03:40 -0800)]
Reland "[LICM] Hoist LOAD without sinking the STORE"

When doing load/store promotion within LICM, if we
cannot prove that it is safe to sink the store we won't
hoist the load, even though we can prove the load could
be dereferenced and moved outside the loop. This patch
implements the load promotion by moving it in the loop
preheader by inserting proper PHI in the loop. The store
is kept as is in the loop. By doing this, we avoid doing
the load from a memory location in each iteration.

Please consider this small example:

loop {
  var = *ptr;
  if (var) break;
  *ptr= var + 1;
}
After this patch, it will be:

var0 = *ptr;
loop {
  var1 = phi (var0, var2);
  if (var1) break;
  var2 = var1 + 1;
  *ptr = var2;
}
This addresses some problems from [0].

[0] https://bugs.llvm.org/show_bug.cgi?id=51193

Differential revision: https://reviews.llvm.org/D113289

2 years ago[BasicAA] Add tests for memset_pattern{4,8,16}.
Florian Hahn [Thu, 2 Dec 2021 11:50:32 +0000 (11:50 +0000)]
[BasicAA] Add tests for memset_pattern{4,8,16}.

This also removes the existing memset_pattern.ll test, which was relying
on GVN. It is also covered by the new test directly.

2 years ago[DAG][PowerPC] Enable initial ISD::BITCAST SimplifyDemandedBits/SimplifyMultipleUseDe...
Simon Pilgrim [Thu, 2 Dec 2021 11:47:43 +0000 (11:47 +0000)]
[DAG][PowerPC] Enable initial ISD::BITCAST SimplifyDemandedBits/SimplifyMultipleUseDemandedBits big-endian handling

This patch begins extending handling for peeking through bitcast nodes to big-endian targets as well as the existing little-endian case.

Differential Revision: https://reviews.llvm.org/D114676

2 years ago[LICM] Adding the test as a precommit for the D113289
Djordje Todorovic [Thu, 2 Dec 2021 11:31:53 +0000 (03:31 -0800)]
[LICM] Adding the test as a precommit for the D113289

2 years ago[ARM] Correct range in isLegalAddressImm
David Green [Thu, 2 Dec 2021 11:33:40 +0000 (11:33 +0000)]
[ARM] Correct range in isLegalAddressImm

The ranges in isLegalAddressImm were off by one, not allowing the
maximum values for unscaled offsets.

Differential Revision: https://reviews.llvm.org/D114636

2 years ago[llvm-readobj] Add support for machine-independent NetBSD ELF core notes.
Frederic Cambus [Mon, 29 Nov 2021 07:04:04 +0000 (08:04 +0100)]
[llvm-readobj] Add support for machine-independent NetBSD ELF core notes.

Notes generated in NetBSD core files provide additional information about
processes. These notes are described in core.5, which can be viewed here:
https://man.netbsd.org/core.5

Differential Revision: https://reviews.llvm.org/D114635

2 years ago[BuildLibCalls] Add support for memset_pattern{4,8}.
Florian Hahn [Thu, 2 Dec 2021 11:04:25 +0000 (11:04 +0000)]
[BuildLibCalls] Add support for memset_pattern{4,8}.

Add support for memset_pattern{4,8} similar to the existing
memset_pattern16 handling.

Reviewed By: ab

Differential Revision: https://reviews.llvm.org/D114883

2 years ago[GlobalOpt] Fix assertion failure during instruction deletion
Nikita Popov [Thu, 2 Dec 2021 10:55:56 +0000 (11:55 +0100)]
[GlobalOpt] Fix assertion failure during instruction deletion

This fixes the assertion failure reported in https://reviews.llvm.org/D114889#3166417,
by making RecursivelyDeleteTriviallyDeadInstructionsPermissive()
more permissive. As the function accepts a WeakTrackingVH, even if
originally only Instructions were inserted, we may end up with
different Value types after a RAUW operation. As such, we should
not assume that the vector only contains instructions.

Notably this matches the behavior of the
RecursivelyDeleteTriviallyDeadInstructions() function variant which
accepts a single value rather than vector.

2 years agoUse cc/c++ instead of gcc/g++ on FreeBSD.
Frederic Cambus [Wed, 24 Nov 2021 12:59:46 +0000 (13:59 +0100)]
Use cc/c++ instead of gcc/g++ on FreeBSD.

All supported FreeBSD platforms do not have GCC in base anymore.

Differential Revision: https://reviews.llvm.org/D114530

2 years ago[ARM] Add additional postinc distribute tests and regenerate tests. NFC
David Green [Thu, 2 Dec 2021 10:40:10 +0000 (10:40 +0000)]
[ARM] Add additional postinc distribute tests and regenerate tests. NFC

2 years ago[Flang] Replace notifyMatchFailure with TODO hard failures
Kiran Chandramohan [Wed, 1 Dec 2021 22:12:12 +0000 (22:12 +0000)]
[Flang] Replace notifyMatchFailure with TODO hard failures

For unimplemented patterns we revert to using TODO hard failures instead of
notifyMatchFailure.

For fir.select_type revert to using mlir::emiterror.
For the fir.embox TODO on a type with len params we cannot add a test since the type cannot be converted to llvm.

Adding negative tests using not and checking for the error message.
TODO exits with an error in a build without assertion but aborts in a
build with assertions. Abort requires using not with the --crash
option. The two different usages of not is handled by using a custom
command %not_todo_cmd which is converted to not or not --crash
depending on the presence or absence of assertions. Using llvm-config
to check the presence of assertions.

Reviewed By: clementval, awarzynski

Differential Revision: https://reviews.llvm.org/D114371

2 years agoRevert "Revert "[VE] Make VE official""
Simon Moll [Thu, 2 Dec 2021 10:17:47 +0000 (11:17 +0100)]
Revert "Revert "[VE] Make VE official""

This reverts commit 27c9e8b45b25614a92539ac6787dbb5670d950b3.

Bugs exposed by AddressSanitizer have been reproduced and fixed locally:
* commit e37000f3bff384
* commit 435d44bf8ab392

2 years ago[InferAttrs] Add memset_pattern{4,8} declarations to test.
Florian Hahn [Thu, 2 Dec 2021 10:11:54 +0000 (10:11 +0000)]
[InferAttrs] Add memset_pattern{4,8} declarations to test.

2 years ago[ELF] Discard input .note.gnu.build-id even with default --build-id=none
Fangrui Song [Thu, 2 Dec 2021 05:02:19 +0000 (05:02 +0000)]
[ELF] Discard input .note.gnu.build-id even with default --build-id=none

binutils 2.38 will adopt this behavior
https://sourceware.org/bugzilla/show_bug.cgi?id=28639

Reviewed By: ikudrin

Differential Revision: https://reviews.llvm.org/D114910

2 years ago[BuildLibCalls] Add additional attrs to memcpy_chk.
Florian Hahn [Thu, 2 Dec 2021 09:50:14 +0000 (09:50 +0000)]
[BuildLibCalls] Add additional attrs to memcpy_chk.

`memcpy_chk` can be treated like `memcpy`, with the exception that it
may not return (if it aborts the program).

See D114793 for a similar patch for `memset_chk`.

Reviewed By: xbolva00

Differential Revision: https://reviews.llvm.org/D114863

2 years ago[VE][NFC] Fix use-after-free in PVFMK expansion
Simon Moll [Thu, 2 Dec 2021 09:35:01 +0000 (10:35 +0100)]
[VE][NFC] Fix use-after-free in PVFMK expansion

There is custom expansion code for packed VFMK Pseudos in the VE
backend.  This code erased the Pseudo without telling
ExpandPostRAPseudos about it, causing the generic expansion function to
access the erased Pseudo.  This bug triggered in the
test/CodeGen/VE/VELIntrinsics/vfmk.ll test with asan-enabled builds.

Detected by:
sanitizer-x86_64-linux-fast
(https://lab.llvm.org/buildbot/#/builders/5/builds/15393)

2 years ago[ORC] Fix ambiguous call to overloaded function.
Lang Hames [Thu, 2 Dec 2021 09:40:16 +0000 (20:40 +1100)]
[ORC] Fix ambiguous call to overloaded function.

This should fix the build failure at
https://lab.llvm.org/buildbot#builders/110/builds/8359

2 years ago[clangd] IncludeClenaer: Don't mark forward declarations of a class if it's declared...
Kirill Bobyrev [Thu, 2 Dec 2021 09:21:19 +0000 (10:21 +0100)]
[clangd] IncludeClenaer: Don't mark forward declarations of a class if it's declared in the main file

This will mark more headers that are unrelated to used symbol but contain its
forawrd declaration. E.g. the following are examples of headers forward
declaring `llvm::StringRef`:

- clang/include/clang/Basic/Cuda.h
- llvm/include/llvm/Support/SHA256.h
- llvm/include/llvm/Support/TrigramIndex.h
- llvm/include/llvm/Support/RandomNumberGenerator.
- ... and more (~50 in total)

This patch is a reduced version of D112707 which was controversial.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D114864

2 years ago[fir] Add fir numeric intrinsic runtime call builder
Valentin Clement [Thu, 2 Dec 2021 09:18:38 +0000 (10:18 +0100)]
[fir] Add fir numeric intrinsic runtime call builder

This patch adds the FIR builder to generate the numeric intrinsic
runtime call.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: rovka

Differential Revision: https://reviews.llvm.org/D114477

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: mleair <leairmark@gmail.com>
2 years ago[llvm-c] Make LLVMAddAlias opaque pointer compatible
Nikita Popov [Wed, 1 Dec 2021 11:12:35 +0000 (12:12 +0100)]
[llvm-c] Make LLVMAddAlias opaque pointer compatible

Deprecate LLVMAddAlias in favor of LLVMAddAlias2, which accepts a
value type and an address space. Previously these were extracted
from the pointer type.

Differential Revision: https://reviews.llvm.org/D114860

2 years ago[GlobalOpt] Add test for PR39751 (NFC)
Nikita Popov [Thu, 2 Dec 2021 08:13:20 +0000 (09:13 +0100)]
[GlobalOpt] Add test for PR39751 (NFC)

This has been fixed by D114889, as noted in the comments.

2 years ago[clang-format] Add better support for co-routinues
mydeveloperday [Thu, 2 Dec 2021 08:05:30 +0000 (08:05 +0000)]
[clang-format] Add better support for co-routinues

Responding to a Discord call to help {D113977} and heavily inspired by the unlanded {D34225} add some support to help coroutinues from not being formatted from

```for co_await(auto elt : seq)```

to

```
for
co_await(auto elt : seq)
```

Because of the dominance of clang-format in the C++ community, I don't think we should make it the blocker that prevents users from embracing the newer parts of the standard because we butcher the layout of some of the new constucts.

Reviewed By: HazardyKnusperkeks, Quuxplusone, ChuanqiXu

Differential Revision: https://reviews.llvm.org/D114859

2 years ago[NFC][sanitizer] Check &real_pthread_join
Vitaly Buka [Thu, 2 Dec 2021 07:55:04 +0000 (23:55 -0800)]
[NFC][sanitizer] Check &real_pthread_join

It's a weak function which may be undefined.

2 years ago[openmp][amdgpu] Disable three tests in preparation for new runtime
Jon Chesterfield [Thu, 2 Dec 2021 07:57:01 +0000 (07:57 +0000)]
[openmp][amdgpu] Disable three tests in preparation for new runtime

2 years ago[ARM] Teach getIntImmCostInst about the cost of saturating fp converts
David Green [Thu, 2 Dec 2021 07:56:27 +0000 (07:56 +0000)]
[ARM] Teach getIntImmCostInst about the cost of saturating fp converts

Given a min(max(fptosi, INT_MIN), INT_MAX) with the correct constants,
we can now generate a fptosi.sat. But in the arm backend, the constant
can be treated as high cost, pulling it out of the basic block in a way
that the DAG combine can no longer see it. This teaches it again that it
is a low cost constant, not worth hoisting out.

Recommitted from 0e98659ea1193c with a fix for APInt comparison.

Differential Revision: https://reviews.llvm.org/D114380

2 years ago[ORC] Add support for removing JITDylibs.
Lang Hames [Tue, 30 Nov 2021 03:46:15 +0000 (14:46 +1100)]
[ORC] Add support for removing JITDylibs.

This allows JITDylibs to be removed from the ExecutionSession. Calling
ExecutionSession::removeJITDylib will disconnect the JITDylib from the
ExecutionSession and clear it (removing all trackers associated with it). The
JITDylib object will then be destroyed as soon as the last JITDylibSP pointing
at it is destroyed.

2 years ago[ORC] Only use JITDylib::GeneratorsMutex while running generators.
Lang Hames [Fri, 26 Nov 2021 01:13:11 +0000 (12:13 +1100)]
[ORC] Only use JITDylib::GeneratorsMutex while running generators.

GeneratorsMutex should prevent lookups from proceeding through the
generators of a single JITDylib concurrently (since this could
result in redundant attempts to generate definitions). Mutation of
the generators list itself should be done under the session lock.

2 years ago[ORC] Hold ResourceTracker in MaterializationResponsibility.
Lang Hames [Wed, 1 Dec 2021 23:48:50 +0000 (10:48 +1100)]
[ORC] Hold ResourceTracker in MaterializationResponsibility.

This keeps the tracker alive for the lifetime of the MR. This is needed so that
we can check whether the tracker has become defunct before posting results (or
failure) for the MR.

2 years ago[AMDGPU] Set most sched model resource's BufferSize to one
Austin Kerbow [Wed, 10 Nov 2021 17:59:31 +0000 (09:59 -0800)]
[AMDGPU] Set most sched model resource's BufferSize to one

Using a BufferSize of one for memory ProcResources will result in better
ILP since it more accurately models the dependencies between memory ops
and their consumers on an in-order processor. After this change, the
scheduler will treat the data edges from loads as blocking so that
stalls are guaranteed when waiting for data to be retreaved from memory.
Since we don't actually track waitcnt here, this should do a better job
at modeling their behavior.

Practically, this means that the scheduler will trigger the 'STALL'
heuristic more often.

This type of change needs to be evaluated experimentally. Preliminary
results are positive.

Fixes: SWDEV-282962

Reviewed By: rampitec

Differential Revision: https://reviews.llvm.org/D114777

2 years ago[AMDGPU][clang] Fix __builtin_nontemporal_store() failure on AMDGPU
skc7 [Wed, 1 Dec 2021 06:12:57 +0000 (06:12 +0000)]
[AMDGPU][clang] Fix  __builtin_nontemporal_store() failure on AMDGPU

Reviewed By: yaxunl, sameerds

Differential Revision: https://reviews.llvm.org/D114849

2 years ago[X86][FP16] Only generate approximate rsqrt when Reciprocal is true for half type
Phoebe Wang [Thu, 2 Dec 2021 05:11:07 +0000 (13:11 +0800)]
[X86][FP16] Only generate approximate rsqrt when Reciprocal is true for half type

We have reasonable fast sqrt and accurate rsqrt for half type due to the
limited fractions. So neither do we need multi steps refinement for
rsqrt nor replace sqrt by rsqrt.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D114844

2 years ago[X86] Insert FMUL for estimated non reciprocal SQRT when `RefinementSteps` = 0
Phoebe Wang [Thu, 2 Dec 2021 05:10:57 +0000 (13:10 +0800)]
[X86] Insert FMUL for estimated non reciprocal SQRT when `RefinementSteps` = 0

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D114843

2 years ago[lldb] Skip test_launch_scripted_process_stack_frames with ASan
Jonas Devlieghere [Thu, 2 Dec 2021 05:33:40 +0000 (21:33 -0800)]
[lldb] Skip test_launch_scripted_process_stack_frames with ASan

This test is failing on the sanitized bot because of a
heap-use-after-free. Disabling the test to turn the bot
green again.

rdar://85954489.

2 years ago[ELF] Prevent internalizing used comdat symbol
Igor Kudrin [Thu, 2 Dec 2021 05:10:07 +0000 (12:10 +0700)]
[ELF] Prevent internalizing used comdat symbol

When a comdat symbol is defined in both bitcode and regular object
files, which are contained in the same archive, the linker could lose
the flag that the symbol is used in the regular object file and allow
LTO to internalize it, which led to "error: undefined symbol".

The issue was introduced in D79300.

Differential Revision: https://reviews.llvm.org/D114801

2 years ago[mlir][drr] Simple heuristic to reduce chance of accidental nullptr dereference
Jacques Pienaar [Thu, 2 Dec 2021 04:45:08 +0000 (20:45 -0800)]
[mlir][drr] Simple heuristic to reduce chance of accidental nullptr dereference

When an attribute is optional & is given an additional constraint in
rewrite pattern that could lead to dereferencing null Attribute. Avoid
cases where the constraints checks attribute but has no check if null.

This should be improved to be more uniformly guarded.

2 years ago[AMDGPU] Add a regclass flag for scalar registers
Christudasan Devadasan [Sat, 18 Sep 2021 06:46:02 +0000 (02:46 -0400)]
[AMDGPU] Add a regclass flag for scalar registers

Along with vector RC flags, this scalar flag will
make various regclass queries like `isVGPR` more
accurate.

Regclasses other than vectors are currently set
with the new flag even though certain unallocatable
classes aren't truly scalars. It would be ok as long
as they remain unallocatable.

Reviewed By: rampitec

Differential Revision: https://reviews.llvm.org/D110053

2 years ago[libc++] Implement P1989R2: range constructor for string_view
Joe Loser [Wed, 3 Nov 2021 22:45:04 +0000 (18:45 -0400)]
[libc++] Implement P1989R2: range constructor for string_view

Implement P1989R2 which adds a range constructor for `string_view`.

Adjust `operator/=` in `path` to avoid atomic constraints caching issue
getting provoked from this PR.

Add defaulted template argument to `string_view`'s "sufficient
overloads" to avoid mangling issues in `clang-cl` builds. It is a
MSVC mangling bug that this works around.

Differential Revision: https://reviews.llvm.org/D113161