platform/upstream/llvm.git
2 years ago[mlir][sparse] add new complex ops to reduction recognition
Aart Bik [Tue, 24 May 2022 18:49:47 +0000 (11:49 -0700)]
[mlir][sparse] add new complex ops to reduction recognition

Reviewed By: bixia

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

2 years ago[RISCV] Add an operand kind to the opcode/imm returned from RISCVMatInt.
Craig Topper [Tue, 24 May 2022 21:54:57 +0000 (14:54 -0700)]
[RISCV] Add an operand kind to the opcode/imm returned from RISCVMatInt.

Instead of matching opcodes to know the format to emit, use an
enum value that we can get from the RISCVMatInt::Inst class.

Change the consumers to use fully covered switches so that we get
a compiler warning if a new kind is added. With the opcode checks
it was easier to forget to update one of the 3 consumers.

Reviewed By: reames

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

2 years ago[riscv] Use getFirstInstrTerminator [nfc]
Philip Reames [Tue, 24 May 2022 21:55:42 +0000 (14:55 -0700)]
[riscv] Use getFirstInstrTerminator [nfc]

2 years ago[RISCV] Hoist VSETVLI out of idiomatic fixed length vector loops
Philip Reames [Tue, 24 May 2022 21:17:43 +0000 (14:17 -0700)]
[RISCV] Hoist VSETVLI out of idiomatic fixed length vector loops

This patch teaches the VSETVLI insertion pass to perform a very limited form of partial redundancy elimination. The motivating example comes from the fixed length vectorization of a simple loop such as:

for (unsigned i = 0; i < a_len; i++)
    a[i] += b;

Without this change, the core vector loop and preheader is as follows:

.LBB0_3:                                # %vector.ph
andi a1, a6, -8
addi a4, a0, 16
mv a5, a1
.LBB0_4:                                # %vector.body
                                        # =>This Inner Loop Header: Depth=1
addi a3, a4, -16
vsetivli zero, 4, e32, m1, ta, mu
vle32.v v8, (a3)
vle32.v v9, (a4)
vadd.vx v8, v8, a2
vadd.vx v9, v9, a2
vse32.v v8, (a3)
vse32.v v9, (a4)
addi a5, a5, -8
addi a4, a4, 32
bnez a5, .LBB0_4

The key thing to note here is that, the execution of the vsetivli only needs to happen once. Since there's no tail folding happening here, the value of the vector configuration registers are invariant through the loop.

After this patch, we hoist the configuration into the preheader and perform it once.

.LBB0_3:                                # %vector.ph
andi a1, a6, -8
vsetivli zero, 4, e32, m1, ta, mu
addi a4, a0, 16
mv a5, a1
.LBB0_4:                                # %vector.body
                                        # =>This Inner Loop Header: Depth=1
addi a3, a4, -16
vle32.v v8, (a3)
vle32.v v9, (a4)
vadd.vx v8, v8, a2
vadd.vx v9, v9, a2
vse32.v v8, (a3)
vse32.v v9, (a4)
addi a5, a5, -8
addi a4, a4, 32
bnez a5, .LBB0_4

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

2 years ago[SelectionDAG] Add support to widen ISD::STEP_VECTOR operations.
Paul Walker [Sun, 22 May 2022 12:49:01 +0000 (13:49 +0100)]
[SelectionDAG] Add support to widen ISD::STEP_VECTOR operations.

Fixes: #55165

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

2 years ago[Flang][OpenMP] Fixes for unstructured OpenMP code
Kiran Chandramohan [Tue, 24 May 2022 21:31:57 +0000 (21:31 +0000)]
[Flang][OpenMP] Fixes for unstructured OpenMP code

Since the FIR operations are mostly structured, it is only the functions
that could contain multiple blocks inside an operation. This changes
with OpenMP since OpenMP regions can contain multiple blocks. For
unstructured code, the blocks are created in advance and belong to the
top-level function. This caused code in OpenMP region to be placed under
the function level.

In this fix, if the OpenMP region is unstructured then new blocks are
created inside it.

Note1: This is part of upstreaming from the fir-dev branch of
https://github.com/flang-compiler/f18-llvm-project. The code in this patch is a
subset of the changes in https://github.com/flang-compiler/f18-llvm-project/pull/1178.

Reviewed By: vdonaldson

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

Co-authored-by: Val Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
2 years agoFix build failure revealed by c35ca3a1c78f693b749ad11742350b7fc6c5cd89
Amy Kwan [Tue, 24 May 2022 21:11:23 +0000 (16:11 -0500)]
Fix build failure revealed by c35ca3a1c78f693b749ad11742350b7fc6c5cd89

This commit resolves a Linux kernel build failure that was revealed by
c35ca3a1c78f693b749ad11742350b7fc6c5cd89. The patch introduces two new
intrinsics, which ultimately changes the intrinsic numbering of other PPC
intrinsics. This causes an issue introduced by
ff40fb07ad6309131c2448ca00572a078c7a2d59, as the patch checks for intrinsics
with particular values, but the addition of the fnabs/fnabss intrinsics updates
the original sqrt/sdiv intrinsic values.

2 years ago[flang][runtime] Catch decimal integer input overflow
Peter Klausler [Fri, 20 May 2022 23:16:09 +0000 (16:16 -0700)]
[flang][runtime] Catch decimal integer input overflow

B/O/Z input overflow is already caught, and real input overflow
is signalled as an IEEE arithmetic exception, but regular decimal
integer overflow was silent.

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

2 years ago[flang] Replace crash and improve a semantics TODO message
Peter Klausler [Fri, 20 May 2022 21:21:59 +0000 (14:21 -0700)]
[flang] Replace crash and improve a semantics TODO message

The derived type information table construction code had a
crash whose root cause was replacing an expression with one
of its operands -- the deletion of the LHS of that assignment
led to the RHS being invalidated before it could be read.
Fix by cloning the RHS.  Also update a TODO message to the
new "_todo_en_US" message class and add a comment about how
it should be resolved.

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

2 years ago[flang] Process subprogram BIND(C,NAME=...) locally
Peter Klausler [Fri, 20 May 2022 20:31:14 +0000 (13:31 -0700)]
[flang] Process subprogram BIND(C,NAME=...) locally

The scalar-default-character-expression that defines the interoperable
name of a function or subroutine (or interface) must have its names
resolved within the context of the subprogram, despite its appearance
on a function-stmt or a subroutine-stmt.  Failure to do so can lead
to bogus errors or to incorrect results.

The solution is to defer name resolution for function-stmt suffixes
(but not entry-stmt suffixes) and for subroutine-stmt language binding
specifications to EndSubprogram().  (Their resolution only need to be
deferred to the end of the specification part, but it's cleanest to
deal with it in EndSubprogram().)

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

2 years ago[clang][dataflow] Relax `Environment` comparison operation.
Yitzhak Mandelbaum [Tue, 24 May 2022 18:45:59 +0000 (18:45 +0000)]
[clang][dataflow] Relax `Environment` comparison operation.

