platform/upstream/llvm.git
3 years ago[SystemZ] Don't use libcall for 128 bit shifts.
Jonas Paulsson [Thu, 6 May 2021 13:22:21 +0000 (15:22 +0200)]
[SystemZ] Don't use libcall for 128 bit shifts.

Expand 128 bit shifts instead of using a libcall.

This patch removes the 128 bit shift libcalls and thereby causes
ExpandShiftWithUnknownAmountBit() to be called.

Review: Ulrich Weigand

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

3 years ago[RISCV] Cleanup instruction formats used for B extension ternary operations.
Craig Topper [Thu, 6 May 2021 15:58:58 +0000 (08:58 -0700)]
[RISCV] Cleanup instruction formats used for B extension ternary operations.

Rename RVInstR4 as used by F/D/Zfh extensions to RVInstR4Frm.
Introduce new RVInstR4 that takes funct3 as a parameter.

Add new format classes for FSRI and FSRIW instead of trying to
bend RVInstR4 to use a shamt overlayed on rs2 and funct2.

Reviewed By: frasercrmck

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

3 years ago[LangRef][VP] Fix typos in VP sdiv/udiv examples
Fraser Cormack [Thu, 6 May 2021 15:37:04 +0000 (16:37 +0100)]
[LangRef][VP] Fix typos in VP sdiv/udiv examples

3 years ago[clangd][ObjC] Highlight Objc Ivar refs
David Goldman [Mon, 3 May 2021 20:18:57 +0000 (16:18 -0400)]
[clangd][ObjC] Highlight Objc Ivar refs

Treat them just like we do for properties - as a `property` semantic
token although ideally we could differentiate the two.

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

3 years ago[AMDGPU] Fix 64 bit DPP validation
Stanislav Mekhanoshin [Wed, 5 May 2021 18:26:07 +0000 (11:26 -0700)]
[AMDGPU] Fix 64 bit DPP validation

AMDGPUAsmParser::isSupportedDPPCtrl() was failing to correctly
find a DPP register operand, regadless of the position it is
always src0. Moved this check into a new validateDPP() method
where we have full instruction already. In particular it was
failing to reject this case:

v_cvt_u32_f64 v5, v[0:1] quad_perm:[0,2,1,1] row_mask:0xf bank_mask:0xf

Essentially it was broken for any case where size of dst and
src0 differ.

It also improves the diagnostics with a proper error message.

The check in the InstPrinter also drops verification of the dst
register as it does not have anything to do with the dpp operand.

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

3 years ago[SLP] Constify the TreeEntry* input into getEntryCost() + setInsertPointAfterBundle...
Simon Pilgrim [Thu, 6 May 2021 15:19:36 +0000 (16:19 +0100)]
[SLP] Constify the TreeEntry* input into getEntryCost() + setInsertPointAfterBundle(). NFCI.

3 years ago[SLP] Constify the TreeEntry* input into dumpTreeCosts(). NFCI.
Simon Pilgrim [Thu, 6 May 2021 15:07:16 +0000 (16:07 +0100)]
[SLP] Constify the TreeEntry* input into dumpTreeCosts(). NFCI.

3 years ago[SLP] Use empty() instead of size() == 0. NFCI.
Simon Pilgrim [Thu, 6 May 2021 15:00:44 +0000 (16:00 +0100)]
[SLP] Use empty() instead of size() == 0. NFCI.

3 years ago[lld-macho] Support loading of zippered dylibs
Jez Ng [Thu, 6 May 2021 15:18:19 +0000 (11:18 -0400)]
[lld-macho] Support loading of zippered dylibs

ld64 can emit dylibs that support more than one platform (typically macOS and
macCatalyst). This diff allows LLD to read in those dylibs. Note that this is a
super bare-bones implementation -- in particular, I haven't added support for
LLD to emit those multi-platform dylibs, nor have I added a variety of
validation checks that ld64 does. Until we have a use-case for emitting zippered
dylibs, I think this is good enough.

Fixes PR49597.

Reviewed By: #lld-macho, oontvoo

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

3 years ago[lld-macho][nfc] Convert the mock libSystem.tbd to TBDv4
Jez Ng [Wed, 5 May 2021 22:30:23 +0000 (18:30 -0400)]
[lld-macho][nfc] Convert the mock libSystem.tbd to TBDv4

It doesn't seem like TBDv3 allows for specifying multiple platforms, so I'm
upgrading us to TBDv4. (We need to support multiple platforms in order to test
that we can handle zippered dylibs; that functionality will be added in an
upcoming diff.)

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

3 years ago[mlir][NFC] Fix warning in VectorTransforms.cpp
thomasraoux [Thu, 6 May 2021 15:11:42 +0000 (08:11 -0700)]
[mlir][NFC] Fix warning in VectorTransforms.cpp

3 years ago[mlir][vector] add pattern to cast away lead unit dimension for broadcast op
thomasraoux [Wed, 5 May 2021 23:03:22 +0000 (16:03 -0700)]
[mlir][vector] add pattern to cast away lead unit dimension for broadcast op

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

3 years ago[PowerPC] Re-commit ed87f512bb9eb5c1d44e9a1182ffeaf23d6c5ae8
Nemanja Ivanovic [Thu, 6 May 2021 14:44:07 +0000 (09:44 -0500)]
[PowerPC] Re-commit ed87f512bb9eb5c1d44e9a1182ffeaf23d6c5ae8

This was reverted in 3761b9a2345aff197707d23a68d4a178489f60e4 just
as I was about to commit the fix. This patch inlcudes the
necessary fix.

3 years ago[AMDGPU][NFC] Fix typos in SIFormMemoryClauses description
Austin Kerbow [Thu, 6 May 2021 14:43:11 +0000 (07:43 -0700)]
[AMDGPU][NFC] Fix typos in SIFormMemoryClauses description

NFC.

3 years ago[OpenMP] Temporarily require X86 target for parallel_for_codegen.cpp test
David Spickett [Thu, 6 May 2021 14:13:19 +0000 (14:13 +0000)]
[OpenMP] Temporarily require X86 target for parallel_for_codegen.cpp test

Since https://reviews.llvm.org/D101849 this test has been failing
on bots that only enable either Arm or AArch64 targets.

See: https://lab.llvm.org/buildbot/#/builders/107/builds/7601

Temporarily requires X86 for this test while the difference is figured out.

3 years ago[libc++] Rewrite std::to_address to avoid relying on element_type
Louis Dionne [Tue, 4 May 2021 22:51:58 +0000 (18:51 -0400)]
[libc++] Rewrite std::to_address to avoid relying on element_type

This is a rough reapplication of the change that fixed std::to_address
to avoid relying on element_type (da456167). It is somewhat different
because the fix to avoid breaking Clang (which caused it to be reverted
in 347f69c55) was a bit more involved.

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

