platform/upstream/llvm.git
2 years ago[analyzer] Ignore IncompleteArrayTypes in getStaticSize() for FAMs
Balazs Benics [Wed, 25 Aug 2021 14:12:17 +0000 (16:12 +0200)]
[analyzer] Ignore IncompleteArrayTypes in getStaticSize() for FAMs

Currently only `ConstantArrayType` is considered for flexible array
members (FAMs) in `getStaticSize()`.
However, `IncompleteArrayType` also shows up in practice as FAMs.

This patch will ignore the `IncompleteArrayType` and return Unknown
for that case as well. This way it will be at least consistent with
the current behavior until we start modeling them accurately.

I'm expecting that this will resolve a bunch of false-positives
internally, caused by the `ArrayBoundV2`.

Reviewed By: ASDenysPetrov

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

2 years ago[libomptarget][amdgpu][nfc] Make grid value access match devicertl
Jon Chesterfield [Wed, 25 Aug 2021 14:09:46 +0000 (15:09 +0100)]
[libomptarget][amdgpu][nfc] Make grid value access match devicertl

2 years ago[DebugInfo][InstrRef] Don't use instr-ref for unoptimised functions
Jeremy Morse [Wed, 25 Aug 2021 13:56:05 +0000 (14:56 +0100)]
[DebugInfo][InstrRef] Don't use instr-ref for unoptimised functions

InstrRefBasedLDV is marginally slower than VarlocBasedLDV when analysing
optimised code -- however, it's much slower when analysing code compiled
-O0.

To avoid this: don't use instruction referencing for -O0 functions. In the
"pure" case of unoptimised code, this won't really harm the debugging
experience because most variables won't have been promoted off the stack,
so can't go missing. It becomes more complicated when optimised code is
inlined into functions marked optnone; however these are rare, and as -O0
doesn't run many optimisations there should be little damage to the debug
experience as a result.

I've taken the opportunity to refactor testing for instruction-referencing
into a MachineFunction method, which seems the most appropriate place to
put it.

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

2 years ago[libomptarget][amdgpu] Refactor debug printing
Jon Chesterfield [Wed, 25 Aug 2021 13:57:50 +0000 (14:57 +0100)]
[libomptarget][amdgpu] Refactor debug printing

Move most debug printing in rtl.cpp behind DP() macro
Adjust the print output for gpu arch mismatch when the architectures match
Convert an assert into graceful failure

Reviewed By: jdoerfert

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

2 years ago[AMDGPU] Support global_atomic_fmin/max on gfx10
Joe Nash [Tue, 24 Aug 2021 18:40:04 +0000 (14:40 -0400)]
[AMDGPU] Support global_atomic_fmin/max on gfx10

Makes patterns added for gfx90a usable with the gfx10 versions of the
insts.

Reviewed By: rampitec

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

Change-Id: I86167bf6b4823f975f74ccb619bd6190331ba16b

2 years ago[X86][NFC] Pre-commit llvm-mca tests for PR51495.
Andrea Di Biagio [Wed, 25 Aug 2021 13:15:17 +0000 (14:15 +0100)]
[X86][NFC] Pre-commit llvm-mca tests for PR51495.

WriteIMulH reports an incorrect latency for RM variants of MULX.

2 years ago[libc++] Assume that compilers support extended constexpr in C++14 mode
Louis Dionne [Tue, 24 Aug 2021 15:58:36 +0000 (11:58 -0400)]
[libc++] Assume that compilers support extended constexpr in C++14 mode

We don't support any compiler that doesn't support C++14 constexpr when
compiling in C++14 mode anymore, so we can just assume that we have C++14
extended constexpr when compiling in C++14 mode. This allows us to remove
some workarounds for older compilers.

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

2 years ago[LoopPeel] Allow peeling with multiple unreachable-terminated exit blocks.
Florian Hahn [Wed, 25 Aug 2021 10:58:49 +0000 (11:58 +0100)]
[LoopPeel] Allow peeling with multiple unreachable-terminated exit blocks.

Support for peeling with multiple exit blocks was added in D63921/77bb3a486fa6.

So far it has only been enabled for loops where all non-latch exits are
'de-optimizing' exits (D63923). But peeling of multi-exit loops can be
highly beneficial in other cases too, like if all non-latch exiting
blocks are unreachable.

The motivating case are loops with runtime checks, like the C++ example
below. The main issue preventing vectorization is that the invariant
accesses to load the bounds of B is conditionally executed in the loop
and cannot be hoisted out. If we peel off the first iteration, they
become dereferenceable in the loop, because they must execute before the
loop is executed, as all non-latch exits are terminated with
unreachable. This subsequently allows hoisting the loads and runtime
checks out of the loop, allowing vectorization of the loop.

     int sum(std::vector<int> *A, std::vector<int> *B, int N) {
       int cost = 0;
       for (int i = 0; i < N; ++i)
         cost += A->at(i) + B->at(i);
       return cost;
     }

This gives a ~20-30% increase of score for Geekbench5/HDR on AArch64.

Note that this requires a follow-up improvement to the peeling cost
model to actually peel iterations off loops as above. I will share that
shortly.

Also, peeling of multi-exits might be beneficial for exit blocks with
other terminators, but I would like to keep the scope limited to known
high-reward cases for now.

I removed the option to disable peeling for multi-deopt exits because
the code is more general now. Alternatively, the option could also be
generalized, but I am not sure if there's much value in the option?

Reviewed By: reames

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

2 years ago[LoopIdiom] Don't transform loop into memmove when load from body has more than one use
Dawid Jurczak [Wed, 25 Aug 2021 11:13:18 +0000 (13:13 +0200)]
[LoopIdiom] Don't transform loop into memmove when load from body has more than one use

This change fixes issue found by Markus: https://reviews.llvm.org/rG11338e998df1
Before this patch following code was transformed to memmove:

for (int i = 15; i >= 1; i--) {
  p[i] = p[i-1];
  sum += p[i-1];
}

However load from p[i-1] is used not only by store to p[i] but also by sum computation.
Therefore we cannot emit memmove in loop header.

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

2 years ago[clang-format] Support TypeScript override keyword
Jan Kuehle [Wed, 25 Aug 2021 12:11:43 +0000 (14:11 +0200)]
[clang-format] Support TypeScript override keyword

TypeScript 4.3 added a new "override" keyword for class members. This
lets clang-format know about it, so it can format code using it
properly.

Reviewed By: krasimir

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

2 years ago[DAGCombine] Check the legality of the index of EXTRACT_SUBVECTOR
Peilin Guo [Wed, 25 Aug 2021 11:31:00 +0000 (19:31 +0800)]
[DAGCombine] Check the legality of the index of EXTRACT_SUBVECTOR

For ISD::EXTRACT_SUBVECTOR, its second operand must be a constant
multiple of the known-minimum vector length of the result type.

Reviewed By: dmgreen

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

2 years ago[DebugInfo][InstrRef] Avoid stack-slot-coloring changing codegen due to DI
Jeremy Morse [Wed, 25 Aug 2021 11:04:59 +0000 (12:04 +0100)]
[DebugInfo][InstrRef] Avoid stack-slot-coloring changing codegen due to DI