Ignore `MemberLocToStruct` in environment comparison. As an ancillary data
structure, including it is redundant. We also can generate environments which
differ in their `MemberLocToStruct` but are otherwise equivalent.

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

2 years ago[flang] Fix false error for multiple defined I/O subroutines
Peter Klausler [Fri, 20 May 2022 15:45:46 +0000 (08:45 -0700)]
[flang] Fix false error for multiple defined I/O subroutines

User-defined derived type I/O subroutines need to be unique for
a given type and operation in any scope, but it is acceptable
to have more than one defined I/O subroutine so long as only one
of them is visible.

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

2 years ago[flang] Accept defined assignment with CLASS(*) RHS
Peter Klausler [Thu, 19 May 2022 23:30:04 +0000 (16:30 -0700)]
[flang] Accept defined assignment with CLASS(*) RHS

A utility predicate in semantics was incorrectly determining that
an INTERFACE ASSIGNMENT(=) (or other form of generic) could not have
a specific procedure with an unlimited polymorphic second argument.
This led to a crash later in expression analysis.  Fix, and
extend tests.

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

2 years ago[flang] Fix purity testing for generic calls
Peter Klausler [Thu, 19 May 2022 22:32:06 +0000 (15:32 -0700)]
[flang] Fix purity testing for generic calls

The purity or impurity of a call to a generic interface
depends on the attributes of the specific procedure or specific
binding.  Change expression analysis of calls to generic interfaces
to replace the symbol in the parse tree with the specific procedure
or binding; this ensures that later checking for purity in
DO CONCURRENT and other contexts will be accurate.

Remove an "XFAIL" from a test that now passes again with this fix.

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

2 years ago[clang][test] mark tests added in ee8524087c78 as unsupported on AIX
Alex Lorenz [Tue, 24 May 2022 20:38:04 +0000 (13:38 -0700)]
[clang][test] mark tests added in ee8524087c78 as unsupported on AIX

These tests are failing on the PPC64 AIX CI bot, but it's unclear why,
as they pass on other CI jobs.
I marked them as unsupported on AIX for now while investigating the failure.

2 years ago[flang] Don't prematurely resolve subprogram names
Peter Klausler [Thu, 19 May 2022 21:17:17 +0000 (14:17 -0700)]
[flang] Don't prematurely resolve subprogram names

Name resolution for subprograms checks whether the name is already
present in the enclosing scope as a generic interface, so that the
case of a generic with the same name as one of its specifics can be
handled.  The particular means by which the enclosing scope is searched
for the name would resolve the name (bind a symbol to it) as a side
effect.  This turns out to be the wrong thing to do when the subprogram
is going to have its symbol created in another scope to cope with its
BIND(C,NAME="name") name, and its Fortran name is already present in the
enclosing scope for a subprogram of the same name but without
BIND(C,NAME="name").

A very long explanation for a one-line fix, sorry.  In short, change
the code to look up the name but not resolve it at that point.

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

2 years ago[clang][dataflow] Make limit on fixpoint-algorithm iterations proportional to size...
Yitzhak Mandelbaum [Tue, 24 May 2022 19:04:54 +0000 (19:04 +0000)]
[clang][dataflow] Make limit on fixpoint-algorithm iterations proportional to size of CFG.

Currently, the maximum number of iterations of the loop for finding the fixpoint
of the dataflow analysis is set at 2^16. When things go wrong in an analysis,
this can be far too large.  This patch changes the limit to be proportional to
the size of the CFG, which will generally be far smaller than 2^16 (while still
maintaining 2^16 as the absolute limit).

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

2 years ago[Sanitizers][Darwin] Replace SANITIZER_MAC with SANITIZER_APPLE in source files
Mariusz Borsa [Mon, 23 May 2022 21:35:42 +0000 (14:35 -0700)]
[Sanitizers][Darwin] Replace SANITIZER_MAC with SANITIZER_APPLE in source files

This is a follow up to [Sanitizers][Darwin] Rename Apple macro SANITIZER_MAC -> SANITIZER_APPLE (D125816)

Performed a global search/replace as in title against LLVM sources

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

2 years ago[flang] Catch calls to assumed-length character functions
Peter Klausler [Wed, 18 May 2022 22:44:01 +0000 (15:44 -0700)]
[flang] Catch calls to assumed-length character functions

Semantics was allowing calls to CHARACTER(*) functions, which are odd
things -- they can be declared, and passed around, but can never actually
be called as such.  They must be redeclared with an explicit length that
ends up being passed as a hidden argument.  So check for these calls
and diagnose them, add tests, and clean up some existing tests that
were in error and now get caught.

Possible TODO for lowering: there were some test cases that used
bad calls to assumed-length CHARACTER*(*) functions and validated
their implementations.  I've removed some, and adjusted another,
but the code that somehow implemented these calls may need to be
removed and replaced with an assert about bad semantics.

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

2 years ago[SLP] Fix crash caused by reorderBottomToTop().
Vasileios Porpodas [Tue, 24 May 2022 16:16:30 +0000 (09:16 -0700)]
[SLP] Fix crash caused by reorderBottomToTop().

The crash is caused by incorrect order set by reorderBottomToTop(), which
happens when it is reordering a TreeEntry which has a user that has already been
reordered earlier. Please see the detailed description in the lit test.

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

2 years ago[InstCombine] fold more shuffles with FP<->Int cast operands
Sanjay Patel [Tue, 24 May 2022 19:07:24 +0000 (15:07 -0400)]
[InstCombine] fold more shuffles with FP<->Int cast operands

shuffle (cast X), (cast Y), Mask --> cast (shuffle X, Y, Mask)

This extends the transform added with 0353c2c996c5.

If the shuffle reduces vector length, the transform
reduces the width of the cast, so that should be a
win for most codegen (if not, it can be inverted).

2 years agoRevert "[compiler-rt][scudo] Add missing preprocessor token" and "[compiler-rt][scudo...
Leonard Chan [Tue, 24 May 2022 18:29:44 +0000 (11:29 -0700)]
Revert "[compiler-rt][scudo] Add missing preprocessor token" and "[compiler-rt][scudo] Simplify TBI checks"

This reverts commit 676eaa2ca967ca6ad4a84d31d6f0ebabdcf3e44b
and f6038cdca03115da22b9e6ada5c25de4df5f42d2 since builders are still
broken.

2 years ago[compiler-rt][scudo] Add missing preprocessor token
Leonard Chan [Tue, 24 May 2022 18:11:31 +0000 (11:11 -0700)]
[compiler-rt][scudo] Add missing preprocessor token

This should fix build errors seen on bots like
https://lab.llvm.org/buildbot/#/builders/57/builds/18263.

2 years agoRecommit "[SelectOpti][5/5] Optimize select-to-branch transformation"
Sotiris Apostolakis [Tue, 24 May 2022 03:04:20 +0000 (23:04 -0400)]
Recommit "[SelectOpti][5/5] Optimize select-to-branch transformation"