3 years ago[AIX][TLS] Add support for TLSGD relocations to XCOFF objects
Victor Huang [Thu, 6 May 2021 13:37:09 +0000 (08:37 -0500)]
[AIX][TLS] Add support for TLSGD relocations to XCOFF objects

- Add branch absolute reloction R_RBA, R_TLS relocation for the variable offset
  for the tlsgd model and R_TLSM for the region handle for the tlsgd model
- Properly set the relocation fixed values for R_TLS and R_TLSM
- Emit the TCEntry with the variant kind in the XCOFFStreamer

Reviewed by: sfertile, nemanjai, DiggerLin

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

3 years agoRevert "[PowerPC] Provide some P8-specific altivec overloads for P7"
Nico Weber [Thu, 6 May 2021 14:00:39 +0000 (10:00 -0400)]
Revert "[PowerPC] Provide some P8-specific altivec overloads for P7"

This reverts commit ed87f512bb9eb5c1d44e9a1182ffeaf23d6c5ae8.
Breaks check-clang, see e.g.
https://lab.llvm.org/buildbot/#/builders/139/builds/3818

3 years ago[lldb][NFC] Make assert in TestStaticVariables more expressive
Raphael Isemann [Thu, 6 May 2021 14:00:24 +0000 (16:00 +0200)]
[lldb][NFC] Make assert in TestStaticVariables more expressive

3 years ago[AMDGPU] SIInsertHardClauses: move more stuff into the class. NFC.
Jay Foad [Thu, 6 May 2021 13:47:43 +0000 (14:47 +0100)]
[AMDGPU] SIInsertHardClauses: move more stuff into the class. NFC.

3 years ago[PowerPC] Provide some P8-specific altivec overloads for P7
Nemanja Ivanovic [Thu, 6 May 2021 11:54:52 +0000 (06:54 -0500)]
[PowerPC] Provide some P8-specific altivec overloads for P7

This adds additional support for XL compatibility. There are a number
of functions in altivec.h that produce a single instruction (or a
very short sequence) for Power8 but can be done on Power7 without
scalarization. XL provides these implementations.
This patch adds the following overloads for doubleword vectors:
vec_add
vec_cmpeq
vec_cmpgt
vec_cmpge
vec_cmplt
vec_cmple
vec_sl
vec_sr
vec_sra

3 years ago[TableGen] [Clang] Clean up Options.td and add asserts.
Paul C. Anagnostopoulos [Wed, 28 Apr 2021 23:55:12 +0000 (19:55 -0400)]
[TableGen] [Clang] Clean up Options.td and add asserts.

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

3 years ago[OpenCL] Remove subgroups pragma in enqueue kernel and pipe builtins.
Anastasia Stulova [Thu, 6 May 2021 11:48:46 +0000 (12:48 +0100)]
[OpenCL] Remove subgroups pragma in enqueue kernel and pipe builtins.

This patch simplifies the parser and makes the language semantics
consistent. There is no extension pragma requirement in the spec
for the subgroup functions in enqueue kernel or pipes and all other
builtin functions are available without the pragama.

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

3 years ago[amdgpu-arch] Fix rpath to run from build dir
Jon Chesterfield [Thu, 6 May 2021 12:06:59 +0000 (13:06 +0100)]
[amdgpu-arch] Fix rpath to run from build dir

[amdgpu-arch] Fix rpath to run from build dir

Prior to this, amdgpu-arch has RUNPATH set to $ORIGIN/../lib which works
for some installs, but not from the build directory where clang executes
the tool from when running tests.

This cmake option adds the location of the rocr runtime to the RUNPATH
(note, it amends RUNPATH here, despite the cmake option referring to RPATH)
to create a binary that runs from build or install location.

Before:
RUNPATH [$ORIGIN/../lib]
After:
RUNPATH [$ORIGIN/../lib:$HOME/llvm-install/lib]

Credit to Greg for knowing this trick and pointing to examples of it in use
for the aomp build scripts.

Reviewed By: pdhaliwal

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

3 years ago[AMDGPU] Fix WQM failure with single block inactive demote
Carl Ritson [Thu, 6 May 2021 11:27:03 +0000 (20:27 +0900)]
[AMDGPU] Fix WQM failure with single block inactive demote

Instruction test for inactive kill/demote needs to be based on
actual opcode not whether instruction would be lowered to demote.

Reviewed By: piotr

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

3 years agoRevert "[ARM] Transforming memcpy to Tail predicated Loop"
Malhar Jajoo [Thu, 6 May 2021 11:20:00 +0000 (12:20 +0100)]
Revert "[ARM] Transforming memcpy to Tail predicated Loop"

Reverting commit since it causes failure (10462).
This reverts commit b856f4a232cbd43476e9b9f75c80aacfc6f5c152.

3 years ago[ORC] Silence unused variable warnings in Release builds. NFC.
Benjamin Kramer [Thu, 6 May 2021 11:37:26 +0000 (13:37 +0200)]
[ORC] Silence unused variable warnings in Release builds. NFC.

3 years ago[LV] Account for tripcount when calculation vectorization profitability
David Green [Thu, 6 May 2021 11:36:46 +0000 (12:36 +0100)]
[LV] Account for tripcount when calculation vectorization profitability

The loop vectorizer will currently assume a large trip count when
calculating which of several vectorization factors are more profitable.
That is often not a terrible assumption to make as small trip count
loops will usually have been fully unrolled. There are cases however
where we will try to vectorize them, and especially when folding the
tail by masking can incorrectly choose to vectorize loops that are not
beneficial, due to the folded tail rounding the iteration count up for
the vectorized loop.

The motivating example here has a trip count of 5, so either performs 5
scalar iterations or 2 vector iterations (with VF=4). At a high enough
trip count the vectorization becomes profitable, but the rounding up to
2 vector iterations vs only 5 scalar makes it unprofitable.

This adds an alternative cost calculation when we know the max trip
count and are folding tail by masking, rounding the iteration count up
to the correct number for the vector width. We still do not account for
anything like setup cost or the mixture of vector and scalar loops, but
this is at least an improvement in a few cases that we have had
reported.

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

3 years ago[LLD] Improve --strip-all help text
Ben Dunbobbin [Thu, 6 May 2021 11:05:27 +0000 (12:05 +0100)]
[LLD] Improve --strip-all help text

This is a slight improvement to the help text, as I was slightly
surprised when strip-all did more than remove the symbol table.

Currently, we match gold's help text for strip-all and strip-debug.
I think that the GNU documentation for these options is not particularly
clear. However, I have opted to make only a minor change here and keep
the help text similar to gold's as these are mature options that are
well understood.