Stack slot colouring adds "weight" to slots if a non-dbg-value instruction
refers to it. This, unfortunately, means that DBG_PHI instructions can have
an effect on codegen. The fix is very simple, replace isDebugValue with
isDebugInstr.

The regression test contains a scenario that reproduces this problem; I've
represented both normal-debug mode and instr-ref debug mode instructions
in comment lines prefixed with AAAAAA and BBBBBB, and un-comment them with
sed to test that the two different modes produce the same behaviour.

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

2 years ago[mlir][AttrTypeGen] Add support for specifying a "accessor" type of a parameter
River Riddle [Wed, 25 Aug 2021 09:26:56 +0000 (09:26 +0000)]
[mlir][AttrTypeGen] Add support for specifying a "accessor" type of a parameter

This allows for using a different type when accessing a parameter than the
one used for storage. This allows for returning parameters by reference,
enables using more optimized/convient reference results, and more.

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

2 years ago[mlir] Update DialectAsmParser::parseString to use std::string instead of StringRef
River Riddle [Wed, 25 Aug 2021 09:26:39 +0000 (09:26 +0000)]
[mlir] Update DialectAsmParser::parseString to use std::string instead of StringRef

This allows for parsing strings that have escape sequences, which require constructing
a string (as they can't be represented by looking at the Token contents directly).

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

2 years ago[mlir] Move the Operation use iteration utilities to ResultRange
River Riddle [Wed, 25 Aug 2021 09:26:23 +0000 (09:26 +0000)]
[mlir] Move the Operation use iteration utilities to ResultRange

This allows for iterating and interacting with the uses of a specific subset of
results as opposed to just the full range.

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

2 years ago[flang] Implement Posix version of DATE_AND_TIME runtime
Jean Perier [Wed, 25 Aug 2021 09:15:22 +0000 (11:15 +0200)]
[flang] Implement Posix version of DATE_AND_TIME runtime

Use gettimeofday and localtime_r to implement DATE_AND_TIME intrinsic.
The Windows version fallbacks to the "no date and time information
available" defined by the standard (strings set to blanks and values to
-HUGE).

The implementation uses an ifdef between windows and the rest because
from my tests, the SFINAE approach leads to undeclared name bogus errors
with clang 8 that seems to ignore failure to instantiate is not an error
for the function names (i.e., it understands it should not instantiate
the version using gettimeofday if it is not there, but still yields an
error that it is not declared on the spot where it is called in the
uninstantiated version).

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

2 years ago[clang][deps] Ensure deterministic order of TU '-fmodule-file=' arguments
Jan Svoboda [Wed, 25 Aug 2021 08:56:15 +0000 (10:56 +0200)]
[clang][deps] Ensure deterministic order of TU '-fmodule-file=' arguments

Translation units with multiple direct modular dependencies trigger a non-deterministic ordering in `clang-scan-deps`. This boils down to usage of `std::unordered_map`, which gets replaced by `std::map` in this patch.

Depends on D103526.

Reviewed By: dexonsmith

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

2 years ago[LoopFlatten] Add statistic for number of loops flattened. NFC
Rosie Sumpter [Tue, 24 Aug 2021 16:04:35 +0000 (17:04 +0100)]
[LoopFlatten] Add statistic for number of loops flattened. NFC

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

2 years ago[mlir] Add assertion in NamedAttrList to prevent adding null attributes
Tres Popp [Mon, 23 Aug 2021 17:24:12 +0000 (19:24 +0200)]
[mlir] Add assertion in NamedAttrList to prevent adding null attributes

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

2 years ago[gn build] Port 48958d02d294
LLVM GN Syncbot [Wed, 25 Aug 2021 09:02:08 +0000 (09:02 +0000)]
[gn build] Port 48958d02d294

2 years ago[NFC][AMDGPU] Reduce includes dependencies.
Daniil Fukalov [Mon, 23 Aug 2021 20:50:19 +0000 (23:50 +0300)]
[NFC][AMDGPU] Reduce includes dependencies.

1. Splitted out some parts of R600 target to separate modules/headers.
2. Reduced some include lists in headers.
3. Found and fixed issue with override `GCNTargetMachine::getSubtargetImpl()`
   and `R600TargetMachine::getSubtargetImpl()` had different return value type
   than base class.
4. Minor forward declarations cleanup.

Reviewed By: foad

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

2 years ago[clang][deps] Use top-level modules as precompiled dependencies
Jan Svoboda [Wed, 25 Aug 2021 08:36:03 +0000 (10:36 +0200)]
[clang][deps] Use top-level modules as precompiled dependencies

The `ASTReader` populates `Module::PresumedModuleMapFile` only for top-level modules, not submodules. To avoid generating empty `-fmodule-map-file=` arguments, make discovered modules depend on top-level precompiled modules. The granularity of submodules is not important here.

The documentation of `Module::PresumedModuleMapFile` says this field is non-empty only when building from preprocessed source. This means there can still be cases where the dependency scanner generates empty `-fmodule-map-file=` arguments. That's being addressed in separate patch: D108544.

Reviewed By: dexonsmith

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

2 years agoHave lit preserve SOURCE_DATE_EPOCH
serge-sans-paille [Wed, 18 Aug 2021 21:48:14 +0000 (23:48 +0200)]
Have lit preserve SOURCE_DATE_EPOCH

This environment variable has been standardized for reproducible builds. Setting
it can help to have reproducible tests too, so keep it as part of the testing
env when set.

See https://reproducible-builds.org/docs/source-date-epoch/

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

2 years ago[clang][deps] Collect precompiled deps from submodules too
Jan Svoboda [Wed, 25 Aug 2021 08:14:15 +0000 (10:14 +0200)]
[clang][deps] Collect precompiled deps from submodules too

In this patch, the dependency scanner starts collecting precompiled dependencies from all encountered submodules, not only from top-level modules.

Reviewed By: dexonsmith

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

2 years ago[hwasan] do not check if freed pointer belonged to allocator.
Florian Mayer [Mon, 23 Aug 2021 13:03:16 +0000 (14:03 +0100)]
[hwasan] do not check if freed pointer belonged to allocator.

In that case it is very likely that there will be a tag mismatch anyway.

We handle the case that the pointer belongs to neither of the allocators
by getting a nullptr from allocator.GetBlockBegin.

Reviewed By: hctim, eugenis

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

2 years ago[GlobalISel] Do not generate illegal G_SEXTLOADs after legalization
Konstantin Schwarz [Tue, 24 Aug 2021 13:13:39 +0000 (15:13 +0200)]
[GlobalISel] Do not generate illegal G_SEXTLOADs after legalization

The sext_inreg_of_load combine did not have the isLegalOrBeforeLegalizer check,
leading to the generation of potentially illegal G_SEXTLOADs when run after legalization.

Reviewed By: foad

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

2 years ago[CUDA] Fix static device variables with -fgpu-rdc
Jonas Hahnfeld [Fri, 20 Aug 2021 11:28:37 +0000 (13:28 +0200)]
[CUDA] Fix static device variables with -fgpu-rdc