Use container::size_type directly to avoid type mismatch causing build failures in Windows.

Original commit message:
This patch optimizes the transformation of selects to a branch when the heuristics deemed it profitable.
It aggressively sinks eligible instructions to the newly created true/false blocks to prevent their
execution on the common path and interleaves dependence slices to maximize ILP.

Depends on D120232

Reviewed By: davidxl

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

2 years ago[flang] Fix crash in semantics after PDT instantiation
Peter Klausler [Thu, 19 May 2022 00:48:34 +0000 (17:48 -0700)]
[flang] Fix crash in semantics after PDT instantiation

The code in semantics that reinitializes symbol table pointers in
the parse tree of a parameterized derived type prior to a new
instantiation of the type was processing the symbols of the
derived type instantiation scope in arbitrary address order,
which could fail if a reference to a type parameter inherited from
an ancestor type was processed prior to the parent component sequence.
Fix by instantiating components of PDT instantiations in declaration
order.

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

2 years ago[flang] Alternate entry points with unused arguments
V Donaldson [Tue, 24 May 2022 17:06:24 +0000 (10:06 -0700)]
[flang] Alternate entry points with unused arguments

A dummy argument in an entry point of a subprogram with multiple
entry points need not be defined in other entry points. It is only
legal to reference such an argument when calling an entry point that
does have a definition. An entry point without such a definition
needs a local "substitute" definition sufficient to generate code.
It is nonconformant to reference such a definition at runtime.
Most such definitions and associated code will be deleted as dead
code at compile time. However, that is not always possible, as in
the following code. This code is conformant if all calls to entry
point ss set m=3, and all calls to entry point ee set n=3.

subroutine ss(a, b, m, d, k) ! no x, y, n
  integer :: a(m), b(a(m)), m, d(k)
  integer :: x(n), y(x(n)), n
  integer :: k
1 print*, m, k
  print*, a
  print*, b
  print*, d
  if (m == 3) return
entry ee(x, y, n, d, k) ! no a, b, m
  print*, n, k
  print*, x
  print*, y
  print*, d
  if (n /= 3) goto 1
end

  integer :: xx(3), yy(5), zz(3)
  xx = 5
  yy = 7
  zz = 9
  call ss(xx, yy, 3, zz, 3)
  call ss(xx, yy, 3, zz, 3)
end

Lowering currently generates fir::UndefOp's for all unused arguments.
This is usually ok, but cases such as the one here incorrectly access
unused UndefOp arguments for m and n from an entry point that doesn't
have a proper definition.

The problem is addressed by creating a more complete definition of an
unused argument in most cases. This is implemented in large part by
moving the definition of an unused argument from mapDummiesAndResults
to mapSymbolAttributes. The code in mapSymbolAttributes then chooses
one of three code generation options, depending on information
available there.

This patch deals with dummy procedures in alternate entries, and adds
a TODO for procedure pointers (the PFTBuilder is modified to analyze
procedure pointer symbol so that they are not silently ignored, and
instead hits proper TODOs).

BoxAnalyzer is also changed because assumed-sized arrays were wrongfully
categorized as constant shape arrays.  This had no impact, except when
there were unused entry points.

Co-authored-by: jeanPerier <jperier@nvidia.com>
Differential Revision: https://reviews.llvm.org/D125867

2 years ago[AMDGPU] Disable newly added gfx90a global isel image tests. NFC.
Stanislav Mekhanoshin [Tue, 24 May 2022 17:47:18 +0000 (10:47 -0700)]
[AMDGPU] Disable newly added gfx90a global isel image tests. NFC.

This fixed build failure with expensive checks after D126009.
The change has added new run lines for Global ISel which has
uncovered a pre-existing problem: it does not select a correct
flavor of these image instructions.

2 years ago[compiler-rt][scudo] Simplify TBI checks
Leonard Chan [Tue, 24 May 2022 17:51:42 +0000 (10:51 -0700)]
[compiler-rt][scudo] Simplify TBI checks

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

2 years agoSema: adjust assertion to account for deduced types
Saleem Abdulrasool [Fri, 20 May 2022 20:35:28 +0000 (20:35 +0000)]
Sema: adjust assertion to account for deduced types

Previous changes for the BTF attributes introduced a new sub-tree
visitation.  That uncovered that when accessing the typespec location we
would assert that the type specification is either a type declaration or
`typename`.  However, `typename` was explicitly permitted.  This change
predates the introduction of newer deduced type representations such as
`__underlying_type` from C++ and the addition of the GNU `__typeof__`
expression.

Thanks to aaron.ballman for the valuable discussion and pointer to
`isTypeRep`.

Differential Revision: https://reviews.llvm.org/D126093
Reviewed By: aaron.ballman, yonghong-song

2 years ago[OpenMP] Fix file arguments for embedding bitcode in the linker wrapper
Joseph Huber [Tue, 24 May 2022 17:43:52 +0000 (13:43 -0400)]
[OpenMP] Fix file arguments for embedding bitcode in the linker wrapper

Summary:
The linker wrapper supports embedding bitcode images instead of linked
device images to facilitate JIT in the device runtime. However, we were
incorrectly passing in the file twice when this option was set. This
patch makes sure we only use the intermediate result of the LTO pass and
don't add the final output to the full job.

In the future we will want to add both of these andle handle that
accoridngly to allow the runtime to either use the AoT compiled version
or JIT compile the bitcode version if availible.

2 years ago[OpenMP] Add parsing/sema support for omp_all_memory reserved locator
Mike Rice [Tue, 17 May 2022 17:11:00 +0000 (10:11 -0700)]
[OpenMP] Add parsing/sema support for omp_all_memory reserved locator

Adds support for the reserved locator 'omp_all_memory' for use
in depend clauses with 'out' or 'inout' dependence-types.

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

2 years ago[flang][runtime] Handle BACKSPACE after reading past EOF
Peter Klausler [Wed, 18 May 2022 20:40:33 +0000 (13:40 -0700)]
[flang][runtime] Handle BACKSPACE after reading past EOF

An external READ(END=) that hits the end of the file must
also note the virtual position of the endfile record that
has just been discovered, so that a later BACKSPACE statement
won't end up at the wrong record.

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

2 years ago[compiler-rt][lsan] Update CanBeAHeapPointer for AArch64
Leonard Chan [Tue, 24 May 2022 17:22:46 +0000 (10:22 -0700)]
[compiler-rt][lsan] Update CanBeAHeapPointer for AArch64

While attempting to get the 64-bit lsan allocator working for Fuchsia, I
noticed this function would incorrectly return false for pointers returned
by the 64-bit allocator. On AArch64, this function attempts to get the VMA
size dynamically by counting the number of leading zeros from the function
frame address. This will fail if the frame address is significantly below an
allocated pointer (that is, the frame address has more leading zeros than an
allocated pointer). This is possible on Fuchsia and linux (when not called
from the initial thread stack).