ld.bfd (https://sourceware.org/binutils/docs/ld/Options.html) has a
similar implication although it defines strip-debug as a subset of
strip-all. However, felt that noting that strip-all implies strip-debug
is better; because, with the ld.bfd approach you have to read both the
--strip-debug and the --strip-all help text to understand the behaviour
of --strip-all (and the --strip-all help text doesn't indicate that he
--strip-debug help text is related).

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

3 years ago[mlir] Add support for ops with regions in 'gpu-async-region' rewriter.
Christian Sigg [Wed, 5 May 2021 18:06:37 +0000 (20:06 +0200)]
[mlir] Add support for ops with regions in 'gpu-async-region' rewriter.

Reviewed By: herhut

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

3 years ago[AMDGPU] Regenerate fp2int tests. NFCI.
Simon Pilgrim [Thu, 6 May 2021 09:26:24 +0000 (10:26 +0100)]
[AMDGPU] Regenerate fp2int tests. NFCI.

3 years ago[AMDGPU] Regenerate shift tests. NFCI.
Simon Pilgrim [Thu, 6 May 2021 09:25:59 +0000 (10:25 +0100)]
[AMDGPU] Regenerate shift tests. NFCI.

3 years ago[SystemZ] Support builtin_frame_address with packed stack without backchain.
Jonas Paulsson [Sun, 2 May 2021 14:38:05 +0000 (16:38 +0200)]
[SystemZ] Support builtin_frame_address with packed stack without backchain.

In order to use __builtin_frame_address(0) with packed stack and no
backchain, the address of where the backchain would have been written is
returned (like GCC).

This address may either contain a saved register or be unused.

Review: Ulrich Weigand

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

3 years ago[SVE][LoopVectorize] Add support for scalable vectorization of first-order recurrences
Kerry McLaughlin [Thu, 6 May 2021 09:50:51 +0000 (10:50 +0100)]
[SVE][LoopVectorize] Add support for scalable vectorization of first-order recurrences

Adds support for scalable vectorization of loops containing first-order recurrences, e.g:
```
for(int i = 0; i < n; i++)
  b[i] =  a[i] + a[i - 1]
```
This patch changes fixFirstOrderRecurrence for scalable vectors to take vscale into
account when inserting into and extracting from the last lane of a vector.
CreateVectorSplice has been added to construct a vector for the recurrence, which
returns a splice intrinsic for scalable types. For fixed-width the behaviour
remains unchanged as CreateVectorSplice will return a shufflevector instead.

The tests included here are the same as test/Transform/LoopVectorize/first-order-recurrence.ll

Reviewed By: david-arm, fhahn

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

3 years ago[clang-format] Rename common types between C#/JS
Eliza Velasquez [Thu, 6 May 2021 10:12:05 +0000 (12:12 +0200)]
[clang-format] Rename common types between C#/JS

Reviewed By: curdeius

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

3 years ago[clang-format] Fix C# nullable-related errors
Eliza Velasquez [Thu, 6 May 2021 10:06:00 +0000 (12:06 +0200)]
[clang-format] Fix C# nullable-related errors

This fixes two errors:

Previously, clang-format was splitting up type identifiers from the
nullable ?. This changes this behavior so that the type name sticks with
the operator.

Additionally, nullable operators attached to return types in interface
functions were not parsed correctly. Digging deeper, it looks like
interface bodies were being parsed differently than classes and structs,
causing MustBeDeclaration to be incorrect for interface members. They
now share the same logic.

One other change is reintroducing the CSharpNullable type independent of
JsTypeOptionalQuestion. Despite having a similar semantic purpose, their
actual syntax differs quite a bit.

Reviewed By: MyDeveloperDay, curdeius

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

3 years ago[clang-format] Add more support for C# 8 nullables
Eliza Velasquez [Thu, 6 May 2021 09:22:31 +0000 (11:22 +0200)]
[clang-format] Add more support for C# 8 nullables

This adds support for the null-coalescing assignment and null-forgiving
operators.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-forgiving

Reviewed By: krasimir, curdeius

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

3 years ago[AMDGPU] SIFoldOperands: clean up tryConstantFoldOp
Jay Foad [Wed, 7 Apr 2021 12:49:07 +0000 (13:49 +0100)]
[AMDGPU] SIFoldOperands: clean up tryConstantFoldOp

First clean up the strange API of tryConstantFoldOp where it took an
immediate operand value, but no indication of which operand it was the
value for.

Second clean up the loop that calls tryConstantFoldOp so that it does
not have to restart from the beginning every time it folds an
instruction.

This is NFCI but there are some minor changes caused by the order in
which things are folded.

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

3 years ago[flang] Remove `%f18` from LIT configuration files
Andrzej Warzynski [Fri, 23 Apr 2021 14:46:35 +0000 (14:46 +0000)]
[flang] Remove `%f18` from LIT configuration files

`%f18` was originally introduced to represent the old Flang driver,
`f18`. With the introduction of the new driver, `flang-new`, we have
been switching to `%flang` (compiler driver) and `%flang_fc1` (frontend
driver) as more generic alternatives.

As most tests have been portend to use the new LIT variables instead of
`%f18`, this is good time to remove it from lit.cfg.py. There's only one
test left that requires the old driver to run. It's updated with:
```
! REQUIRES: old-flang-driver
```
This way we preserve its semantics while reducing the number of
variables in LIT configuration.

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

3 years ago[ARM] Transforming memcpy to Tail predicated Loop
Malhar Jajoo [Thu, 6 May 2021 00:38:20 +0000 (01:38 +0100)]
[ARM] Transforming memcpy to Tail predicated Loop

This patch converts llvm.memcpy intrinsic into Tail Predicated
Hardware loops for a target that supports the Arm M-profile
Vector Extension (MVE).

From an implementation point of view, the patch

- adds an ARM specific SDAG Node (to which the llvm.memcpy intrinsic is lowered to, during first phase of ISel)
- adds a corresponding TableGen entry to generate a pseudo instruction, with a custom inserter,
  on matching the above node.
- Adds a custom inserter function that expands the pseudo instruction into MIR suitable
   to be (by later passes) into a WLSTP loop.

Note: A cli option is used to control the conversion of memcpy to TP
loop and this option is currently disabled by default. It may be enabled
in the future after further downstream testing.

Reviewed By: dmgreen

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

3 years ago[lit] Report tool path from use_llvm_tool if found via env variable
James Henderson [Wed, 5 May 2021 10:56:46 +0000 (11:56 +0100)]
[lit] Report tool path from use_llvm_tool if found via env variable

Previously, if the search_env argument was specified, and the tool was
found at that location, the path was not reported, unlike other
situations when this function was called. Adding the reporting makes the
function consistent.

Reviewed by: thopre

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

3 years ago[llvm-objdump] Use std::make_unique
Tim Renouf [Tue, 4 May 2021 09:10:41 +0000 (10:10 +0100)]
[llvm-objdump] Use std::make_unique

Fix up my recent commit rG1128311a19179ceca799ff0fbc4dd206ab56e560 to
use std::make_unique instead of std::unique_ptr(new), as requested by
David Blaikie.

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

3 years ago[llvm][NFC] Remove CallingConvLower deprecated alignment functions
Guillaume Chatelet [Thu, 6 May 2021 07:46:19 +0000 (07:46 +0000)]
[llvm][NFC] Remove CallingConvLower deprecated alignment functions

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

3 years ago[llvm][NFC] Remove SelectionDag alignment deprecated functions
Guillaume Chatelet [Thu, 6 May 2021 07:44:14 +0000 (07:44 +0000)]
[llvm][NFC] Remove SelectionDag alignment deprecated functions

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

3 years ago[llvm][NFC] Remove deprecated InterleaveGroup::getAlignment() function.
Guillaume Chatelet [Thu, 6 May 2021 07:40:18 +0000 (07:40 +0000)]
[llvm][NFC] Remove deprecated InterleaveGroup::getAlignment() function.

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

3 years ago[llvm][NFC] Remove deprecated DataLayout::getPreferredAlignment functions
Guillaume Chatelet [Thu, 6 May 2021 07:28:00 +0000 (07:28 +0000)]
[llvm][NFC] Remove deprecated DataLayout::getPreferredAlignment functions

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

3 years ago[llvm][NFC] Remove deprecated Alignment::None()
Guillaume Chatelet [Thu, 6 May 2021 07:21:23 +0000 (07:21 +0000)]
[llvm][NFC] Remove deprecated Alignment::None()

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

3 years ago[OpenMP] Overhaul `declare target` handling
Johannes Doerfert [Thu, 22 Apr 2021 05:57:28 +0000 (00:57 -0500)]
[OpenMP] Overhaul `declare target` handling

This patch fixes various issues with our prior `declare target` handling
and extends it to support `omp begin declare target` as well.

This started with PR49649 in mind, trying to provide a way for users to
avoid the "ref" global use introduced for globals with internal linkage.
From there it went down the rabbit hole, e.g., all variables, even
`nohost` ones, were emitted into the device code so it was impossible to
determine if "ref" was needed late in the game (based on the name only).
To make it really useful, `begin declare target` was needed as it can
carry the `device_type`. Not emitting variables eagerly had a ripple
effect. Finally, the precedence of the (explicit) declare target list
items needed to be taken into account, that meant we cannot just look
for any declare target attribute to make a decision. This caused the
handling of functions to require fixup as well.

I tried to clean up things while I was at it, e.g., we should not "parse
declarations and defintions" as part of OpenMP parsing, this will always
break at some point. Instead, we keep track what region we are in and
act on definitions and declarations instead, this is what we do for
declare variant and other begin/end directives already.

Highlights:
  - new diagnosis for restrictions specificed in the standard,
  - delayed emission of globals not mentioned in an explicit
    list of a declare target,
  - omission of `nohost` globals on the host and `host` globals on the
    device,
  - no explicit parsing of declarations in-between `omp [begin] declare
    variant` and the corresponding end anymore, regular parsing instead,
  - precedence for explicit mentions in `declare target` lists over
    implicit mentions in the declaration-definition-seq, and
  - `omp allocate` declarations will now replace an earlier emitted
    global, if necessary.

---

Notes:

The patch is larger than I hoped but it turns out that most changes do
on their own lead to "inconsistent states", which seem less desirable
overall.

After working through this I feel the standard should remove the
explicit declare target forms as the delayed emission is horrible.
That said, while we delay things anyway, it seems to me we check too
often for the current status even though that is often not sufficient to
act upon. There seems to be a lot of duplication that can probably be
trimmed down. Eagerly emitting some things seems pretty weak as an
argument to keep so much logic around.

---

Reviewed By: ABataev

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

3 years ago[OpenMP] Ensure the DefaultMapperId has a location
Johannes Doerfert [Fri, 16 Apr 2021 05:44:50 +0000 (00:44 -0500)]
[OpenMP] Ensure the DefaultMapperId has a location

A user reported an assertion (below) but without a reproducer. I failed to
create a test myself but from the assertion one can derive the problem.
I set the DefaultMapperId location now to make sure this doesn't cause
trouble.

```
clang-13: .../DeclTemplate.h:1940:
void clang::ClassTemplateSpecializationDecl::setPointOfInstantiation(clang::SourceLocation):
Assertion `Loc.isValid() && "point of instantiation must be valid!"' failed.
```

Reviewed By: JonChesterfield

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

3 years ago[OpenMP] Make sure classes work on the device as they do on the host
Johannes Doerfert [Fri, 16 Apr 2021 05:35:29 +0000 (00:35 -0500)]
[OpenMP] Make sure classes work on the device as they do on the host

We do provide `operator delete(void*)` in `<new>` but it should be
available by default. This is mostly boilerplate to test it and the
unconditional include of `<new>` in the header we always in include
on the device.

Reviewed By: JonChesterfield

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

3 years ago[MLIR][GPU][NVVM] Add warp synchronous matrix-multiply accumulate ops
Navdeep Kumar [Thu, 6 May 2021 06:35:07 +0000 (12:05 +0530)]
[MLIR][GPU][NVVM] Add warp synchronous matrix-multiply accumulate ops

Add warp synchronous matrix-multiply accumulate ops in GPU and NVVM
dialect. Add following three ops to GPU dialect :-
  1.) subgroup_mma_load_matrix
  2.) subgroup_mma_store_matrix
  3.) subgroup_mma_compute
Add following three ops to NVVM dialect :-
  1.) wmma.m16n16k16.load.[a,b,c].[f16,f32].row.stride
  2.) wmma.m16n16k16.store.d.[f16,f32].row.stride
  3.) wmma.m16n16k16.mma.row.row.[f16,f32].[f16,f32]

Reviewed By: bondhugula, ftynse, ThomasRaoux

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

3 years ago[clangd] Check if macro is already in the IdentifierTable before loading it
Queen Dela Cruz [Thu, 6 May 2021 06:22:32 +0000 (08:22 +0200)]
[clangd] Check if macro is already in the IdentifierTable before loading it

Having nested macros in the C code could cause clangd to fail an assert in clang::Preprocessor::setLoadedMacroDirective() and crash.

 #1 0x00000000007ace30 PrintStackTraceSignalHandler(void*) /qdelacru/llvm-project/llvm/lib/Support/Unix/Signals.inc:632:1
 #2 0x00000000007aaded llvm::sys::RunSignalHandlers() /qdelacru/llvm-project/llvm/lib/Support/Signals.cpp:76:20
 #3 0x00000000007ac7c1 SignalHandler(int) /qdelacru/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x00007f096604db20 __restore_rt (/lib64/libpthread.so.0+0x12b20)
 #5 0x00007f0964b307ff raise (/lib64/libc.so.6+0x377ff)
 #6 0x00007f0964b1ac35 abort (/lib64/libc.so.6+0x21c35)
 #7 0x00007f0964b1ab09 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21b09)
 #8 0x00007f0964b28de6 (/lib64/libc.so.6+0x2fde6)
 #9 0x0000000001004d1a clang::Preprocessor::setLoadedMacroDirective(clang::IdentifierInfo*, clang::MacroDirective*, clang::MacroDirective*) /qdelacru/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp:116:5

An example of the code that causes the assert failure:
```
...
```

During code completion in clangd, the macros will be loaded in loadMainFilePreambleMacros() by iterating over the macro names and calling PreambleIdentifiers->get(). Since these macro names are store in a StringSet (has StringMap underlying container), the order of the iterator is not guaranteed to be same as the order seen in the source code.

When clangd is trying to resolve nested macros it sometimes attempts to load them out of order which causes a macro to be stored twice. In the example above, ECHO2 macro gets resolved first, but since it uses another macro that has not been resolved it will try to resolve/store that as well. Now there are two MacroDirectives stored in the Preprocessor, ECHO and ECHO2. When clangd tries to load the next macro, ECHO, the preprocessor fails an assert in clang::Preprocessor::setLoadedMacroDirective() because there is already a MacroDirective stored for that macro name.

In this diff, I check if the macro is already inside the IdentifierTable and if it is skip it so that it is not resolved twice.

Reviewed By: kadircet

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

3 years ago[OpenMP][NFC] Refactor Clang OpenMP tests using update_cc_test_checks
Giorgis Georgakoudis [Wed, 5 May 2021 22:13:14 +0000 (15:13 -0700)]
[OpenMP][NFC] Refactor Clang OpenMP tests using update_cc_test_checks

This patch refactors a subset of Clang OpenMP tests, generating checklines using the update_cc_test_checks script. This refactoring facilitates updating the Clang OpenMP code generation codebase by automating test generation.

Reviewed By: jdoerfert

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

3 years ago[SelectionDAG][Mips][PowerPC][RISCV][WebAssembly] Teach computeKnownBits/ComputeNumSi...
Jessica Clarke [Thu, 6 May 2021 03:01:20 +0000 (04:01 +0100)]
[SelectionDAG][Mips][PowerPC][RISCV][WebAssembly] Teach computeKnownBits/ComputeNumSignBits about atomics

Unlike normal loads these don't have an extension field, but we know
from TargetLowering whether these are sign-extending or zero-extending,
and so can optimise away unnecessary extensions.

This was noticed on RISC-V, where sign extensions in the calling
convention would result in unnecessary explicit extension instructions,
but this also fixes some Mips inefficiencies. PowerPC sees churn in the
tests as all the zero extensions are only for promoting 32-bit to
64-bit, but these zero extensions are still not optimised away as they
should be, likely due to i32 being a legal type.

This also simplifies the WebAssembly code somewhat, which currently
works around the lack of target-independent combines with some ugly
patterns that break once they're optimised away.

Re-landed with correct handling in ComputeNumSignBits for Tmp == VTBits,
where zero-extending atomics were incorrectly returning 0 rather than
the (slightly confusing) required return value of 1.

Reviewed By: RKSimon, atanasyan

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

3 years ago[BPF][Test] Disable codegen test on AIX
Jinsong Ji [Thu, 6 May 2021 02:38:31 +0000 (02:38 +0000)]
[BPF][Test] Disable codegen test on AIX

https://reviews.llvm.org/D101194 changed the default getMultiarchTriple in toolchain.
So -march=bpf on AIX will get triple of bpf-ibm-aix now,
this is unexpected and causing test failures.

BPF on AIX is not supported (yet), disable the codegen test on AIX in lit cfg.

Reviewed By: yonghong-song

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

3 years ago[ORC] Add missing library dependency on IRReader.
Lang Hames [Thu, 6 May 2021 02:30:24 +0000 (19:30 -0700)]
[ORC] Add missing library dependency on IRReader.

3 years ago[OpenMP] Fix non-determinism in clang copyin codegen
Giorgis Georgakoudis [Thu, 6 May 2021 01:28:23 +0000 (18:28 -0700)]
[OpenMP] Fix non-determinism in clang copyin codegen

Codegen for OpeMP copyin has non-deterministic IR output due to the unspecified evaluation order in a codegen conditional branch, which makes automatic test generation unreliable. This patch refactors codegen code to avoid this non-determinism.

Reviewed By: jdoerfert

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

3 years ago[ORC] Introduce C API for adding object buffers directly to an object layer.
Lang Hames [Thu, 6 May 2021 01:29:26 +0000 (18:29 -0700)]
[ORC] Introduce C API for adding object buffers directly to an object layer.

This can be useful for clients constructing custom JIT stacks: If the C API
for your custom stack exposes API to obtain a reference to an object layer
(e.g. LLVMOrcLLJITGetObjLinkingLayer) then the newly added
LLVMOrcObjectLayerAddObjectFile and LLVMOrcObjectLayerAddObjectFileWithRT
functions can be used to add objects directly to that layer.

3 years ago[scudo] Add initialization for TSDRegistrySharedT
Christopher Ferris [Thu, 6 May 2021 02:00:30 +0000 (19:00 -0700)]
[scudo] Add initialization for TSDRegistrySharedT

Fixes compilation on Android which has a TSDSharedRegistry object in the config.

Reviewed By: cryptoad, vitalybuka

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

3 years ago[AMDGPU] Switch AnnotateUniformValues to MemorySSA
Stanislav Mekhanoshin [Wed, 5 May 2021 23:28:09 +0000 (16:28 -0700)]
[AMDGPU] Switch AnnotateUniformValues to MemorySSA

This shall speedup compilation and also remove threshold
limitations used by memory dependency analysis.

It also seem to fix the bug in the coalescer_remat.ll
where an SMRD load was used in presence of a potentially
clobbering store.

Fixes: SWDEV-272132

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

3 years ago[AMDGPU] Move insertion of function entry waitcnt later
Austin Kerbow [Tue, 27 Apr 2021 16:29:27 +0000 (09:29 -0700)]
[AMDGPU] Move insertion of function entry waitcnt later

This allows tracking these as preexisting waitcnt.

Reviewed By: rampitec

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

3 years ago[M68k][test][NFC] Scrubing some tests
Min-Yih Hsu [Thu, 6 May 2021 00:46:56 +0000 (17:46 -0700)]
[M68k][test][NFC] Scrubing some tests

Remove unecessary labels and assembly directives. NFC.

3 years ago[AArch64] Replace fixup_aarch64_tlsdesc_call with FirstLiteralRelocationKind + R_AARC...
Fangrui Song [Thu, 6 May 2021 00:41:56 +0000 (17:41 -0700)]
[AArch64] Replace fixup_aarch64_tlsdesc_call with FirstLiteralRelocationKind + R_AARCH64_{,P32_}TLSDESC_CALL

3 years ago[test] Delete redundant arm64-tls-relocs.s
Fangrui Song [Thu, 6 May 2021 00:41:04 +0000 (17:41 -0700)]
[test] Delete redundant arm64-tls-relocs.s

It just replicates tls-relocs.s

3 years ago[InstCombine] Fully disable select to and/or i1 folding
Juneyoung Lee [Sun, 2 May 2021 03:28:16 +0000 (12:28 +0900)]
[InstCombine] Fully disable select to and/or i1 folding

This is a patch that disables the poison-unsafe select -> and/or i1 folding.

It has been blocking D72396 and also has been the source of a few miscompilations
described in llvm.org/pr49688 .
D99674 conditionally blocked this folding and successfully fixed the latter one.
The former one was still blocked, and this patch addresses it.

Note that a few test functions that has `_logical` suffix are now deoptimized.
These are created by @nikic to check the impact of disabling this optimization
by copying existing original functions and replacing and/or with select.

I can see that most of these are poison-unsafe; they can be revived by introducing
freeze instruction. I left comments at fcmp + select optimizations (or-fcmp.ll, and-fcmp.ll)
because I think they are good targets for freeze fix.

Reviewed By: nikic

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

3 years ago[AMDGPU] Revise handling of preexisting waitcnt
Austin Kerbow [Fri, 9 Apr 2021 17:54:21 +0000 (10:54 -0700)]
[AMDGPU] Revise handling of preexisting waitcnt

Preexisting waitcnt may not update the scoreboard if the instruction
being examined needed to wait on fewer counters than what was encoded in
the old waitcnt instruction. Fixing this results in the elimination of
some redudnat waitcnt.

These changes also enable combining consecutive waitcnt into a single
S_WAITCNT or S_WAITCNT_VSCNT instruction.

Reviewed By: rampitec

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

3 years ago[ARM] Simplification to ARMBlockPlacement Pass.
Malhar Jajoo [Wed, 5 May 2021 19:20:46 +0000 (20:20 +0100)]
[ARM] Simplification to ARMBlockPlacement Pass.

It simplifies the logic by moving the predecessor  (preHeader or it's predecessor) above the target (or loopExit),
instead of moving the target to after the predecessor.

Since the loopExit is no longer being moved, directions of any branches within/to it are unaffected.

While the predecessor is being moved, the backwards movement simplifies some considerations,
and the only consideration now required is that a forward WLS to the predecessor should not become backwards.

Reviewed By: dmgreen

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

3 years ago [dfsan] extend a test case to measure origin memory usage
Jianzhou Zhao [Wed, 5 May 2021 00:53:51 +0000 (00:53 +0000)]
 [dfsan] extend a test case to measure origin memory usage

This is to support D101204.

Reviewed By: gbalats

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

3 years ago[M68k][AsmParser] Fix invalid register name parsing logics
Min-Yih Hsu [Sun, 2 May 2021 21:31:38 +0000 (14:31 -0700)]
[M68k][AsmParser] Fix invalid register name parsing logics

Adjust sanity check in register parsing function to allow register
name with more than 2 characters (e.g. ccr).

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

3 years ago[M68k][AsmParser] Support negative integer constants
Min-Yih Hsu [Sun, 2 May 2021 21:27:33 +0000 (14:27 -0700)]
[M68k][AsmParser] Support negative integer constants

Parsing negative integer constants as expressions.

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

3 years ago[M68k][test] Initial migration of MC tests
Min-Yih Hsu [Tue, 27 Apr 2021 16:51:57 +0000 (09:51 -0700)]
[M68k][test] Initial migration of MC tests

As the context depicted by bug 49865[1], we are migrating tests under
`test/CodeGen/M68k/Encoding`, which was originally used to test
instruction encoding using MIR file as input, into `test/MC/M68k`. We
are also adding test directives for AsmParser using the same set of
inputs.

Currently we are converting the original MIR test files into assembly
code as well as translating the original LIT "RUN" statement into one
that only uses built-in LLVM tools (i.e. Get rid of `extract-section`).

However, since AsmParser has not completely finished, many of these
original test cases fail. Thus, this patch only migrate test files
that are passed by the current implementation of AsmParser (and
MCCodeEmitter). The remaining tests (under test/CodeGen/M68k/Encoding)
will be ported alone with the patch that fixes the related issues.

[1]: https://bugs.llvm.org/show_bug.cgi?id=49865

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

3 years ago[WebAssembly] Fix JS code mentions in LowerEmscriptenEHSjLj
Heejin Ahn [Tue, 4 May 2021 04:48:38 +0000 (21:48 -0700)]
[WebAssembly] Fix JS code mentions in LowerEmscriptenEHSjLj

- Removes the mention of fastcomp, which is deprecated.
- Some functions in Emscripten have moved from JS glue code to
  compiler-rt/emscripten_setjmp.c and
  compiler-rt/emscripten_exception_builtins.c. This fixes comments about
  that.

Reviewed By: sbc100

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

3 years ago[flang] Provide access to constant character array data
peter klausler [Fri, 23 Apr 2021 23:30:34 +0000 (16:30 -0700)]
[flang] Provide access to constant character array data

Allow direct access to constant character array data (for creating a hash ID of a constant).

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

3 years ago[mlir] Check generated IR of math_polynomial_approx.mlir
Emilio Cota [Wed, 5 May 2021 23:41:22 +0000 (16:41 -0700)]
[mlir] Check generated IR of math_polynomial_approx.mlir

Instead of just checking that we emit something.

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

3 years ago[tests] Update Transforms/FunctionAttrs/nosync.ll
Nicolai Hähnle [Wed, 5 May 2021 23:36:45 +0000 (01:36 +0200)]
[tests] Update Transforms/FunctionAttrs/nosync.ll

Commit generated by running update_test_checks.py, to reflect the fact
that we now add the `mustprogress` attribute.

3 years ago[AArch64] Deleted unused AsmBackend functions
Fangrui Song [Wed, 5 May 2021 23:28:39 +0000 (16:28 -0700)]
[AArch64] Deleted unused AsmBackend functions

3 years ago[MCAsmInfo] Support UsesCFIForDebug for targets with no exception handling
RamNalamothu [Wed, 5 May 2021 23:18:59 +0000 (04:48 +0530)]
[MCAsmInfo] Support UsesCFIForDebug for targets with no exception handling

This change enables emitting CFI unwind information for debugging purpose
for targets with MCAsmInfo::ExceptionsType == ExceptionHandling::None.

Currently generating CFI unwind information is entangled with supporting
the exceptions, even when AsmPrinter explicitly recognizes that the unwind
tables are being generated as debug information.

In fact, the unwind information is not generated even if we specify
--force-dwarf-frame-section, unless exceptions are enabled. The LIT test
llvm/test/CodeGen/AMDGPU/debug_frame.ll demonstrates this behavior.

Enable this option for AMDGPU to prepare for future patches which add
complete CFI support.

Reviewed By: dblaikie, MaskRay

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

3 years ago[mlir][Linalg] Fix test to use new reshape op form.
MaheshRavishankar [Wed, 5 May 2021 23:05:44 +0000 (16:05 -0700)]
[mlir][Linalg] Fix test to use new reshape op form.

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

3 years agoAttach metadata to simplified masked loads and stores
Coplin, Jared [Wed, 20 Jan 2021 22:11:49 +0000 (16:11 -0600)]
Attach metadata to simplified masked loads and stores

3 years agoAllow /STACK in #pragma comment(linker, ...)
Alex Reinking [Wed, 5 May 2021 22:54:17 +0000 (15:54 -0700)]
Allow /STACK in #pragma comment(linker, ...)

The Halide project uses `#pragma comment(linker, "/STACK:...")` to set
the stack size high enough for our embedded compiler to run in end-user
programs on Windows.

Unfortunately, lld-link.exe breaks on this when embedded in a COFF
object, despite supporting the flag on the command line. MSVC's link.exe
supports this fine. This patch extends support for this to lld-link.exe
for better compatibility with MSVC projects.

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

3 years agoAMDGPU: Fix lit test
Matt Arsenault [Wed, 5 May 2021 22:40:58 +0000 (18:40 -0400)]
AMDGPU: Fix lit test

3 years ago[mlir][Linalg] Fix element type of results when folding reshapes.
MaheshRavishankar [Wed, 5 May 2021 22:38:25 +0000 (15:38 -0700)]
[mlir][Linalg] Fix element type of results when folding reshapes.

Fixing a minor bug which lead to element type of the output being
modified when folding reshapes with generic op.

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

3 years ago[AArch64] Fix some coding standard issues related to namespace llvm
Fangrui Song [Wed, 5 May 2021 22:27:16 +0000 (15:27 -0700)]
[AArch64] Fix some coding standard issues related to namespace llvm

https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions

3 years ago[Driver] Move -print-runtime-dir and -print-resource-dir tests
Petr Hosek [Tue, 4 May 2021 05:05:27 +0000 (22:05 -0700)]
[Driver] Move -print-runtime-dir and -print-resource-dir tests

Put these into a separate files to match other -print-* options tests.

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

3 years ago[AMDGPU][GlobalISel] Widen 1 and 2 byte scalar loads
Vang Thao [Wed, 14 Apr 2021 00:51:58 +0000 (17:51 -0700)]
[AMDGPU][GlobalISel] Widen 1 and 2 byte scalar loads

Widen 1 and 2 byte scalar loads to 4 bytes when sufficiently
aligned to avoid using a global load.

Reviewed By: arsenm

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

3 years ago[gn build] (semi-manually) port 0b10bb7ddd3c more
Nico Weber [Wed, 5 May 2021 22:15:07 +0000 (18:15 -0400)]
[gn build] (semi-manually) port 0b10bb7ddd3c more

3 years ago[lldb] Handle missing SBStructuredData copy assignment cases
Dave Lee [Thu, 29 Apr 2021 23:03:46 +0000 (16:03 -0700)]
[lldb] Handle missing SBStructuredData copy assignment cases

Fix cases that can crash `SBStructuredData::operator=`.

This happened in a case where `rhs` had a null `SBStructuredDataImpl`.

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

3 years ago[lld-macho] Check simulator platforms to avoid issuing false positive errors.
Vy Nguyen [Tue, 4 May 2021 20:23:21 +0000 (16:23 -0400)]
[lld-macho] Check simulator platforms to avoid issuing false positive errors.

Currently the linker causes unnecessary errors when either the target or the config's platform is a simulator.

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

3 years ago[gn build] (semi-manually) port 0b10bb7ddd3c
Nico Weber [Wed, 5 May 2021 22:06:52 +0000 (18:06 -0400)]
[gn build] (semi-manually) port 0b10bb7ddd3c

3 years agoAMDGPU: Add a few more tail call tests
Matt Arsenault [Sun, 14 Mar 2021 17:52:31 +0000 (13:52 -0400)]
AMDGPU: Add a few more tail call tests

Add some cases I noticed were missing when porting to GlobalISel. The
cases that required any argument splitting did not work at first.

3 years agoARM/GlobalISel: Don't store a MachineInstrBuilder reference
Matt Arsenault [Wed, 5 May 2021 21:22:10 +0000 (17:22 -0400)]
ARM/GlobalISel: Don't store a MachineInstrBuilder reference

This is basically a pointer anyway

3 years agoWhen performing template argument deduction to select a partial
Richard Smith [Wed, 5 May 2021 21:44:49 +0000 (14:44 -0700)]
When performing template argument deduction to select a partial
specialization while substituting a partial template parameter pack,
don't try to extend the existing deduction.

This caused us to select the wrong partial specialization in some rare
cases. A recent change to libc++ caused this to happen in practice for
code using std::conjunction.

3 years ago[AMDGPU] Improve global SADDR selection
Stanislav Mekhanoshin [Mon, 3 May 2021 18:01:13 +0000 (11:01 -0700)]
[AMDGPU] Improve global SADDR selection

An address can be a uniform sum of two i64 bit values.
That regularly happens in a loop where index is an induction
variable promoted to 64 bit by the LSR. We can materialize
zero in a VGPR and still use SADDR form of the load.

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

3 years ago[clangd] Split CC and refs limit and increase refs limit to 1000
Kirill Bobyrev [Wed, 5 May 2021 21:39:37 +0000 (23:39 +0200)]
[clangd] Split CC and refs limit and increase refs limit to 1000

Related discussion: https://github.com/clangd/clangd/discussions/761

Reviewed By: kadircet

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

3 years agoGlobalISel: Update documentation
Matt Arsenault [Wed, 5 May 2021 17:55:24 +0000 (13:55 -0400)]
GlobalISel: Update documentation

3 years agoAMDGPU/GlobalISel: Remove unnecessary override
Matt Arsenault [Wed, 5 May 2021 02:29:30 +0000 (22:29 -0400)]
AMDGPU/GlobalISel: Remove unnecessary override

This is the same as the default implementation

3 years agoX86/GlobalISel: Use generic version of splitToValueTypes
Matt Arsenault [Sun, 28 Feb 2021 16:35:37 +0000 (11:35 -0500)]
X86/GlobalISel: Use generic version of splitToValueTypes

The custom insert of an unmerge and the callback weirdness should be
unnecessary. Since handleAssignments should now use
getRegisterTypeForCalling conv as SelectionDAG builder would, this
should now just be able to use the generic code. X86-32 relies on the
generated CCAssignFns not seeing illegal types and sharing code with
x86_64, so i64 values would incorrectly be assigned to 64-bit
registers.

3 years agoGlobalISel: Use DAG call lowering infrastructure in a more compatible way
Matt Arsenault [Tue, 13 Apr 2021 17:45:35 +0000 (13:45 -0400)]
GlobalISel: Use DAG call lowering infrastructure in a more compatible way

Unfortunately the current call lowering code is built on top of the
legacy MVT/DAG based code. However, GlobalISel was not using it the
same way. In short, the DAG passes legalized types to the assignment
function, and GlobalISel was passing the original raw type if it was
simple.

I do believe the DAG lowering is conceptually broken since it requires
picking a type up front before knowing how/where the value will be
passed. This ends up being a problem for AArch64, which wants to pass
i1/i8/i16 values as a different size if passed on the stack or in
registers.

The argument type decision is split across 3 different places which is
hard to follow. SelectionDAG builder uses
getRegisterTypeForCallingConv to pick a legal type, tablegen gives the
illusion of controlling the type, and the target may have additional
hacks in the C++ part of the call lowering. AArch64 hacks around this
by not using the standard AnalyzeFormalArguments and special casing
i1/i8/i16 by looking at the underlying type of the original IR
argument.

I believe people have generally assumed the calling convention code is
processing the original types, and I've discovered a number of dead
paths in several targets.

x86 actually relies on the opposite behavior from AArch64, and relies
on x86_32 and x86_64 sharing calling convention code where the 64-bit
cases implicitly do not work on x86_32 due to using the pre-legalized
types.

AMDGPU targets without legal i16/f16 have always used a broken ABI
that promotes to i32/f32. GlobalISel accidentally fixed this to be the
ABI we should have, but this fixes it so we're using the worse ABI
that is compatible with the DAG. Ideally we would fix the DAG to match
the old GlobalISel behavior, but I don't wish to fight that battle.

A new native GlobalISel call lowering framework should let the target
process the incoming types directly.

CCValAssigns select a "ValVT" and "LocVT" but the meanings of these
aren't entirely clear. Different targets don't use them consistently,
even within their own call lowering code. My current belief is the
intent was "ValVT" is supposed to be the legalized value type to use
in the end, and and LocVT was supposed to be the ABI passed type
(which is also legalized).

With the default CCState::Analyze functions always passing the same
type for these arguments, these only differ when the TableGen part of
the lowering decide to promote the type from one legal type to
another. AArch64's i1/i8/i16 hack ends up inverting the meanings of
these values, so I had to add an additional hack to let the target
interpret how large the argument memory is.

Since targets don't consistently interpret ValVT and LocVT, this
doesn't produce quite equivalent code to the initial DAG
lowerings. I've opted to consistently interpret LocVT as the in-memory
size for stack passed values, and ValVT as the register type to assign
from that memory. We therefore produce extending loads directly out of
the IRTranslator, whereas the DAG would emit regular loads of smaller
values. This will also produce loads/stores that are wider than the
argument value if the allocated stack slot is larger (and there will
be undef padding bytes). If we had the optimizations to reduce
load/stores based on truncated values, this wouldn't produce a
different end result.

Since ValVT/LocVT are more consistently interpreted, we now will emit
more G_BITCASTS as requested by the CCAssignFn. For example AArch64
was directly assigning types to some physical vector registers which
according to the tablegen spec should have been casted to a vector
with a different element type.

This also moves the responsibility for inserting
G_ASSERT_SEXT/G_ASSERT_ZEXT from the target ValueHandlers into the
generic code, which is closer to how SelectionDAGBuilder works.

I had to xfail an x86 test since I don't see a quick way to fix it
right now (I filed bug 50035 for this). It's broken independently of
this change, and only triggers since now we end up with more ands
which hit the improperly handled selection pattern.

I also observed that FP arguments that need promotion (e.g. f16 passed
as f32) are broken, and use regular G_TRUNC and G_ANYEXT.

TLDR; the current call lowering infrastructure is bad and nobody has
ever understood how it chooses types.

3 years ago[mlir] Add polynomial approximation for math::ExpM1
Emilio Cota [Wed, 5 May 2021 21:26:50 +0000 (14:26 -0700)]
[mlir] Add polynomial approximation for math::ExpM1

This approximation matches the one in Eigen.

```
name                      old cpu/op  new cpu/op  delta
BM_mlir_Expm1_f32/10      90.9ns ± 4%  52.2ns ± 4%  -42.60%    (p=0.000 n=74+87)
BM_mlir_Expm1_f32/100      837ns ± 3%   231ns ± 4%  -72.43%    (p=0.000 n=79+69)
BM_mlir_Expm1_f32/1k      8.43µs ± 3%  1.58µs ± 5%  -81.30%    (p=0.000 n=77+83)
BM_mlir_Expm1_f32/10k     83.8µs ± 3%  15.4µs ± 5%  -81.65%    (p=0.000 n=83+69)
BM_eigen_s_Expm1_f32/10   68.8ns ±17%  72.5ns ±14%   +5.40%  (p=0.000 n=118+115)
BM_eigen_s_Expm1_f32/100   694ns ±11%   717ns ± 2%   +3.34%   (p=0.000 n=120+75)
BM_eigen_s_Expm1_f32/1k   7.69µs ± 2%  7.97µs ±11%   +3.56%   (p=0.000 n=95+117)
BM_eigen_s_Expm1_f32/10k  88.0µs ± 1%  89.3µs ± 6%   +1.45%   (p=0.000 n=74+106)
BM_eigen_v_Expm1_f32/10   44.3ns ± 6%  45.0ns ± 8%   +1.45%   (p=0.018 n=81+111)
BM_eigen_v_Expm1_f32/100   351ns ± 1%   360ns ± 9%   +2.58%    (p=0.000 n=73+99)
BM_eigen_v_Expm1_f32/1k   3.31µs ± 1%  3.42µs ± 9%   +3.37%   (p=0.000 n=71+100)
BM_eigen_v_Expm1_f32/10k  33.7µs ± 8%  34.1µs ± 9%   +1.04%    (p=0.007 n=99+98)
```

Reviewed By: ezhulenev

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

3 years ago[MachineCSE][NFC]: Refactor and comment on preventing CSE for isConvergent instrs
Michael Kitzan [Sat, 1 May 2021 02:50:54 +0000 (19:50 -0700)]
[MachineCSE][NFC]: Refactor and comment on preventing CSE for isConvergent instrs

- Move the code preventing CSE of `isConvergent` instrs into
  `ProcessBlockCSE` (from `isProfitableToCSE`)
- Add comments explaining why `isConvergent` is used to prevent
  CSE of non-local instrs in MachineCSE and the new test