NVPTX does not allow dots in the identifier, so ptxas errors out with
   fatal   : Parsing error near '.static': syntax error
because it parses .static as a directive. Avoid this problem by using
two underscores, similar to what OpenMP does for outlined functions.

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

2 years ago[clang] Don't generate warn-stack-size when the warning is ignored
Yi Kong [Tue, 24 Aug 2021 09:06:08 +0000 (17:06 +0800)]
[clang] Don't generate warn-stack-size when the warning is ignored

8ace12130526 introduced a regression for code that explicitly ignores the
-Wframe-larger-than= warning. Make sure we don't generate the
warn-stack-size attribute for that case.

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

2 years agoAdd "REQUIRES: arm-registered-target" line to test added in D108603.
Douglas Yung [Wed, 25 Aug 2021 05:22:16 +0000 (22:22 -0700)]
Add "REQUIRES: arm-registered-target" line to test added in D108603.

This should fix the test failure on the PS4 build bot.

2 years ago[MachineCopyPropagation] Check CrossCopyRegClass for cross-class copys
Vang Thao [Fri, 13 Aug 2021 04:39:32 +0000 (21:39 -0700)]
[MachineCopyPropagation] Check CrossCopyRegClass for cross-class copys

On some AMDGPU subtargets, copying to and from AGPR registers using another
AGPR register is not possible. A intermediate VGPR register is needed for AGPR
to AGPR copy. This is an issue when machine copy propagation forwards a
COPY $agpr, replacing a COPY $vgpr which results in $agpr = COPY $agpr. It is
removing a cross class copy that may have been optimized by previous passes and
potentially creating an unoptimized cross class copy later on.

To avoid this issue, check CrossCopyRegClass if a different register class will
be needed for the copy. If so then avoid forwarding the copy when the
destination does not match the desired register class and if the original copy
already matches the desired register class.

Issue seen while attempting to optimize another AGPR to AGPR issue:

Live-ins: $agpr0
$vgpr0 = COPY $agpr0
$agpr1 = V_ACCVGPR_WRITE_B32 $vgpr0
$agpr2 = COPY $vgpr0
$agpr3 = COPY $vgpr0
$agpr4 = COPY $vgpr0

After machine-cp:

$vgpr0 = COPY $agpr0
$agpr1 = V_ACCVGPR_WRITE_B32 $vgpr0
$agpr2 = COPY $agpr0
$agpr3 = COPY $agpr0
$agpr4 = COPY $agpr0

Machine-cp propagated COPY $agpr0 to replace $vgpr0 creating 3 AGPR to AGPR
copys. Later this creates a cross-register copy from AGPR->VGPR->AGPR for each
copy when the prior VGPR->AGPR copy was already optimal.

Reviewed By: lkail, rampitec

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

2 years ago[JITLink][MachO] Add more detail to error message.
Lang Hames [Wed, 25 Aug 2021 03:31:06 +0000 (13:31 +1000)]
[JITLink][MachO] Add more detail to error message.

2 years ago[ORC] Fix typo in debugging output
Lang Hames [Wed, 25 Aug 2021 01:18:00 +0000 (11:18 +1000)]
[ORC] Fix typo in debugging output

2 years ago[DAGCombine] Pre-commit test for D108619
Carl Ritson [Wed, 25 Aug 2021 03:11:51 +0000 (12:11 +0900)]
[DAGCombine] Pre-commit test for D108619

2 years ago[InstrProfiling] Keep profd non-private for non-renamable comdat functions
Fangrui Song [Wed, 25 Aug 2021 03:14:02 +0000 (20:14 -0700)]
[InstrProfiling] Keep profd non-private for non-renamable comdat functions

The NS==0 condition used by D103717 missed a corner case: if the current copy
does not have a hash suffix (e.g. weak_odr), a copy with value profiling (with a
different CFG) may exist. This is super rare, but is possible with pre-inlining
PGO instrumentation (which can make a weak_odr function inlines its callees
differently, sometimes with value profiling while sometimes without).

If the current copy with private profd is prevailing, the non-prevailing copy
may get an undefined symbol if a caller inlining the non-prevailing function
references its profd. If the other copy with non-private profd is prevailing,
the current copy may cause a "relocation to discarded section" linker error.

The fix is straightforward: just keep non-private profd in such a `DataReferencedByCode` case.