It seems the intended use of this function is to speed up pointer scanning by
filtering out addresses that user code might not be able to access. Other
platforms this check is done on seem to hardcode the VMA size/shift, so it
seems appropriate to do this for aarch64 as well. This implies pointers on
aarch64 where the VMA size is <64 will pass through, but bad pointers will
still be caught by subsequent scan checks.

This patch also renames the function to something more fitting of what it's
trying to do.

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

2 years ago[clangd] Handle '--' in QueryDriverDatabase
Nathan Ridge [Tue, 24 May 2022 06:12:53 +0000 (02:12 -0400)]
[clangd] Handle '--' in QueryDriverDatabase

Fixes https://github.com/clangd/clangd/issues/1100,
a regression from D116721.

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

2 years agoReland "[PS5] Verify defaults to -fno-stack-size-section"
Paul Robinson [Tue, 24 May 2022 17:03:20 +0000 (10:03 -0700)]
Reland "[PS5] Verify defaults to -fno-stack-size-section"

This reverts commit efebb27b745a0d677ad2ea9aefff242c12aef29c.
Fixes typos (accidentally omitted %s from some RUN lines).

2 years ago[AMDGPU] Enforce alignment of image vaddr on gfx90a
Stanislav Mekhanoshin [Wed, 18 May 2022 19:22:38 +0000 (12:22 -0700)]
[AMDGPU] Enforce alignment of image vaddr on gfx90a

Even though single address image instructions only use a single VGPR
HW accesses 4 or 5 which creates alignment requirement.

Fixes: SWDEV-316648

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

2 years ago[libclang] add supporting for indexing/visiting C++ concepts
Alex Lorenz [Thu, 19 May 2022 23:09:36 +0000 (16:09 -0700)]
[libclang] add supporting for indexing/visiting C++ concepts

This commit builds upon recently added indexing support for C++ concepts
from https://reviews.llvm.org/D124441 by extending libclang to
support indexing and visiting concepts, constraints and requires
expressions as well.

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

2 years agoRevert "[PS5] Verify defaults to -fno-stack-size-section"
Paul Robinson [Tue, 24 May 2022 16:59:57 +0000 (09:59 -0700)]
Revert "[PS5] Verify defaults to -fno-stack-size-section"

This reverts commit 28432b0f655641df7f9d079cf69ba235038d6340.

Caused some unexpected buildbot failures.

2 years agoNFC. Clang-formatting.
Chris Bieneman [Tue, 24 May 2022 16:51:00 +0000 (11:51 -0500)]
NFC. Clang-formatting.

Since the rest of the DirectX backend is pretty well clang-format
clean, this file should be too.

2 years ago[flang][runtime] INQUIRE(UNIT=666,NUMBER=n) must set n=666
Peter Klausler [Wed, 18 May 2022 20:23:39 +0000 (13:23 -0700)]
[flang][runtime] INQUIRE(UNIT=666,NUMBER=n) must set n=666

Whether a unit number in an inquire-by-unit statement is valid or not,
it should be the value to which the NUMBER= variable is set, not -1.
-1 should be returned to NUMBER= only for an inquire-by-file statement
when the FILE= is not connected to any unit.

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

2 years ago[PS5] Verify defaults to -fno-stack-size-section
Paul Robinson [Tue, 24 May 2022 16:47:22 +0000 (09:47 -0700)]
[PS5] Verify defaults to -fno-stack-size-section

2 years agoRecommit "[RISCV] Use selectShiftMaskXLen ComplexPattern for isel of rotates."
Craig Topper [Tue, 24 May 2022 16:41:04 +0000 (09:41 -0700)]
Recommit "[RISCV] Use selectShiftMaskXLen ComplexPattern for isel of rotates."

This reverts commit dfe513ae1bb6e788ead93b850d80d77d54cf29d3.

Tests have been changed to avoid the type legalization bug being
fixed in D126036.

Original commit message:
This will remove masks on the shift amount. We usually get this with
SimplifyDemandedBits in DAGCombine, but that's restricted to cases
where the AND has a single use. selectShiftMaskXLen does not have
that restriction.

2 years ago[RISCV] Add test cases showing failure to remove mask on rotate amounts.
Craig Topper [Tue, 24 May 2022 16:41:00 +0000 (09:41 -0700)]
[RISCV] Add test cases showing failure to remove mask on rotate amounts.

This is similar to tests I added in
e2f410feeab27a8bb2c015fc02bb8527702e401f that had to be reverted.

I've modified them to avoid the bug that is being fixed by D126036.

2 years ago[gn build] Reformat all build files
Nico Weber [Tue, 24 May 2022 15:42:34 +0000 (11:42 -0400)]
[gn build] Reformat all build files

Ran:

    git ls-files '*.gn' '*.gni' | xargs llvm/utils/gn/gn.py format

2 years ago[flang] Extension: Accept Hollerith actual arguments as if they were BOZ
Peter Klausler [Thu, 19 May 2022 16:55:29 +0000 (09:55 -0700)]
[flang] Extension: Accept Hollerith actual arguments as if they were BOZ

When a Hollerith (or short character) literal is presented as an actual
argument that corresponds to a dummy argument for which a BOZ literal
would be acceptable, treat the Hollerith as if it had been a BOZ
literal in the same way -- and with the same code -- as f18 already
does for the similar extension in DATA statements.

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

2 years ago[Clang] Avoid misleading 'conflicting types' diagnostic with no-prototype decls.
Cyndy Ishida [Tue, 24 May 2022 13:24:02 +0000 (06:24 -0700)]
[Clang] Avoid misleading 'conflicting types' diagnostic with no-prototype decls.

Clang has recently started diagnosing prototype redeclaration errors like [rG385e7df33046](https://reviews.llvm.org/rG385e7df33046d7292612ee1e3ac00a59d8bc0441)

This flagged legitimate issues in a codebase but was confusing to resolve because it actually conflicted with a function declaration from a system header and not from the one emitted with "note: ".

This patch updates the error handling to use the canonical declaration's source location instead to avoid misleading errors like the one described.

Reviewed By: aaron.ballman

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

2 years ago[gn build] (semi-automatically) port 0360b9f1599b
Nico Weber [Tue, 24 May 2022 15:40:40 +0000 (11:40 -0400)]
[gn build] (semi-automatically) port 0360b9f1599b

2 years ago[libc++][NFC] Whitespace refactoring of string.cpp for consistency and legibility
Louis Dionne [Tue, 24 May 2022 15:31:31 +0000 (11:31 -0400)]
[libc++][NFC] Whitespace refactoring of string.cpp for consistency and legibility

2 years ago[libc++][NFC] Move definitions around in string.cpp to reduce _LIBCPP_HAS_NO_WIDE_CHA...
Louis Dionne [Tue, 24 May 2022 15:22:43 +0000 (11:22 -0400)]
[libc++][NFC] Move definitions around in string.cpp to reduce _LIBCPP_HAS_NO_WIDE_CHARACTERS blocks

2 years ago[mlir] Rename mlir::SmallVector -> llvm::SmallVector
Mogball [Tue, 24 May 2022 15:03:12 +0000 (15:03 +0000)]
[mlir] Rename mlir::SmallVector -> llvm::SmallVector

2 years ago[mlir] Breakdown diagnostic string literals
Logan Chien [Wed, 18 May 2022 20:59:08 +0000 (13:59 -0700)]
[mlir] Breakdown diagnostic string literals

This commit breaks down diagnostic string literals so that the attribute
name and enumurator names can be shared with the stringify utility
function and the "expected ", " to be one of ", and ", " can be shared
between different enum-related diagnostic.

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

2 years ago[flang][runtime] Clean up asynchronous I/O APIs
Peter Klausler [Thu, 12 May 2022 00:08:21 +0000 (17:08 -0700)]
[flang][runtime] Clean up asynchronous I/O APIs

Now that the requirements and implementation of asynchronous I/O are
better understood, adjust their I/O runtime APIs.  In particular:
1) Remove the BeginAsynchronousOutput/Input APIs; they're not needed,
   since any data transfer statement might have ASYNCHRONOUS= and
   (if ASYNCHRONOUS='YES') ID= control list specifiers that need to
   at least be checked.
2) Add implementations for BeginWait(All) to check for the error
   case of a bad unit number and nonzero ID=.
3) Rearrange and comment SetAsynchronous so that it's clear that
   it can be called for READ/WRITE as well as for OPEN.

The implementation remains completely synchronous, but should be conforming.
Where opportunities make sense for true asynchronous implementations of
some big block transfers without SIZE= in the future, we'll need to add
a GetAsynchronousId API to capture ID= on a READ or WRITE; add sourceFile
and sourceLine arguments to BeginWait(All) for good error reporting;
track pending operations in unit.h; and add code to force synchronization
to non-asynchronous I/O operations.

Lowering should call SetAsynchronous when ASYNCHRONOUS= appears as
a control list specifier.  It should also set ID=x variables to 0
until such time as we support asynchronous operations, if ever.
This patch only removes the removed APIs from lowering.

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

2 years agoFix behavior of is_fp_class on empty class set
Serge Pavlov [Tue, 24 May 2022 11:30:13 +0000 (18:30 +0700)]
Fix behavior of is_fp_class on empty class set

The second argument to is_fp_class specifies the set of floating-point
class to test against. It can be zero, in this case the intrinsic is
expected to return zero value.

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

2 years ago[DAG] Unroll vectorized FPOW instructions before widening that will scalarize to...
Simon Pilgrim [Tue, 24 May 2022 14:44:44 +0000 (15:44 +0100)]
[DAG] Unroll vectorized FPOW instructions before widening that will scalarize to libcalls anyway

Followup to D125988 - FPOW is similar to FREM and will most likely scalarize to libcalls, so unroll before widening to prevent use making additional libcalls with UNDEF args.

2 years ago[libcxx] Add sort.bench.cpp to libcxx/benchmarks/CMakeLists.txt
Hans Wennborg [Tue, 24 May 2022 13:47:41 +0000 (15:47 +0200)]
[libcxx] Add sort.bench.cpp to libcxx/benchmarks/CMakeLists.txt

It was forgotten in D124740.

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

2 years ago[TypePromotion] Avoid unnecessary trunc zext pairs
Sam Parker [Tue, 24 May 2022 14:33:21 +0000 (15:33 +0100)]
[TypePromotion] Avoid unnecessary trunc zext pairs

Any zext 'sink' should already have an operand that is in the legal
value, so avoid using a trunc and just use the trunc operand instead.

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

2 years ago[mlir][vector] Add new lowering mode to vector.contractionOp
Thomas Raoux [Tue, 24 May 2022 14:16:00 +0000 (14:16 +0000)]
[mlir][vector] Add new lowering mode to vector.contractionOp

Add lowering for cases where the reduction dimension is fully unrolled.
It is common to unroll the reduction dimension, therefore we would want
to lower the contractions to an elementwise vector op in this case.

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

2 years ago[CostModel][X86] getScalarizationOverhead - improve extraction costs for > 128-bit...
Simon Pilgrim [Tue, 24 May 2022 14:17:59 +0000 (15:17 +0100)]
[CostModel][X86] getScalarizationOverhead - improve extraction costs for > 128-bit vectors

We were using the default getScalarizationOverhead expansion for extraction costs, which adds up all the individual element extraction costs.

This is fine for 128-bit vectors, but for 256/512-bit vectors each element extraction also has to account for extracting the upper 128-bit subvector extraction before it can handle the element. For scalarization costs we only need to extract each demanded subvector once.

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

2 years ago[AMDGPU][MC][GFX11] Support base+soffset+offset SMEM loads.
Ivan Kosarev [Tue, 24 May 2022 14:12:45 +0000 (15:12 +0100)]
[AMDGPU][MC][GFX11] Support base+soffset+offset SMEM loads.

Reviewed By: dp

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

2 years ago[InstCombine] Strip bitcasts in GEP diff fold
Nikita Popov [Tue, 24 May 2022 14:08:21 +0000 (16:08 +0200)]
[InstCombine] Strip bitcasts in GEP diff fold

Bitcasts were stripped in one case, but not the other. Of course,
this no longer really matters with opaque pointers, but as I went
through the trouble of tracking this down, we may as well remove
one typed vs opaque pointer optimization discrepancy.

2 years ago[InstCombine] Add test for GEP difference with bitcasts (NFC)
Nikita Popov [Tue, 24 May 2022 14:09:26 +0000 (16:09 +0200)]
[InstCombine] Add test for GEP difference with bitcasts (NFC)

2 years ago[libc++] Rename the generic-singlethreaded CI job to generic-no-threads for consistency
Louis Dionne [Tue, 24 May 2022 13:58:04 +0000 (09:58 -0400)]
[libc++] Rename the generic-singlethreaded CI job to generic-no-threads for consistency

2 years ago[InstCombine] Use IRBuilder in freeze pushing transform (PR55619)
Nikita Popov [Tue, 24 May 2022 13:48:28 +0000 (15:48 +0200)]
[InstCombine] Use IRBuilder in freeze pushing transform (PR55619)

Use IRBuilder so that the newly created freeze instructions
automatically gets inserted back into the IC worklist.

The changed worklist processing order leads to some cosmetic
differences in tests.

Fixes https://github.com/llvm/llvm-project/issues/55619.

2 years ago[InstCombine] Add tests for freeze of load with metadata (NFC)
Nikita Popov [Tue, 24 May 2022 13:17:19 +0000 (15:17 +0200)]
[InstCombine] Add tests for freeze of load with metadata (NFC)

2 years ago[pseudo] (trivial) bracket-matching
Sam McCall [Wed, 18 May 2022 17:24:07 +0000 (19:24 +0200)]
[pseudo] (trivial) bracket-matching