With this change, a stage 2 (`-DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_BUILD_INSTRUMENTED=IR`)
clang is 0.08% larger (172431496/172286720-1).
`stat -c %s **/*.o | awk '{s+=$1}END{print s}' is 0.026% larger.
The majority of D103717's benefits remains.

Reviewed By: xur

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

2 years agoPR48030: Fix COMDAT-related linking problem with C++ thread_local static data members.
Richard Smith [Wed, 25 Aug 2021 01:34:38 +0000 (18:34 -0700)]
PR48030: Fix COMDAT-related linking problem with C++ thread_local static data members.

Previously when emitting a C++ guarded initializer, we tried to work out what
the enclosing function would be used for and added it to the COMDAT containing
the variable if we thought that doing so would be correct. But this was done
from a context in which we didn't -- and realistically couldn't -- correctly
infer how the enclosing function would be used.

Instead, add the initialization function to a COMDAT from the code that
creates it, in the case where it makes sense to do so: when we know that
the one and only reference to the initialization function is in
@llvm.global.ctors and that reference is in the same COMDAT.

Reviewed By: rjmccall

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

2 years ago[WebAssembly] Fix some UB from ca541aa319cd
Thomas Lively [Wed, 25 Aug 2021 02:44:03 +0000 (19:44 -0700)]
[WebAssembly] Fix some UB from ca541aa319cd

2 years agoRevert D108432 "[InstrProfiling] Keep profd non-private for non-renamable comdat...
Fangrui Song [Wed, 25 Aug 2021 02:16:07 +0000 (19:16 -0700)]
Revert D108432 "[InstrProfiling] Keep profd non-private for non-renamable comdat functions"

This reverts commit f653beea88d2684cdc8117e662b321ba04666771.

It broke Windows coverage-inline.cpp because link.exe has a limitation
that external symbols in IMAGE_COMDAT_SELECT_ASSOCIATIVE don't work.

It essentially dropped the previous size optimization for coverage
because coverage doesn't rename comdat by default.
Needs more investigation what we should do.

2 years ago[mlir][tosa] Quantized tosa.avg_pool2d lowering to linalg
Rob Suderman [Wed, 25 Aug 2021 01:23:21 +0000 (18:23 -0700)]
[mlir][tosa] Quantized tosa.avg_pool2d lowering to linalg

Includes the quantized version of average pool lowering to linalg dialect.
This includes a lit test for the transform. It is not 100% correct as the
multiplier / shift should be done in i64 however this is negligable rounding
difference.

Reviewed By: NatashaKnk

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

2 years ago[mlir][tosa] Table did not apply offset before extract on i8 input
Rob Suderman [Wed, 25 Aug 2021 01:14:47 +0000 (18:14 -0700)]
[mlir][tosa] Table did not apply offset before extract on i8 input

Lowering to table was incorrect as it did not apply a 128 offset before
extracting the value from the table. Fixed and correct tensor length on input
table.

Reviewed By: NatashaKnk

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

2 years ago[mlir][SCF] Generalize AffineMinSCFCanonicalization to min/max ops
Matthias Springer [Wed, 25 Aug 2021 01:28:01 +0000 (10:28 +0900)]
[mlir][SCF] Generalize AffineMinSCFCanonicalization to min/max ops

* Add support for affine.max ops to SCF loop peeling pattern.
* Add support for affine.max ops to `AffineMinSCFCanonicalizationPattern`.
* Rename `AffineMinSCFCanonicalizationPattern` to `AffineOpSCFCanonicalizationPattern`.
* Rename `AffineMinSCFCanonicalization` pass to `SCFAffineOpCanonicalization`.

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

2 years ago[mlir][sparse] Correcting the use of emplace_back
wren romano [Wed, 25 Aug 2021 01:29:05 +0000 (18:29 -0700)]
[mlir][sparse] Correcting the use of emplace_back

The emplace commands are variadic and should take all the constructor arguments directly, since they implicitly call the constructor themselves in order to avoid the cost of constructing and then moving/copying temporaries.

Reviewed By: aartbik

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

2 years ago[WebAssembly] Use SSAUpdaterBulk in LowerEmscriptenSjLj
Heejin Ahn [Tue, 17 Aug 2021 06:30:02 +0000 (23:30 -0700)]
[WebAssembly] Use SSAUpdaterBulk in LowerEmscriptenSjLj

We update SSA in two steps in Emscripten SjLj:
1. Rewrite uses of `setjmpTable` and `setjmpTableSize` variables and
   place `phi`s where necessary, which are updated where we call
   `saveSetjmp`.
2. Do a whole function level SSA update for all variables, because we
   split BBs where `setjmp` is called and there are possibly variable
   uses that are not dominated by a def.
   (See https://github.com/llvm/llvm-project/blob/955b91c19c00ed4c917559a5d66d14c669dde2e3/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp#L1314-L1324)

We have been using `SSAUpdater` to do this, but `SSAUpdaterBulk` class
was added after this pass was first created, and for the step 2 it looks
like a better alternative with a possible performance benefit. Not sure
the author is aware of it, but `SSAUpdaterBulk` seems to have a
limitation: it cannot handle a use within the same BB as a def but
before it. For example:
```
... = %a + 1
%a = foo();
```
or
```
%a = %a + 1
```
The uses `%a` in RHS should be rewritten with another SSA variable of
`%a`, most likely one generated from a `phi`. But `SSAUpdaterBulk`
thinks all uses of `%a` are below the def of `%a` within the same BB.
(`SSAUpdater` has two different functions of rewriting because of this:
`RewriteUse` and `RewriteUseAfterInsertions`.) This doesn't affect our
usage in the step 2 because that deals with possibly non-dominated uses
by defs after block splitting. But it does in the step 1, which still
uses `SSAUpdater`.

But this CL also simplifies the step 1 by using `make_early_inc_range`,
removing the need to advance the iterator before rewriting a use.

This is NFC; the test changes are just the order of PHI nodes.

Reviewed By: dschuff

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

2 years ago[mlir][tosa] Fix conv/depthwise conv padding for quantized values
Rob Suderman [Wed, 25 Aug 2021 01:08:07 +0000 (18:08 -0700)]
[mlir][tosa] Fix conv/depthwise conv padding for quantized values

When padding quantized operations, the padding needs to equal the zero point
of the input value. Corrected the pass to change the padding value if quantized.

Reviewed By: NatashaKnk

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

2 years ago[WebAssembly] Add Wasm SjLj option support for clang
Heejin Ahn [Mon, 23 Aug 2021 10:55:55 +0000 (03:55 -0700)]
[WebAssembly] Add Wasm SjLj option support for clang

This adds support for Wasm SjLj in clang. Also this sets the new
`-mllvm -wasm-enable-eh` option for Wasm EH.

Note there is a little unfortunate inconsistency there: Wasm EH is
enabled by a clang option `-fwasm-exceptions`, which sets
`-mllvm -wasm-enable-eh` in the backend options. It also sets
`-exception-model=wasm` but this is done in the common code.

Wasm SjLj doesn't have a clang-level option like `-fwasm-exceptions`.
`-fwasm-exceptions` was added because each exception model has its
corresponding `-f***-exceptions`, but I'm not sure if adding a new
option like `-fwasm-sjlj` or something is a good idea.

So the current plan is Emscripten sets `-mllvm -wasm-enable-sjlj` if
Wasm SJLj is enabled in its settings.js, as it does for Emscripten
EH/SjLj (it sets `-mllvm -enable-emscripten-cxx-exceptions` for
Emscripten EH and `-mllvm -enable-emscripten-sjlj` for Emscripten SjLj).
And setting this enables the exception handling feature, and also sets
`-exception-model=wasm`, but this time this is not done in the common
code so we do it ourselves.

Also note that other exception models have 1-to-1 correspondance with
their `-f***-exceptions` flag and their `-exception-model=***` flag, but
because we use `-exception-model=wasm` also for Wasm SjLj while
`-fwasm-exceptions` still means Wasm EH, there is also a little
inconsistency there, but I think it is manageable.

Also this adds various error checking and tests.

Reviewed By: dschuff

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

2 years ago[clang] allow -fstack-clash-protection on FreeBSD
Ed Maste [Mon, 23 Aug 2021 16:12:43 +0000 (12:12 -0400)]
[clang] allow -fstack-clash-protection on FreeBSD

-fstack-clash-protection was added in Clang commit e67cbac81211 but was
enabled only on Linux.  Allow it on FreeBSD as well, as it works fine.

Reviewed By: serge-sans-paille

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

2 years ago[gn build] Manually port dbed061b more
Nico Weber [Wed, 25 Aug 2021 01:01:20 +0000 (21:01 -0400)]
[gn build] Manually port dbed061b more

2 years ago[WebAssembly] Tidy up EH/SjLj options
Heejin Ahn [Sat, 7 Aug 2021 02:35:18 +0000 (19:35 -0700)]
[WebAssembly] Tidy up EH/SjLj options

This CL is small, but the description can be a little long because I'm
trying to sum up the status quo for Emscripten/Wasm EH/SjLj options.

First, this CL adds an option for Wasm SjLj (`-wasm-enable-sjlj`), which
handles SjLj using Wasm EH. The implementation for this will be added as
a followup CL, but this adds the option first to do error checking.

This also adds an option for Wasm EH (`-wasm-enable-eh`), which has been
already implemented. Before we used `-exception-model=wasm` as the same
meaning as enabling Wasm EH, but after we add Wasm SjLj, it will be
possible to use Wasm EH instructions for Wasm SjLj while not enabling
EH, so going forward, to use Wasm EH, `opt` and `llc` will need this
option. This only affects `opt` and `llc` command lines and does not
affect Emscripten user interface.

Now we have two modes of EH (Emscripten/Wasm) and also two modes of SjLj
(also Emscripten/Wasm). The options corresponding to each of are:
- Emscripten EH: `-enable-emscripten-cxx-exceptions`
- Emscripten SjLj: `-enable-emscripten-sjlj`
- Wasm EH: `-wasm-enable-eh -exception-model=wasm`
           `-mattr=+exception-handling`
- Wasm SjLj: `-wasm-enable-sjlj -exception-model=wasm`
             `-mattr=+exception-handling`
The reason Wasm EH/SjLj's options are a little complicated are
`-exception-model` and `-mattr` are common LLVM options ane not under
our control. (`-mattr` can be omitted if it is embedded within the
bitcode file.)

And we have the following rules of the option composition:
- Emscripten EH and Wasm EH cannot be turned on at the same itme
- Emscripten SjLj and Wasm SjLj cannot be turned on at the same time
- Wasm SjLj should be used with Wasm EH

Which means we now allow these combinations:
- Emscripten EH + Emscripten SjLj: the current default in `emcc`
- Wasm EH + Emscripten SjLj:
  This is allowed, but only as an interim step in which we are testing
  Wasm EH but not yet have a working implementation of Wasm SjLj. This
  will error out (D107687) in compile time if `setjmp` is called in a
  function in which Wasm exception is used.
- Wasm EH + Wasm SjLj:
  This will be the default mode later when using Wasm EH. Currently Wasm
  SjLj implementation doesn't exist, so it doesn't work.
- Emscripten EH + Wasm SjLj will not work.

This CL moves these error checking routines to
`WebAssemblyPassConfig::addIRPasses`. Not sure if this is an ideal place
to do this, but I couldn't find elsewhere. Currently some checking is
done within LowerEmscriptenEHSjLj, but these checks only run if
LowerEmscriptenEHSjLj runs so it may not run when Wasm EH is used. This
moves that to `addIRPasses` and adds some more checks.

Currently LowerEmscriptenEHSjLj pass is responsible for Emscripten EH
and Emscripten SjLj. Wasm EH transformations are done in multiple
places, including WasmEHPrepare, LateEHPrepare, and CFGStackify. But in
the followup CL, LowerEmscriptenEHSjLj pass will be also responsible for
a part of Wasm SjLj transformation, because WasmSjLj will also be using
several Emscripten library functions, and we will be sharing more than
half of the transformation to do that between Emscripten SjLj and Wasm
SjLj.

Currently we have `-enable-emscripten-cxx-exceptions` and
`-enable-emscripten-sjlj` but these only work for `llc`, because for
`llc` we feed these options to the pass but when we run the pass using
`opt` the pass will be created with no options and the default options
will be used, which turns both Emscripten EH and Emscripten SjLj on.

Now we have one more SjLj option to care for, LowerEmscriptenEHSjLj pass
needs a finer way to control these options. This CL removes those
default parameters and make LowerEmscriptenEHSjLj pass read directly
from command line options specified. So if we only run
`opt -wasm-lower-em-ehsjlj`, currently both Emscripten EH and Emscripten
SjLj will run, but with this CL, none will run unless we additionally
pass `-enable-emscripten-cxx-exceptions` or `-enable-emscripten-sjlj`,
or both. This does not affect users; this only affects our `opt` tests
because `emcc` will not call either `opt` or `llc`. As a result of this,
our existing Emscripten EH/SjLj tests gained one or both of those
options in their `RUN` lines.

Reviewed By: dschuff

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

2 years ago[GlobalOpt] Fix the assert for null check of global value
Shimin Cui [Wed, 25 Aug 2021 00:47:33 +0000 (20:47 -0400)]
[GlobalOpt] Fix the assert for null check of global value

This is to fix the reported assert - https://bugs.llvm.org/show_bug.cgi?id=51608.

Reviewed By: asbirlea

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

2 years ago[mlir][docs] A friendlier improvement for the Toy tutorial chapter 4.
Chenggang Zhao [Wed, 25 Aug 2021 00:41:35 +0000 (00:41 +0000)]
[mlir][docs] A friendlier improvement for the Toy tutorial chapter 4.

Add notes for discarding private-visible functions in the Toy tutorial chapter 4.

Reviewed By: mehdi_amini

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

2 years ago[libomptarget][amdgpu] Fix debug build from D104696
Jon Chesterfield [Wed, 25 Aug 2021 00:26:45 +0000 (01:26 +0100)]
[libomptarget][amdgpu] Fix debug build from D104696

2 years ago[WebAssembly] Fix up out-of-range BUILD_VECTOR lane constants
Thomas Lively [Wed, 25 Aug 2021 00:24:03 +0000 (17:24 -0700)]
[WebAssembly] Fix up out-of-range BUILD_VECTOR lane constants

Fixes PR51605 in which a DAG combine and legalization sequence generated
out-of-range constants in BUILD_VECTOR lanes. In the v16i8 case, the constants
were 255, which would be in range if DAG ISel used unsigned constants, but it is
out of range because DAG ISel uses signed constants.

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

2 years ago[msan] Unpoison trailing nullptr in wordexp interceptor
Vitaly Buka [Tue, 24 Aug 2021 21:43:59 +0000 (14:43 -0700)]
[msan] Unpoison trailing nullptr in wordexp interceptor

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

2 years ago[msan] Don't EXPECT_POISONED beyond the we_wordv
Vitaly Buka [Wed, 25 Aug 2021 00:11:51 +0000 (17:11 -0700)]
[msan] Don't EXPECT_POISONED beyond the we_wordv

Partially reverts commit 629411d799223d7bc7aad98661b1443a4788c0c5.

EXPECT_POISONED argument is outside of the allocation so we can't
assume the state of shadow there.

2 years agoExtend diagnostic for out of date AST input file.
Richard Smith [Fri, 23 Jul 2021 00:52:16 +0000 (17:52 -0700)]
Extend diagnostic for out of date AST input file.

If the size has changed, list the old and new sizes; if the mtime has
changed, list the old and new mtimes (as raw time_t values).

2 years ago[mlir][linalg] Replace AffineMinSCFCanonicalizationPattern with SCF reimplementation
Matthias Springer [Tue, 24 Aug 2021 23:47:05 +0000 (08:47 +0900)]
[mlir][linalg] Replace AffineMinSCFCanonicalizationPattern with SCF reimplementation

Use the new canonicalization pattern in the SCF dialect.

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

2 years ago[msan] Fix wordexp after D108646
Vitaly Buka [Tue, 24 Aug 2021 23:23:50 +0000 (16:23 -0700)]
[msan] Fix wordexp after D108646

I introduced this bug reformating the patch before commit.

2 years agoRevert "[AArch64][GlobalISel] Don't contract cross-bank copies into truncating stores."
Amara Emerson [Tue, 24 Aug 2021 23:08:08 +0000 (16:08 -0700)]
Revert "[AArch64][GlobalISel] Don't contract cross-bank copies into truncating stores."

This reverts commit 67bf3ac7446bd8ba16bb5ef82fa9f28a848616da.

The reason is that this change is now superseded by 04fb9b729a53 which fixes the
underlying problem in the selector. Now it's fine to generate truncating FP stores
since the selector code will just generate subreg copies to handle them.

2 years ago[mlir][sparse] enable a few vectorized runs in integration tests
Aart Bik [Tue, 24 Aug 2021 22:18:29 +0000 (15:18 -0700)]
[mlir][sparse] enable a few vectorized runs in integration tests

Recent changes outside sparse compiler exposed the requirement of running a
new pass (lower-affine) but this only became apparent with private testing.
By adding some vectorized runs to integration test, we will detect the need
for such changes earlier and also widen codegen coverage of course.

Reviewed By: gussmith23

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

2 years ago[AArch64][GlobalISel] Fix incorrect handling of fp truncating stores.
Amara Emerson [Tue, 24 Aug 2021 20:56:01 +0000 (13:56 -0700)]
[AArch64][GlobalISel] Fix incorrect handling of fp truncating stores.

When the tablegen patterns fail to select a truncating scalar FPR store,
our manual selection code also failed to handle it silently, trying to
generate an invalid copy. Fix this by adding support in the manual code
to generate a proper subreg copy before selecting a non-truncating store.

2 years ago[InstrProfiling] Keep profd non-private for non-renamable comdat functions
Fangrui Song [Tue, 24 Aug 2021 22:59:35 +0000 (15:59 -0700)]
[InstrProfiling] Keep profd non-private for non-renamable comdat functions

The NS==0 condition used by D103717 missed a corner case: if the current copy
does not have a hash suffix (e.g. weak_odr), a copy with value profiling (with a
different CFG) may exist. This is super rare, but is possible with pre-inlining
PGO instrumentation (which can make a weak_odr function inlines its callees
differently, sometimes with value profiling while sometimes without).

If the current copy with private profd is prevailing, the non-prevailing copy
may get an undefined symbol if a caller inlining the non-prevailing function
references its profd. If the other copy with non-private profd is prevailing,
the current copy may cause a "relocation to discarded section" linker error.

The fix is straightforward: just keep non-private profd in this case.

With this change, a stage 2 (`-DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_BUILD_INSTRUMENTED=IR`)
clang is 0.08% larger (172431496/172286720-1).
`stat -c %s **/*.o | awk '{s+=$1}END{print s}' is 0.026% larger.
The majority of D103717's benefits remains.

Reviewed By: xur

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

2 years ago[mlir][scf] Add general affine.min canonicalization pattern
Matthias Springer [Tue, 24 Aug 2021 12:21:12 +0000 (21:21 +0900)]
[mlir][scf] Add general affine.min canonicalization pattern

This canonicalization simplifies affine.min operations inside "for loop"-like operations (e.g., scf.for and scf.parallel) based on two invariants:
* iv >= lb
* iv < lb + step * ((ub - lb - 1) floorDiv step) + 1

This commit adds a new pass `canonicalize-scf-affine-min` (instead of being a canonicalization pattern) to avoid dependencies between the Affine dialect and the SCF dialect.

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

2 years agoRevert "[lldb] Add support for debugging via the dynamic linker."
Rumeet Dhindsa [Tue, 24 Aug 2021 22:20:52 +0000 (15:20 -0700)]
Revert "[lldb] Add support for debugging via the dynamic linker."

This reverts commit 1cbdc07ec015d83038c08dc562d55eccfd808591.

Buildbot failure started after this patch with failure in
api/multithreaded/TestMultithreaded.py:
https://lab.llvm.org/buildbot/#/builders/68/builds/17556

2 years ago[mlir] Fix attachInterface typo
Logan Chien [Tue, 24 Aug 2021 21:39:59 +0000 (14:39 -0700)]
[mlir] Fix attachInterface typo

This commit fixes the documentation typo regarding `attachInterface`.

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

2 years ago[DFSan] Add wrapper for getentropy().
Andrew Browne [Tue, 24 Aug 2021 01:33:25 +0000 (18:33 -0700)]
[DFSan] Add wrapper for getentropy().

Reviewed By: morehouse

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

2 years ago[sanitizer coverage] add a basic default implementation of callbacks for -fsanitize...
Kostya Serebryany [Thu, 19 Aug 2021 20:45:36 +0000 (13:45 -0700)]
[sanitizer coverage] add a basic default implementation of callbacks for -fsanitize-coverage=inline-8bit-counters,pc-table

[sanitizer coverage] add a basic default implementation of callbacks for -fsanitize-coverage=inline-8bit-counters,pc-table

Reviewed By: kostik

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

2 years ago[LLDB] Remove typos from NativeRegisterContextLinux_arm*
Muhammad Omair Javaid [Tue, 24 Aug 2021 21:53:31 +0000 (02:53 +0500)]
[LLDB] Remove typos from NativeRegisterContextLinux_arm*

This patch removed some typos from NativeRegisterContextLinux_arm and
NativeRegisterContextLinux_arm64. Some of the log/error messages were
being reported as x86_64.

2 years agoRevert "[lldb] Refactor Module::LookupInfo constructor"
Alex Langford [Tue, 24 Aug 2021 21:52:17 +0000 (14:52 -0700)]
Revert "[lldb] Refactor Module::LookupInfo constructor"

This reverts commit cd2134e42aa7d1168a3ed54e41793b022f961b1f.

Seems like this broke some tests on arm and aarch64 boxes. Will
investigate before re-landing.

2 years ago[MSAN] Fix wordexp interception when WRDE_DOOFFS is used
Justin Cady [Tue, 24 Aug 2021 19:34:41 +0000 (12:34 -0700)]
[MSAN] Fix wordexp interception when WRDE_DOOFFS is used

Handle the case of wordexp being invoked with WRDE_DOOFFS and
we.we_offs set to a positive value, which will result in NULL
entries prepended to the result. With this change the entire
result, containing both NULL and actual entries, is unpoisoned.

Reviewed By: vitalybuka

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

2 years ago[tests] Add a couple tests for intersection of ec8d87e and D108651
Philip Reames [Tue, 24 Aug 2021 21:28:57 +0000 (14:28 -0700)]
[tests] Add a couple tests for intersection of ec8d87e and D108651

2 years ago[clang][codegen] Set CurLinkModule in CodeGenAction::ExecuteAction
Bob Haarman [Sat, 21 Aug 2021 00:14:32 +0000 (00:14 +0000)]
[clang][codegen] Set CurLinkModule in CodeGenAction::ExecuteAction

CodeGenAction::ExecuteAction creates a BackendConsumer for the
purpose of handling diagnostics. The BackendConsumer's
DiagnosticHandlerImpl method expects CurLinkModule to be set,
but this did not happen on the code path that goes through
ExecuteAction. This change makes it so that the BackendConsumer
constructor used by ExecuteAction requires the Module to be
specified and passes the appropriate module in ExecuteAction.

The change also adds a test that fails without this change
and passes with it. To make the test work, the FIXME in the
handling of DK_Linker diagnostics was addressed so that warnings
and notes are no longer silently discarded. Since this introduces
a new warning diagnostic, a flag to control it (-Wlinker-warnings)
has also been added.

Reviewed By: xur

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

2 years ago[SCEV] Infer nuw from nw for addrecs
Philip Reames [Tue, 24 Aug 2021 21:23:03 +0000 (14:23 -0700)]
[SCEV] Infer nuw from nw for addrecs

This was previously committed in 914836b, and reverted due to confusion on the status of the review.

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

2 years ago[orc] Fix unit tests that use ORC C API
Ben Langmuir [Tue, 24 Aug 2021 18:10:11 +0000 (11:10 -0700)]
[orc] Fix unit tests that use ORC C API

* c_api_tests was failing to build after the API change to
  __orc_rt_CWrapperFunctionResultAllocate

* wrapper_function_utils_test was causing an assertion failure, because
  it was creating a result for `void(void)` with Size = 0, but seeing an
  uninitialized pointer, which it considered to be an out-of-bound
  error.

I noticed locally that making modifications to c_api.h is not causing
these unit tests to be rebuilt, which may be how the bug slipped in in
the first place.

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

2 years ago[test] Prcommit tests for D108651
Philip Reames [Tue, 24 Aug 2021 21:18:50 +0000 (14:18 -0700)]
[test] Prcommit tests for D108651

2 years ago[hwasan] Always untag short granule in shadow.
Mitch Phillips [Tue, 24 Aug 2021 21:10:02 +0000 (14:10 -0700)]
[hwasan] Always untag short granule in shadow.

Fixes a regression when the allocator is disabled, and a dirty
allocation is re-used. This only occurs when the allocator is disabled,
so a test-only fix, but still necessary.

Reviewed By: eugenis

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

2 years ago[X86] Add explicit library dependency on LLVMInstrumentation
Min-Yih Hsu [Tue, 24 Aug 2021 21:07:21 +0000 (14:07 -0700)]
[X86] Add explicit library dependency on LLVMInstrumentation

Patch 9588b685c6b2 introduced dependency on ASAN. But it didn't
explicitly put LLVMInstrumentation as one of the library dependencies
such that the build will fail if we're building LLVM as shared libraries
(i.e. -DBUILD_SHARED_LIBS=ON).
This patch explicitly links X86CodeGen against the Instrumentation
component.

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

2 years ago[AArch64][GlobalISel] Legalize narrow scalar FP arithmetic
Jessica Paquette [Tue, 24 Aug 2021 20:21:15 +0000 (13:21 -0700)]
[AArch64][GlobalISel] Legalize narrow scalar FP arithmetic

Widen narrow fp arithmetic ops (e.g. G_FADD). When we don't have full FP16
support, widen to s32. Otherwise widen to s16.

https://godbolt.org/z/TbT9Pqa7e

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

2 years ago[lldb] Refactor Module::LookupInfo constructor
Alex Langford [Tue, 17 Aug 2021 17:55:05 +0000 (10:55 -0700)]
[lldb] Refactor Module::LookupInfo constructor

Module::LookupInfo's constructor currently goes over supported languages
trying to figure out the best way to search for a symbol name. This
seems like a great candidate for refactoring. Specifically, this is work
that can be delegated to language plugins.

Once again, the goal here is to further decouple plugins from
non-plugins. The idea is to have each language plugin take a name and
give you back some information about the name from the perspective of
the language. Specifically, each language now implements a
`GetFunctionNameInfo` method which returns an object of type
`Language::FunctionNameInfo`. Right now, it consists of a basename,
a context, and a FunctionNameType. Module::LookupInfo's constructor will
call `GetFunctionNameInfo` with the appropriate language plugin(s) and
then decide what to do with that information. I have attempted to maintain
existing behavior as best as possible.

A nice side effect of this change is that lldbCore no longer links
against the ObjC Language plugin.

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

2 years ago[libc++abi] Apply simplify scan_eh_tab to SjLj
Kazushi (Jam) Marukawa [Tue, 24 Aug 2021 20:51:21 +0000 (16:51 -0400)]
[libc++abi] Apply simplify scan_eh_tab to SjLj

Previous "simplify scan_eh_tab" patch, https://reviews.llvm.org/D93190,
saves landingpad if and only if the target is not using SjLj exceptions.
However, the landingpad is used by SjLj exception handler also.  This
patch changes to set landingpad for both exception handlers.

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

2 years ago[lldb] Add support for debugging via the dynamic linker.
Rumeet Dhindsa [Tue, 24 Aug 2021 20:38:45 +0000 (13:38 -0700)]
[lldb] Add support for debugging via the dynamic linker.

This patch adds support for shared library load when the executable is
called through ld.so.

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

2 years ago[gn build] (manually) port 87dd51983cf9
Nico Weber [Tue, 24 Aug 2021 20:40:44 +0000 (16:40 -0400)]
[gn build] (manually) port 87dd51983cf9

2 years agoMake WindowsManifestMerger::merge() take a MemoryBufferRef
Nico Weber [Tue, 24 Aug 2021 20:38:34 +0000 (16:38 -0400)]
Make WindowsManifestMerger::merge() take a MemoryBufferRef

No behavior change.

2 years agollvm-xray {convert,extract}: Add --demangle
Fangrui Song [Tue, 24 Aug 2021 20:35:19 +0000 (13:35 -0700)]
llvm-xray {convert,extract}: Add --demangle

No demangling may be a better default in the future.
Add `--demangle` for migration convenience.

Reviewed By: Enna1

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

2 years ago[MCA] Adding an AMDGPUCustomBehaviour implementation.
Patrick Holland [Fri, 23 Jul 2021 00:46:39 +0000 (17:46 -0700)]
[MCA] Adding an AMDGPUCustomBehaviour implementation.

This implementation allows mca to model the desired behaviour of the s_waitcnt
instruction. This patch also adds the RetireOOO flag to the AMDGPU instructions
within the scheduling model. This flag is only used by mca and allows
instructions to finish out-of-order which helps mca's simulations more closely
model the actual device.

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

2 years agoRevert "[asan] Implemented intrinsic for the custom calling convention similar used...
Kirill Stoimenov [Tue, 24 Aug 2021 20:01:21 +0000 (13:01 -0700)]
Revert "[asan] Implemented intrinsic for the custom calling convention similar used by HWASan for X86."

This reverts commit 9588b685c6b2d90e4b6dd68e02e6a44affd77c3f. Breaks a bunch of builds.

Reviewed By: GMNGeoffrey

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

2 years ago[libc] Fix too long number in strtoul_test
Michael Jones [Tue, 24 Aug 2021 19:59:29 +0000 (19:59 +0000)]
[libc] Fix too long number in strtoul_test

I think this is the last windows type conversion fix, the rest of the
build seems to be okay.

Reviewed By: sivachandra

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

2 years ago[M68k][test] Migrate MC tests related to MOVEM instruciton
Min-Yih Hsu [Tue, 24 Aug 2021 19:50:28 +0000 (12:50 -0700)]
[M68k][test] Migrate MC tests related to MOVEM instruciton

Since we're now supporting the (correct) assembly syntax for MOVEM since
47f52f989b06. The remaining MOVEM MC tests can not be migrated into
test/MC/M68k.

2 years ago[Clang][OpenMP] Use enum to dereference children data array in OMPAtomicDirective
Shilei Tian [Tue, 24 Aug 2021 20:00:17 +0000 (16:00 -0400)]
[Clang][OpenMP] Use enum to dereference children data array in OMPAtomicDirective

Reviewed By: ABataev

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

2 years ago[libc] Fix type errors on Windows
Michael Jones [Tue, 24 Aug 2021 18:38:40 +0000 (18:38 +0000)]
[libc] Fix type errors on Windows

Fix the errors caused by having some numbers too large for a 32 bit
number in the tests for windows. Also fix the base causing some type
confusion.

Reviewed By: sivachandra

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

2 years ago[InstSimplify] fold or+shifted -1 to -1
Sanjay Patel [Tue, 24 Aug 2021 19:14:21 +0000 (15:14 -0400)]
[InstSimplify] fold or+shifted -1 to -1

These are similar to the rotate pattern added with:
dcf659e8219b
...but we don't have guard ops on the shift amount,
so we don't canonicalize to the intrinsic.

  declare void @llvm.assume(i1)

  define i32 @src(i32 %shamt, i32 %bitwidth) {
    ; subtract must be in range of bitwidth
    %lt = icmp ule i32 %bitwidth, 32
    call void @llvm.assume(i1 %lt)

    %r = lshr i32 -1, %shamt
    %s = sub i32 %bitwidth, %shamt
    %l = shl i32 -1, %s
    %o = or i32 %r, %l
    ret i32 %o
  }

  define i32 @tgt(i32 %shamt, i32 %bitwidth) {
    ret i32 -1
  }

https://alive2.llvm.org/ce/z/aF7WHx

2 years ago[InstSimplify] add tests for or-of-shifted-one-bits; NFC
Sanjay Patel [Tue, 24 Aug 2021 17:06:38 +0000 (13:06 -0400)]
[InstSimplify] add tests for or-of-shifted-one-bits; NFC

2 years ago[asan] Implemented intrinsic for the custom calling convention similar used by HWASan...
Kirill Stoimenov [Tue, 10 Aug 2021 17:49:48 +0000 (17:49 +0000)]
[asan] Implemented intrinsic for the custom calling convention similar used by HWASan for X86.

The implementation uses the int_asan_check_memaccess intrinsic to instrument the code. The intrinsic is replaced by a call to a function which performs the access check. The generated function names encode the input register name as a number using Reg - X86::NoRegister formula.

Reviewed By: vitalybuka

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

2 years ago[ARC] Add codegen for the readcyclecounter intrinsic along with disassembly for assoc...
Thomas Johnson [Tue, 24 Aug 2021 17:22:34 +0000 (10:22 -0700)]
[ARC] Add codegen for the readcyclecounter intrinsic along with disassembly for associated instructions

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

2 years ago[Polly][test] Add missing %loadPolly.
Michael Kruse [Tue, 24 Aug 2021 18:44:48 +0000 (13:44 -0500)]
[Polly][test] Add missing %loadPolly.

This fixes check-polly when using the -load mechanism,
i.e. LLVM_POLLY_LINK_INTO_TOOLS=OFF.

2 years ago[NFC] Add tests for i128 fshl on a few targets.
Eli Friedman [Tue, 24 Aug 2021 18:43:35 +0000 (11:43 -0700)]
[NFC] Add tests for i128 fshl on a few targets.

In preparation for D108058.

2 years agoSupport alias.scope and noalias metadata
Tyler Augustine [Tue, 24 Aug 2021 18:38:32 +0000 (20:38 +0200)]
Support alias.scope and noalias metadata

Introduces new Ops to represent 1. alias.scope metadata in LLVM, and 2. domains for these scopes. These correspond to the metadata described in https://llvm.org/docs/LangRef.html#noalias-and-alias-scope-metadata. Lists of scopes are modeled the same way as access groups - as an ArrayAttr on the Op (added in https://reviews.llvm.org/D97944).

Lowering 'noalias' attributes on function parameters is already supported. However, lowering `noalias` metadata on individual Ops is not, which is added in this change. LLVM uses the same keyword for these, but this change introduces a separate attribute name 'noalias_scopes' to represent this distinct concept.

Reviewed By: mehdi_amini

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

2 years ago[libc++] Remove support for CloudABI, which has been abandoned
Louis Dionne [Tue, 24 Aug 2021 15:40:05 +0000 (11:40 -0400)]
[libc++] Remove support for CloudABI, which has been abandoned

Based on https://github.com/NuxiNL/cloudlibc, it appears that the CloudABI
project has been abandoned. This patch removes a bunch of CloudABI specific
logic that had been added to support that platform.

Note that some knobs like LIBCXX_ENABLE_STDIN and LIBCXX_ENABLE_STDOUT
coud be useful in their own right, however those are currently broken.
If we want to re-add such knobs in the future, we can do it like we've
done it for localization & friends so that we can officially support
that configuration.

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

2 years agoAllow rematerialization of virtual reg uses
Stanislav Mekhanoshin [Thu, 19 Aug 2021 18:42:09 +0000 (11:42 -0700)]
Allow rematerialization of virtual reg uses

Currently isReallyTriviallyReMaterializableGeneric() implementation
prevents rematerialization on any virtual register use on the grounds
that is not a trivial rematerialization and that we do not want to
extend liveranges.

It appears that LRE logic does not attempt to extend a liverange of
a source register for rematerialization so that is not an issue.
That is checked in the LiveRangeEdit::allUsesAvailableAt().

The only non-trivial aspect of it is accounting for tied-defs which
normally represent a read-modify-write operation and not rematerializable.

The test for a tied-def situation already exists in the
/CodeGen/AMDGPU/remat-vop.mir,
test_no_remat_v_cvt_f32_i32_sdwa_dst_unused_preserve.

The change has affected ARM/Thumb, Mips, RISCV, and x86. For the targets
where I more or less understand the asm it seems to reduce spilling
(as expected) or be neutral. However, it needs a review by all targets'
specialists.

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

2 years ago[libc] fix string conversion tests for windows
Michael Jones [Mon, 23 Aug 2021 22:37:08 +0000 (22:37 +0000)]
[libc] fix string conversion tests for windows

There were some copy paste errors as well as some oddities around how
windows handles the difference between long and long long types. This
change fixes those.

Reviewed By: sivachandra

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

2 years ago[AArch64][GlobalISel] Legalize + select v2p0 -> v264 G_PTRTOINT
Jessica Paquette [Tue, 24 Aug 2021 04:59:27 +0000 (21:59 -0700)]
[AArch64][GlobalISel] Legalize + select v2p0 -> v264 G_PTRTOINT

1) Just mark this case as legal because it can just be a copy.

2) Ensure the copy in the existing code actually gets selected. Without doing
this, we'll crash because the destination won't have a register class.

This fell back 35 times in a build of clang with GISel for AArch64.

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

2 years ago[OpenMP][amdgcn] Don't use in-tree clang if not available.
Michael Kruse [Tue, 24 Aug 2021 17:38:00 +0000 (12:38 -0500)]
[OpenMP][amdgcn] Don't use in-tree clang if not available.

The use of `$<TARGET_FILE:clang>` was adapted too broadly from D101265.

Fixes llvm.org/PR51579

Also see discussion in D108534.

Reviewed By: JonChesterfield

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