Error-tolerant bracket matching enables our error-tolerant parsing strategies.
The implementation here is *not* yet error tolerant: this patch sets up the APIs
and plumbing, and describes the planned approach.

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

2 years ago[OpenMP] Add `-Xoffload-linker` to forward input to the device linker
Joseph Huber [Mon, 23 May 2022 21:51:30 +0000 (17:51 -0400)]
[OpenMP] Add `-Xoffload-linker` to forward input to the device linker

We use the clang-linker-wrapper to perform device linking of embedded
offloading object files. This is done by generating those jobs inside of
the linker-wrapper itself. This patch adds an argument in Clang and the
linker-wrapper that allows users to forward input to the device linking
phase. This can either be done for every device linker, or for a
specific target triple. We use the `-Xoffload-linker <arg>` and the
`-Xoffload-linker-<triple> <arg>` syntax to accomplish this.

Reviewed By: markdewing, tra

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

2 years ago[SLP][NFC]Make isFirstInsertElement a weak strict ordering comparator.
Alexey Bataev [Tue, 24 May 2022 13:01:17 +0000 (06:01 -0700)]
[SLP][NFC]Make isFirstInsertElement a weak strict ordering comparator.

To be used correctly in a sort-like function, isFirstInsertElement
function must follow weak strict ordering rule, i.e.
isFirstInsertElement(IE1, IE1) should return false.

2 years ago[x86][DAG] Unroll vectorized FREMs that will become libcalls
Nabeel Omer [Tue, 24 May 2022 12:30:47 +0000 (13:30 +0100)]
[x86][DAG] Unroll vectorized FREMs that will become libcalls

Currently, two element vectors produced as the result of a binary op are
widened to four element vectors on x86 by
DAGTypeLegalizer::WidenVecRes_BinaryCanTrap. If the op still isn't legal
after widening it is unrolled into 4 scalar ops in SelectionDAG before
being converted into a libcall. This way we end up with 4 libcalls (two of
them on known undef elements) instead of the original two libcalls.

This patch modifies DAGTypeLegalizer::WidenVectorResult to ensure that if
it is known that a binary op will be tunred into a libcall, it is unrolled
instead of being widened. This prevents the creation of the extra scalar
instructions on known undef elements and (eventually) libacalls with known
undef parameters which would otherwise be created when the op gets expanded
post widening.

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

2 years agoRevert "[TableGen] Remove code beads"
Sylvestre Ledru [Tue, 24 May 2022 12:17:49 +0000 (14:17 +0200)]
Revert "[TableGen] Remove code beads"

It is breaking the build with:

/build/llvm-toolchain-snapshot-15~++20220524114008+96323c9f4c10/llvm/lib/Target/M68k/MCTargetDesc/M68kMCCodeEmitter.cpp:478:10: fatal error: 'M68kGenMCCodeBeads.inc' file not found
         ^~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Remove the #include causes:
error: undefined reference to 'llvm::M68k::getMCInstrBeads(unsigned int)'

This reverts commit f50be3d21808ae113c40a68a9ac6581f203d92d2.

2 years ago[Clang][CodeGen] Fix the cmse-clear-return.c test.
Ivan Kosarev [Tue, 24 May 2022 11:32:48 +0000 (12:32 +0100)]
[Clang][CodeGen] Fix the cmse-clear-return.c test.

Caught with D125604.

Reviewed By: nikic

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

2 years agoMinutes for security group sync-ups have moved to Discourse.
Kristof Beyls [Tue, 24 May 2022 11:46:08 +0000 (13:46 +0200)]
Minutes for security group sync-ups have moved to Discourse.

2 years ago[X86] scalar_widen_div.ll - remove non-generated CHECKs
Simon Pilgrim [Tue, 24 May 2022 10:55:36 +0000 (11:55 +0100)]
[X86] scalar_widen_div.ll - remove non-generated CHECKs

These were left over from when we converted to the update_llc_test_checks script and were just matching some asm/cfi directives - we have CHECK-LABEL to do this properly now.

2 years ago[OpenCL] Make -cl-ext a driver option.
Anastasia Stulova [Tue, 24 May 2022 10:26:43 +0000 (11:26 +0100)]
[OpenCL] Make -cl-ext a driver option.

For generic targets such as SPIR-V clang sets all OpenCL
extensions/features as supported by default. However
concrete targets are unlikely to support all extensions
features, which creates a problem when such generic SPIR-V
binary is compiled for a specific target later on.

To allow compile time diagnostics for unsupported features
this flag is now being exposed in the clang driver.

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

2 years agoFix comment in test. NFC
Max Kazantsev [Tue, 24 May 2022 10:22:16 +0000 (17:22 +0700)]
Fix comment in test. NFC

2 years ago[Test] Add LICM test for PR55672 showing problem with freeze instruction
Max Kazantsev [Tue, 24 May 2022 10:17:05 +0000 (17:17 +0700)]
[Test] Add LICM test for PR55672 showing problem with freeze instruction

2 years ago[X86][AMX] Reduce the compiling time for non-amx code.
Luo, Yuanke [Tue, 24 May 2022 08:46:27 +0000 (16:46 +0800)]
[X86][AMX] Reduce the compiling time for non-amx code.

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

2 years ago[X86] Add test showing failure to expand <2 x float> fpow without widening to <4...
Simon Pilgrim [Tue, 24 May 2022 09:45:12 +0000 (10:45 +0100)]
[X86] Add test showing failure to expand <2 x float> fpow without widening to <4 x float>

Similar to D125988 (and I have a pending follow up patch to handle fpow).

2 years ago[TableGen] Remove code beads
Sheng [Tue, 24 May 2022 02:53:48 +0000 (10:53 +0800)]
[TableGen] Remove code beads

Code beads is useless since the only user, M68k, has moved on to
a new encoding/decoding infrastructure.

2 years ago[RISCV][NFC] Change interface of RVVIntrinsic::getSuffixStr
Kito Cheng [Fri, 20 May 2022 08:24:37 +0000 (16:24 +0800)]
[RISCV][NFC] Change interface of RVVIntrinsic::getSuffixStr

This NFC patch is splited from D111617.

Using llvm::ArrayRef rather than llvm::SmallVector, ArrayRef is more generic
interface that could accept both llvm::ArrayRef and llvm::SmallVector.

Reviewed By: reames

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

2 years ago[InstCombine] Support logical and in masked icmp fold
Nikita Popov [Tue, 24 May 2022 08:45:29 +0000 (10:45 +0200)]
[InstCombine] Support logical and in masked icmp fold

Most of the folds implemented in this function work fine with
logical operations. We only need to be careful for the cases that
work on non-constant masks, where the RHS operand shouldn't be
poison.

This is a conservative implementation that bails out of illegal
transforms, but we could also change these to insert freeze instead.

2 years ago[InstCombine] Add tests for masked icmps with bitwise+logical and (NFC)
Nikita Popov [Tue, 24 May 2022 09:10:36 +0000 (11:10 +0200)]
[InstCombine] Add tests for masked icmps with bitwise+logical and (NFC)

2 years ago[InstCombine] Use m_APInt() in asymmetric masked icmp fold
Nikita Popov [Tue, 24 May 2022 08:56:16 +0000 (10:56 +0200)]
[InstCombine] Use m_APInt() in asymmetric masked icmp fold

This is mostly intended as code cleanup, but it does also add
support for splat vectors to this fold.

2 years ago[InstCombine] Add splat vector test for asymmetric masked icmp fold
Nikita Popov [Tue, 24 May 2022 08:49:08 +0000 (10:49 +0200)]
[InstCombine] Add splat vector test for asymmetric masked icmp fold
(NFC)

2 years ago[gn build] Port 1d1a191edcfa
LLVM GN Syncbot [Tue, 24 May 2022 08:37:12 +0000 (08:37 +0000)]
[gn build] Port 1d1a191edcfa

2 years ago[libc++] Implement ranges::reverse
Nikolas Klauser [Tue, 24 May 2022 08:32:50 +0000 (10:32 +0200)]
[libc++] Implement ranges::reverse

Reviewed By: var-const, #libc

Spies: libcxx-commits, mgorny

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

2 years ago[libc++] Replace modulus operations in std::seed_seq::generate with conditional checks.
Laramie Leavitt [Tue, 24 May 2022 08:27:37 +0000 (10:27 +0200)]
[libc++] Replace modulus operations in std::seed_seq::generate with conditional checks.

Abseil benchmarks suggest that the conditional checks result in faster code (4-5x)
as they are compiled into conditional move instructions (cmov on x86).

Reviewed By: #libc, philnik, Mordante

Spies: pengfei, Mordante, philnik, libcxx-commits

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

2 years ago[LegalizeTypes][NFC] Fix node name in assertion message
Fraser Cormack [Tue, 24 May 2022 08:16:18 +0000 (09:16 +0100)]
[LegalizeTypes][NFC] Fix node name in assertion message

This was probably copy/pasted from the MSCATTER widening.

2 years ago[libc++] type_traits: use __is_core_convertible in __invokable_r.
Aaron Jacobs [Tue, 24 May 2022 08:21:05 +0000 (10:21 +0200)]
[libc++] type_traits: use __is_core_convertible in __invokable_r.

This fixes incorrect handling of non-moveable types, adding tests for this case.
See [issue 55346](https://github.com/llvm/llvm-project/issues/55346).

The current implementation is based on is_convertible, which is
[defined](https://timsong-cpp.github.io/cppwp/n4659/meta.rel#5) in terms of
validity of the following function:

```
To test() {
  return declval<From>();
}
```

But this doesn't work if To and From are both some non-moveable type, which the
[definition](https://timsong-cpp.github.io/cppwp/n4659/conv#3) of implicit
conversions says should work due to guaranteed copy elision:

```
To to = E;  // E has type From
```

It is this latter definition that is used in the
[definition](https://timsong-cpp.github.io/cppwp/n4659/function.objects#func.require-2)
of INVOKE<R>. Make __invokable_r use __is_core_convertible, which
captures the ability to use guaranteed copy elision, making the
definition correct for non-moveable types.

Fixes llvm/llvm-project#55346.

Reviewed By: #libc, philnik, EricWF

Spies: EricWF, jloser, ldionne, philnik, libcxx-commits

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

2 years ago[InstCombine] Handle logical and/or in recursive and/or of icmps fold
Nikita Popov [Tue, 24 May 2022 08:07:00 +0000 (10:07 +0200)]
[InstCombine] Handle logical and/or in recursive and/or of icmps fold

The and/or of icmps fold is also applied in reassociated form.
However, this currently only happens for bitwise and of bitwise
and, but not for bitwise and of logical and (or other combinations,
but this is the one being addressed here).

We can do this for bitwise+logical combinations as well, but need
to be a bit careful about which of the resulting ands are logical:
https://alive2.llvm.org/ce/z/WYSjGh
https://alive2.llvm.org/ce/z/guxYnz
https://alive2.llvm.org/ce/z/S5SYxY
https://alive2.llvm.org/ce/z/2rAWeW

2 years ago[InstCombine] Use different icmp pattern in test (NFC)
Nikita Popov [Tue, 24 May 2022 08:04:24 +0000 (10:04 +0200)]
[InstCombine] Use different icmp pattern in test (NFC)

Use an and/or of icmp pattern that produces different code
depending on whether it is part of a logical or bitwise and/or.

2 years agollvm-reduce: improve basic-blocks removal pass
Markus Lavin [Tue, 24 May 2022 07:42:07 +0000 (09:42 +0200)]
llvm-reduce: improve basic-blocks removal pass

When the single branch target of a block has been removed try updating
it to target a  block that is kept (by scanning forward in the sequence)
instead of replacing the branch with a return instruction. Doing so
reduces the risk of breaking loop structures meaning that when the loop
is 'interesting' these reductions should have more blocks eliminated.

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

2 years ago[LoopUnroll] Freeze tripcount rather than condition
Nikita Popov [Wed, 18 May 2022 15:09:36 +0000 (17:09 +0200)]
[LoopUnroll] Freeze tripcount rather than condition

This is a followup to D125754. We introduce two branches, one
before the unrolled loop and one before the epilogue (and similar
for the prologue case). The previous patch only froze the
condition on the first branch.

Rather than independently freezing the second condition, this patch
instead freezes TripCount and bases BECount on it. These are the
two quantities involved in the conditions, and this ensures that
both work on a consistent, non-poisonous trip count.

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

2 years ago[LegalizeTypes][VP] Fix OpNo in WidenVecOp_VP_SCATTER
Lian Wang [Tue, 24 May 2022 07:12:31 +0000 (07:12 +0000)]
[LegalizeTypes][VP] Fix OpNo in WidenVecOp_VP_SCATTER

Reviewed By: craig.topper

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

2 years ago[RISCV] Ensure the entire stack is aligned to the RVV stack alignment
Fraser Cormack [Thu, 19 May 2022 13:47:40 +0000 (14:47 +0100)]
[RISCV] Ensure the entire stack is aligned to the RVV stack alignment

This patch fixes another bug in the RVV frame lowering. While some frame
objects with non-default stack IDs (such scalable-vector alloca
instructions) are considered in the target-independent max alignment
calculations, others (for example, during calling-convention lowering)
are not. This means we'd occasionally align the base of the stack to
only 16 bytes, with no way to ensure that the RVV section contained
within that is aligned to anything higher.

Reviewed By: StephenFan

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

2 years ago[RISCV] Fix RVV stack frame alignment bugs
Fraser Cormack [Mon, 16 May 2022 09:57:32 +0000 (10:57 +0100)]
[RISCV] Fix RVV stack frame alignment bugs

This patch addresses several alignment issues in the stack frame when
RVV objects are taken into account.

One bug is that the RVV stack was never guaranteed to keep the alignment
of the stack *as a whole*. We must maintain a 16-byte aligned stack at
all times, especially when calling other functions. With the standard V
extension, this is conveniently happening since VLEN is at least 128 and
always 16-byte aligned. However, we support Zvl64b which does not
guarantee this. To fix this, the RVV stack size is rounded up to be
aligned to 16 bytes. This in practice generally makes us allocate a
stack sized at least 2*VLEN in size, and a multiple of 2.

    |------------------------------| -- <-- FP
    | 8-byte callee-save           | |      |
    |------------------------------| |      |
    | one VLENB-sized RVV object   | |      |
    |------------------------------| |      |
    | 8-byte local variable        | |      |
    |------------------------------| -- <-- SP (must be aligned to 16)

In the example above, with Zvl64b we are decrementing SP by 12 bytes
which does not leave SP correctly aligned. We therefore introduce an
extra VLENB-sized amount used for alignment. This would therefore ensure
the total stack size was 16 bytes (48 for Zvl128b, 80 for Zvl256b, etc):

    |------------------------------| -- <-- FP
    | 8-byte callee-save           | |      |
    |------------------------------| |      |
    | one VLENB-sized padding obj  | |      |
    | one VLENB-sized RVV object   | |      |
    |------------------------------| |      |
    | 8-byte local variable        | |      |
    |------------------------------| -- <-- SP

A new RVV invariant has been introduced in this patch, which is that the
base of the RVV stack itself is now always aligned to 16 bytes, not 8 as
before. This keeps us more in line with the scalar stack and should be
easier to reason about. The calculation of the RVV padding has thus
changed to be the amount required to align the scalar local variable
section to the RVV section's alignment. This amount is further rounded
up when setting up the initial stack to keep everything aligned:

    |------------------------------| -- <-- FP
    | 8-byte callee-save           |
    |------------------------------|
    |                              |
    | RVV objects                  |
    | (aligned to at least 16)     |
    |                              |
    |------------------------------|
    | RVV padding of 8 bytes       |
    |------------------------------|
    | 8-byte local variable        |
    |------------------------------| -- <-- SP

In the example above, it's clear that we need 8 bytes of padding to keep
the RVV section aligned to 16 when using SP. But to keep SP *itself*
aligned to 16 we can't decrement the initial stack pointer by 24 - we
have to round up to 32.

With the RVV section correctly aligned, the second bug fixed by
this patch is that RVV objects themselves are now correctly aligned. We
were previously only guaranteeing an alignment of 8 bytes, even if they
required a higher alignment. This is relatively simple and in practice
we see more rounding up of VLEN amounts to account for alignment in
between objects:

    |------------------------------|
    | RVV object (aligned to 16)   |
    |------------------------------|
    | no padding necessary         |
    |------------------------------|
    | 2*VLENB RVV object (align 16)|
    |------------------------------|
    | VLENB alignment padding      |
    |------------------------------|
    | RVV object (align 32)        |
    |------------------------------|
    | 3*VLENB alignment padding    |
    |------------------------------|
    | VLENB RVV object (align 32)  |
    |------------------------------| -- <-- base of RVV section

Note that a lot of the regressions in codegen owing to the new alignment
rules are correct but actually only strictly necessary for Zvl64b (and
Zvl32b but that's not really supported). I plan a follow-up patch to
take the known VLEN into account when padding for alignment.

Reviewed By: StephenFan

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

2 years ago[gn build] Port 496156ac57da
LLVM GN Syncbot [Tue, 24 May 2022 05:44:48 +0000 (05:44 +0000)]
[gn build] Port 496156ac57da

2 years ago[X86][AMX] Multiple configure for AMX register.
Luo, Yuanke [Tue, 3 May 2022 10:57:25 +0000 (18:57 +0800)]
[X86][AMX] Multiple configure for AMX register.

The previous solution depends on variable name to record the shape
information. However it is not reliable, because in release build
compiler would not set the variable name. It can be accomplished with an
additional option `fno-discard-value-names`, but it is not acceptable
for users.
This patch is to preconfigure the tile register with machine
instruction. It follow the same way what sigle configure does. In the
future we can fall back to multiple configure when single configure
fails due to the shape dependency issue.
The algorithm to configure the tile register is simple in the patch. We
may improve it in the future. It configure tile register based on basic
block. Compiler would spill the tile register if it live out the basic
block. After the configure there should be no spill across tile
confgiure in the register alloction. Just like fast register allocation
the algorithm walk the instruction in reverse order. When the shape
dependency doesn't meet, it insert ldtilecfg after the last instruction
that define the shape.
In post configuration compiler also walk the basic block to collect the
physical tile register number and generate instruction to fill the stack
slot for the correponding shape information.
TODO: There is some following work in D125602. The risk is modifying the
fast RA may cause regression as fast RA is usded for different targets.
We may create an independent RA for tile register.

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

2 years ago[MachineSink] replace MachineLoop with MachineCycle
Chen Zheng [Tue, 19 Apr 2022 07:40:17 +0000 (03:40 -0400)]
[MachineSink] replace MachineLoop with MachineCycle

MachineCycle can handle irreducible loop. Natural loop
analysis (MachineLoop) can not return correct loop depth if
the loop is irreducible loop. And MachineSink is sensitive
to the loop depth, see MachineSinking::isProfitableToSinkTo().

This patch tries to use MachineCycle so that we can handle
irreducible loop better.

Reviewed By: sameerds, MatzeB

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

2 years ago[OpenMP][IRBuilder] `omp task` support
Shraiysh Vaishay [Tue, 24 May 2022 04:23:33 +0000 (09:53 +0530)]
[OpenMP][IRBuilder] `omp task` support

This patch adds basic support for `omp task` to the OpenMPIRBuilder.

The outlined function after code extraction is called from a wrapper function with appropriate arguments. This wrapper function is passed to the runtime calls for task allocation.

This approach is different from the Clang approach - clang directly emits the runtime call to the outlined function. The outlining utility (OutlineInfo) simply outlines the code and generates a function call to the outlined function. After the function has been generated by the outlining utility, there is no easy way to alter the function arguments without meddling with the outlining itself. Hence the wrapper function approach is taken.

Reviewed By: Meinersbur

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

2 years ago[flang] Allow more forward references to ENTRY names
Peter Klausler [Tue, 17 May 2022 01:10:27 +0000 (18:10 -0700)]
[flang] Allow more forward references to ENTRY names

Forward references to ENTRY names to pass them as actual procedure arguments
don't work in all cases, exposing some basic ordering problems in
name resolution for these symbols.  Refactor; create all the
necessary procedure symbols, and either function result or host association
symbols (for subroutines), at the time that the subprogrma scope is
created, so that the names exist in the scope as text "before"
the ENTRY is processed in name resolution.  Some processing
remains in PostEntryStmt() so that we can check that an ENTRY with
an explicit distinct RESULT doesn't also have declarations for the
ENTRY name.

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