platform/upstream/llvm.git
2 years ago[clang] number labels in asm goto strings after tied inputs
Nick Desaulniers [Tue, 11 Jan 2022 19:51:22 +0000 (11:51 -0800)]
[clang] number labels in asm goto strings after tied inputs

I noticed that the following case would compile in Clang but not GCC:
    void *x(void) {
      void *p = &&foo;
      asm goto ("# %0\n\t# %l1":"+r"(p):::foo);
      foo:;
      return p;
    }

Changing the output template above from %l2 would compile in GCC but not
Clang.

This demonstrates that when using tied outputs (say via the "+r" output
constraint), the hidden inputs occur or are numbered BEFORE the labels,
at least with GCC.

In fact, GCC does denote this in its documentation:
https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Extended-Asm.html#Goto-Labels

> Output operand with constraint modifier ‘+’ is counted as two operands
> because it is considered as one output and one input operand.

For the sake of compatibility, I think it's worthwhile to just make this
change.

It's better to use symbolic names for compatibility (especially now
between released version of Clang that support asm goto with outputs).
ie. %l1 from the above would be %l[foo]. The GCC docs also make this
recommendation.

Also, I cleaned up some cruft in GCCAsmStmt::getNamedOperand. AFAICT,
NumPlusOperands was no longer used, though I couldn't find which commit
didn't clean that up correctly.

Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98096
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103640
Link: https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Extended-Asm.html#Goto-Labels
Reviewed By: void

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

2 years agoAccept string literal decay in conditional operator
Elvis Stansvik [Tue, 11 Jan 2022 20:04:27 +0000 (15:04 -0500)]
Accept string literal decay in conditional operator

The cppcoreguidelines-pro-bounds-array-to-pointer-decay check currently
accepts:

const char *b = i ? "foo" : "foobar";

but not

const char *a = i ? "foo" : "bar";

This is because the AST is slightly different in the latter case (see
https://godbolt.org/z/MkHVvs).

This eliminates the inconsistency by making it accept the latter form
as well.

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

2 years ago[DSE] Generalize store null to calloc allocated memory [NFC-ish]
Philip Reames [Tue, 11 Jan 2022 20:00:42 +0000 (12:00 -0800)]
[DSE] Generalize store null to calloc allocated memory [NFC-ish]

This change removes a direct check for calloc-like allocation functions, and instead handles the generic case where we're storing a constant to constant initialized memory.  This is mostly to remove the call to isCallocLike, but if someone downstream happens to have an initialized alloc which initializes to e.g. -1, this will also kick in for them.  (I don't know of such an example ftr.)

2 years ago[MLIR][LLVM] Add MemRead/MemWrite behavior to llvm store/load/addressof ops
William S. Moses [Tue, 11 Jan 2022 18:33:43 +0000 (13:33 -0500)]
[MLIR][LLVM] Add MemRead/MemWrite behavior to llvm store/load/addressof ops

This patch adds corresponding memory effects to mlir llvm-dialect load/store/addressof ops, which thus enables canonicalizations of those ops (like dead code elimination) that rely on the effect interface

Reviewed By: mehdi_amini

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

2 years ago[HIP] Fix device malloc/free
Yaxun (Sam) Liu [Mon, 10 Jan 2022 17:57:41 +0000 (12:57 -0500)]
[HIP] Fix device malloc/free

ROCm 4.5 device library introduced __ockl_dm_alloc and __ockl_dm_dealloc
for supporting device side malloc/free.

This patch redefines device malloc/free to use these functions.

It also fixes a bug in the wrapper header which incorrectly defines free
with return type void* instead of void.

Reviewed by: Artem Belevich

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

2 years ago[gn build] (manually) port f77d115cc136 more
Nico Weber [Tue, 11 Jan 2022 19:49:08 +0000 (14:49 -0500)]
[gn build] (manually) port f77d115cc136 more

2 years ago[clang][CGStmt] emit i constraint rather than X for asm goto indirect dests
Nick Desaulniers [Tue, 11 Jan 2022 19:32:35 +0000 (11:32 -0800)]
[clang][CGStmt] emit i constraint rather than X for asm goto indirect dests

As suggested in:
https://reviews.llvm.org/D114895#3177794
X will be converted to i by SelectionDAGISEL anyways.

Reviewed By: void, jyknight

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

2 years ago[NFC][SimplifyCFG] Add some more tests for sinking into 'unreachable' block
Roman Lebedev [Tue, 11 Jan 2022 19:18:28 +0000 (22:18 +0300)]
[NFC][SimplifyCFG] Add some more tests for sinking into 'unreachable' block

2 years agoFix bazel build after f77d115cc136585f39d30a78c741eb296f9e804d.
James Y Knight [Tue, 11 Jan 2022 17:55:35 +0000 (17:55 +0000)]
Fix bazel build after f77d115cc136585f39d30a78c741eb296f9e804d.

2 years ago[llvm][test] rewrite callbr to use i rather than X constraint NFC
Nick Desaulniers [Tue, 11 Jan 2022 19:08:48 +0000 (11:08 -0800)]
[llvm][test] rewrite callbr to use i rather than X constraint NFC

In D115311, we're looking to modify clang to emit i constraints rather
than X constraints for callbr's indirect destinations. Prior to doing
so, update all of the existing tests in llvm/ to match.

Reviewed By: void, jyknight

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

2 years ago[CodeGen] Treat ObjC `__unsafe_unretained` and class types as trivial
Akira Hatanaka [Sat, 8 Jan 2022 21:27:28 +0000 (13:27 -0800)]
[CodeGen] Treat ObjC `__unsafe_unretained` and class types as trivial
when generating copy/dispose helper functions

Analyze the block captures just once before generating copy/dispose
block helper functions and honor the inert `__unsafe_unretained`
qualifier. This refactor fixes a bug where captures of ObjC
`__unsafe_unretained` and class types were needlessly retained/released
by the copy/dispose helper functions.

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

2 years agoApply clang-tidy fixes for readability-redundant-control-flow in OpenMPDialect.cpp...
Mehdi Amini [Tue, 11 Jan 2022 00:31:22 +0000 (00:31 +0000)]
Apply clang-tidy fixes for readability-redundant-control-flow in OpenMPDialect.cpp (NFC)

2 years agoFix clang-tidy bugprone-argument-comment that was mixed up
Shafik Yaghmour [Tue, 11 Jan 2022 18:30:32 +0000 (10:30 -0800)]
Fix clang-tidy bugprone-argument-comment that was mixed up

Several of the comments were annotating the wrong argument.

I caught this while reviewing this clean-up: https://github.com/llvm/llvm-project/commit/8afcfbfb8fc1e53023ffac9d9bdc424248d6d2ff

which was changing booleans to use true and false and in the this case the comment and the type looked mismatched.

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

2 years ago[mlir] Fix a missing override warning
Kazu Hirata [Tue, 11 Jan 2022 19:03:22 +0000 (11:03 -0800)]
[mlir] Fix a missing override warning

This patch fixes:

  mlir/lib/Dialect/Tosa/Transforms/TosaOptionalDecompositions.cpp:28:8:
  error: 'runOnFunction' overrides a member function but is not marked
  'override' [-Werror,-Wsuggest-override]

2 years ago[SelectionDAG] treat X constrained labels as i for asm
Nick Desaulniers [Tue, 11 Jan 2022 18:16:33 +0000 (10:16 -0800)]
[SelectionDAG] treat X constrained labels as i for asm

Completely rework how we handle X constrained labels for inline asm.

X should really be treated as i. Then existing tests can be moved to use
i D115410 and clang can just emit i D115311. (D115410 and D115311 are
callbr, but this can be done for label inputs, too).

Coincidentally, this simplification solves an ICE uncovered by D87279
based on assumptions made during D69868.

This is the third approach considered. See also discussions v1 (D114895)
and v2 (D115409).

Reported-by: kernel test robot <lkp@intel.com>
Fixes: https://github.com/ClangBuiltLinux/linux/issues/1512

Reviewed By: void, jyknight

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

2 years ago[mlir][tosa] Allow optional TOSA decompositions to be populated separately
Aaron DeBattista [Tue, 11 Jan 2022 18:16:01 +0000 (10:16 -0800)]
[mlir][tosa] Allow optional TOSA decompositions to be populated separately

Moved all TOSA decomposition patterns so that they can be optionally populated
and used by external rewrites. This avoids decomposing TOSa operations when
backends may benefit from the non-decomposed version.

Reviewed By: rsuderman, mehdi_amini

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

2 years ago[libc++][libc++abi][libunwind] Dedup install path var definitions
John Ericson [Tue, 11 Jan 2022 03:03:21 +0000 (03:03 +0000)]
[libc++][libc++abi][libunwind] Dedup install path var definitions

In D116873 I did this for libunwind prior to defining a new install path
variable. But I think the change is good on its own, and libc++{,abi}
could also use it.

libc++ needed the base header var defined above the conditional part to
use it for the prefi+ed headers in the non-target-specific case. For
consistency, I therefore put the unconditional ones above for all 3
libs, which is why I touched the libunwind code (seeing that it had the
core change already)

Reviewed By: phosek, #libunwind, #libc, #libc_abi, ldionne

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

2 years ago[NFC][LazyCallGraph] Remove check in removeDeadFunction() if graph is empty
Arthur Eubanks [Mon, 13 Dec 2021 21:59:47 +0000 (13:59 -0800)]
[NFC][LazyCallGraph] Remove check in removeDeadFunction() if graph is empty

If we're in removeDeadFunction(), we should have already constructed the call graph.

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

2 years ago[ShrinkWrap] check for PPC's non-callee-saved LR
Nick Desaulniers [Tue, 11 Jan 2022 18:01:25 +0000 (10:01 -0800)]
[ShrinkWrap] check for PPC's non-callee-saved LR

As pointed out in https://reviews.llvm.org/D115688#inline-1108193, we
don't want to sink the save point past an INLINEASM_BR, otherwise
prologepilog may incorrectly sink a prolog past the MBB containing an
INLINEASM_BR and into the wrong MBB.

ShrinkWrap is getting this wrong because LR is not in the list of callee
saved registers. Specifically, ShrinkWrap::useOrDefCSROrFI calls
RegisterClassInfo::getLastCalleeSavedAlias which reads
CalleeSavedAliases which was populated by
RegisterClassInfo::runOnMachineFunction by iterating the list of
MCPhysReg returned from MachineRegisterInfo::getCalleeSavedRegs.

Because PPC's LR is non-allocatable, it's NOT considered callee saved.
Add an interface to TargetRegisterInfo for such a case and use it in
Shrinkwrap to ensure we don't sink a prolog past an INLINEASM or
INLINEASM_BR that clobbers LR.

Reviewed By: jyknight, efriedma, nemanjai, #powerpc

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

2 years ago[mlir][tosa] Relax tosa.apply_scale operations
Rob Suderman [Tue, 11 Jan 2022 17:49:36 +0000 (09:49 -0800)]
[mlir][tosa] Relax tosa.apply_scale operations

Apply scale may operate on vectors, scalars, or tensors during
tiling. Relax the requirements to avoid failures.

Reviewed By: NatashaKnk

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

2 years ago[MLIR][SCF] Simplify scf.if by swapping regions if condition is a not
William S. Moses [Tue, 11 Jan 2022 03:27:14 +0000 (22:27 -0500)]
[MLIR][SCF] Simplify scf.if by swapping regions if condition is a not

Given an if of the form, simplify it by eliminating the not and swapping the regions

scf.if not(c) {
  yield origTrue
} else {
  yield origFalse
}

becomes

scf.if c {
  yield origFalse
} else {
  yield origTrue
}

Reviewed By: mehdi_amini

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

2 years ago[ELF] Add RelocationScanner. NFC
Fangrui Song [Tue, 11 Jan 2022 17:54:53 +0000 (09:54 -0800)]
[ELF] Add RelocationScanner. NFC

Currently the way some relocation-related static functions pass around
states is clumsy. Add a Resolver class to store some states as member
variables.

Advantages:

* Avoid the parameter `InputSectionBase &sec` (this offsets the cost passing around `this` paramemter)
* Avoid the parameter `end` (Mips and PowerPC hacks)
* `config` and `target` can be cached as member variables to reduce global state accesses. (potential speedup because the compiler didn't know `config`/`target` were not changed across function calls)
* If we ever want to reduce if-else costs (e.g. `config->emachine==EM_MIPS` for non-Mips) or introduce parallel relocation scan not handling some tricky arches (PPC/Mips), we can templatize Resolver

`target` isn't used as much as `config`, so I change it to a const reference
during the migration.

There is a minor performance inprovement for elf::scanRelocations.

Reviewed By: ikudrin, peter.smith

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

2 years ago[mlir][linalg] Improve pooling op iterator order consistency
Lei Zhang [Tue, 11 Jan 2022 17:04:39 +0000 (17:04 +0000)]
[mlir][linalg] Improve pooling op iterator order consistency

All named ops list iterators for accessing output first except
pooling ops. This commit made the pooling ops consistent with
the rest.

Reviewed By: nicolasvasilache

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

2 years agoFix bazel build after 8503c688d555014b88849e933bf096035a351586.
James Y Knight [Tue, 11 Jan 2022 17:42:49 +0000 (17:42 +0000)]
Fix bazel build after 8503c688d555014b88849e933bf096035a351586.

2 years ago[IRBuilder] Introduce folder using inst-simplify, use for Or fold.
Florian Hahn [Tue, 11 Jan 2022 17:30:48 +0000 (17:30 +0000)]
[IRBuilder] Introduce folder using inst-simplify, use for Or fold.

Alternative to D116817.

This introduces a new value-based folding interface for Or (FoldOr),
which takes 2 values and returns an existing Value or a constant if the
Or can be simplified. Otherwise nullptr is returned. This replaces the
more restrictive CreateOr which takes 2 constants.

This is the used to implement a folder that uses InstructionSimplify.
The logic to simplify `Or` instructions is moved there. Subsequent
patches are going to transition other CreateXXX to the more general
FoldXXX interface.

Reviewed By: nikic, lebedev.ri

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

2 years ago[clang-format] Fix SeparateDefinitionBlocks issues
ksyx [Wed, 5 Jan 2022 15:20:16 +0000 (10:20 -0500)]
[clang-format] Fix SeparateDefinitionBlocks issues

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

- Make no formatting for macros
- Attach comment with definition headers
- Make no change on use of empty lines at block start/end
- Fix misrecognition of keyword namespace

Differential Revision: https://reviews.llvm.org/D116663
Reviewed By: MyDeveloperDay, HazardyKnusperkeks, curdeius

2 years ago[instsimplify] Add a comment and test for a highly confusing case
Philip Reames [Tue, 11 Jan 2022 17:23:33 +0000 (09:23 -0800)]
[instsimplify] Add a comment and test for a highly confusing case

2 years ago[gn build] Port f77d115cc136
LLVM GN Syncbot [Tue, 11 Jan 2022 17:12:28 +0000 (17:12 +0000)]
[gn build] Port f77d115cc136

2 years agoX86InstrInfo: Support immediates that are +1/-1 different in optimizeCompareInstr
Matthias Braun [Tue, 28 Sep 2021 00:57:22 +0000 (17:57 -0700)]
X86InstrInfo: Support immediates that are +1/-1 different in optimizeCompareInstr

This is a re-commit of e2c7ee0743592e39274e28dbe0d0c213ba342317 which
was reverted in a2a58d91e82db38fbdf88cc317dcb3753d79d492 and
ea81cea8163a1a0e54df42103ee1c657bbf03791. This includes a fix to
consistently check for EFLAGS being live-out. See phabricator
review.

Original Summary:

This extends `optimizeCompareInstr` to re-use previous comparison
results if the previous comparison was with an immediate that was 1
bigger or smaller. Example:

    CMP x, 13
    ...
    CMP x, 12   ; can be removed if we change the SETg
    SETg ...    ; x > 12  changed to `SETge` (x >= 13) removing CMP

Motivation: This often happens because SelectionDAG canonicalization
tends to add/subtract 1 often when optimizing for fallthrough blocks.
Example for `x > C` the fallthrough optimization switches true/false
blocks with `!(x > C)` --> `x <= C` and canonicalization turns this into
`x < C + 1`.

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

2 years ago[RISCV] Add DAG combine to fold (fp_to_int (ffloor X)) -> (fcvt X, rdn)
Craig Topper [Tue, 11 Jan 2022 16:55:45 +0000 (08:55 -0800)]
[RISCV] Add DAG combine to fold (fp_to_int (ffloor X)) -> (fcvt X, rdn)

Similar for ceil, trunc, round, and roundeven. This allows us to use
static rounding modes to avoid a libcall.

This optimization is done for AArch64 as isel patterns.
RISCV doesn't have instructions for ceil/floor/trunc/round/roundeven
so the operations don't stick around until isel to enable a pattern
match. Thus I've implemented a DAG combine.

We only handle XLen types except i32 on RV64. i32 will be type
legalized to a RISCVISD node. All other types will be type legalized
to XLen and maintain the FP_TO_SINT/UINT ISD opcode.

Reviewed By: asb

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

2 years ago[SPIR-V] Drop double quote from test pattern
Sven van Haastregt [Tue, 11 Jan 2022 16:54:19 +0000 (16:54 +0000)]
[SPIR-V] Drop double quote from test pattern

When spirv-link is found, it won't match a leading `"`.  This fixes
the test added by commit dbb8d086377b ("[SPIR-V] Add linking using
spirv-link.", 2022-01-11).

2 years ago[clang] Move `ApplyHeaderSearchOptions` from Frontend to Lex
Jan Svoboda [Tue, 11 Jan 2022 16:17:07 +0000 (17:17 +0100)]
[clang] Move `ApplyHeaderSearchOptions` from Frontend to Lex

In D116750, the `clangFrontend` library was added as a dependency of `LexTests` in order to make `clang::ApplyHeaderSearchOptions()` available. This increased the number of TUs the test depends on.

This patch moves the function into `clangLex` and removes dependency of `LexTests` on `clangFrontend`.

Reviewed By: thakis

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

2 years ago[libc][NFC] Move sys/mman entrypoints to the default build configs.
Siva Chandra Reddy [Tue, 11 Jan 2022 05:24:57 +0000 (05:24 +0000)]
[libc][NFC] Move sys/mman entrypoints to the default build configs.

Specifically, mmap and munmap have been moved to the default build list
of entrypoints. To support this, certain deps and includes have been
adjusted. The use of errno in some cases has been updated.

2 years agoMark arith.minf, arith.maxf as commutative.
Christian Sigg [Tue, 11 Jan 2022 12:13:17 +0000 (13:13 +0100)]
Mark arith.minf, arith.maxf as commutative.

Reviewed By: herhut

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

2 years ago[GlobalsModRef] Apply indirect-global rule to all globals initialized from noalias...
Philip Reames [Tue, 11 Jan 2022 16:40:03 +0000 (08:40 -0800)]
[GlobalsModRef] Apply indirect-global rule to all globals initialized from noalias calls

Extend the existing malloc-family specific optimization to all noalias calls.  This allows us to handle allocation wrappers, and removes a dependency on a lib-func check in favor of generic attribute usage.

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

2 years ago[X86] Apply clang-format to X86TargetLowering::isVectorShiftByScalarCheap
Simon Pilgrim [Tue, 11 Jan 2022 16:40:24 +0000 (16:40 +0000)]
[X86] Apply clang-format to X86TargetLowering::isVectorShiftByScalarCheap

Fix indentation

2 years ago[DSE] Style improvements after 3cef3cf - remove redundant dyn_casts [NFC]
Philip Reames [Tue, 11 Jan 2022 16:37:41 +0000 (08:37 -0800)]
[DSE] Style improvements after 3cef3cf - remove redundant dyn_casts [NFC]

I'd been working on exactly the same patch when Nikita landed his, so this patch is basically the style diff between the two.  :)

2 years ago[Nomination] Adding Intel representatives to security group
Dimitry Andric [Tue, 11 Jan 2022 16:30:19 +0000 (17:30 +0100)]
[Nomination] Adding Intel representatives to security group

We would like to nominate Andy Kaylor and Sergey Maslov to join the LLVM security group as a representative of Intel.  Both are members of the Intel compiler team, and would like to register as vendor contacts.  Intel packages and distributes LLVM-based toolchains as part of our compiler products.   As such, we would like to be aware of any security vulnerability found in the compiler, and would like to contribute to the resolution of such issues.

Please let us know if anything is missing from the nomination.

Reviewed By: apilipenko, dim, george.burgess.iv, kristof.beyls, mattdr, nikhgupt, probinson, peter.smith, pietroalbini, steveklabnik

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

2 years ago[InstSimplify] Fold inbounds GEP to poison if base is undef.
Florian Hahn [Tue, 11 Jan 2022 16:11:22 +0000 (16:11 +0000)]
[InstSimplify] Fold inbounds GEP to poison if base is undef.

D92270 updated constant expression folding to fold inbounds GEP to
poison if the base is undef. Apply the same logic to SimplifyGEPInst.

The justification is that we can choose an out-of-bounds pointer as base
pointer.

Reviewed By: nikic, lebedev.ri

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

2 years ago[mips][lld] Add test case to check symbol index reading on mips64el. NFC
Simon Atanasyan [Tue, 11 Jan 2022 16:06:40 +0000 (19:06 +0300)]
[mips][lld] Add test case to check symbol index reading on mips64el. NFC

2 years ago[mips] Use `push_back` to insert element at the end of a container. NFC
Simon Atanasyan [Tue, 11 Jan 2022 05:56:26 +0000 (08:56 +0300)]
[mips] Use `push_back` to insert element at the end of a container. NFC

2 years ago[X86] Tag existing shuffle test case as PR53124
Simon Pilgrim [Tue, 11 Jan 2022 15:11:06 +0000 (15:11 +0000)]
[X86] Tag existing shuffle test case as PR53124

The poor AVX1 codegen matches the core issue raised in PR53124

2 years ago[SCEV] `getSequentialMinMaxExpr()`: look into `umin` when deduplicating operands
Roman Lebedev [Tue, 11 Jan 2022 15:23:02 +0000 (18:23 +0300)]
[SCEV] `getSequentialMinMaxExpr()`: look into `umin` when deduplicating operands

We could just merge all umin into umin_seq, but that is likely
a pessimization, so don't do that, but pretend that we did
for the purpose of deduplication.

2 years ago[NFC][SCEV] More tests with operand-wise redundant operands of umin of umin_seq
Roman Lebedev [Tue, 11 Jan 2022 15:25:53 +0000 (18:25 +0300)]
[NFC][SCEV] More tests with operand-wise redundant operands of umin of umin_seq

2 years ago[compiler-rt] Silence warnings when building with MSVC
Alexandre Ganea [Tue, 11 Jan 2022 15:36:46 +0000 (10:36 -0500)]
[compiler-rt] Silence warnings when building with MSVC

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

2 years ago[libc++] Use TEST_HAS_NO_UNICODE instead of _LIBCPP_HAS_NO_UNICODE in the test suite
Louis Dionne [Mon, 10 Jan 2022 22:14:01 +0000 (17:14 -0500)]
[libc++] Use TEST_HAS_NO_UNICODE instead of _LIBCPP_HAS_NO_UNICODE in the test suite

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

2 years ago[ASan] Driver changes to always link-in asan_static library.
Kirill Stoimenov [Wed, 5 Jan 2022 17:14:40 +0000 (17:14 +0000)]
[ASan] Driver changes to always link-in asan_static library.

This enables the changes from D116182.

Reviewed By: vitalybuka

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

2 years ago[GlobalStatus] Look through non-constexpr casts
Nikita Popov [Tue, 11 Jan 2022 15:00:13 +0000 (16:00 +0100)]
[GlobalStatus] Look through non-constexpr casts

analyzeGlobal() looks through non-constexpr cast instructions when
looking for users. However, this particular place only strips the
casts again if they are constexprs. We should be looking through all
casts here.

2 years ago[NFC][SCEV] Add more tests for umin_seq with redundant operands
Roman Lebedev [Tue, 11 Jan 2022 14:33:15 +0000 (17:33 +0300)]
[NFC][SCEV] Add more tests for umin_seq with redundant operands

2 years ago[gn build] (manually) port 8503c688d555
Nico Weber [Tue, 11 Jan 2022 14:47:28 +0000 (09:47 -0500)]
[gn build] (manually) port 8503c688d555

2 years ago[GlobalOpt] Regenerate test checks (NFC)
Nikita Popov [Tue, 11 Jan 2022 14:34:16 +0000 (15:34 +0100)]
[GlobalOpt] Regenerate test checks (NFC)

2 years ago[clang][lex] Keep references to `DirectoryLookup` objects up-to-date
Jan Svoboda [Tue, 11 Jan 2022 13:47:03 +0000 (14:47 +0100)]
[clang][lex] Keep references to `DirectoryLookup` objects up-to-date

The elements of `SearchPath::SearchDirs` are being referenced to by their indices. This proved to be error-prone: `HeaderSearch::SearchDirToHSEntry` was accidentally not being updated in `HeaderSearch::AddSearchPath()`. This patch fixes that by referencing `SearchPath::SearchDirs` elements by their address instead, which is stable thanks to the bump-ptr-allocation strategy.

Reviewed By: ahoppen

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

2 years ago[mlir][linalg] Use cast instead of dyn_cast that's always dereferenced
Benjamin Kramer [Tue, 11 Jan 2022 14:05:45 +0000 (15:05 +0100)]
[mlir][linalg] Use cast instead of dyn_cast that's always dereferenced

This turns a random nullptr deref into an assertion failure in case
`tensor::registerInferTypeOpInterfaceExternalModels` isn't called.

2 years ago[SCEV] `getSequentialMinMaxExpr()`: keep only the first instance of an operand
Roman Lebedev [Tue, 11 Jan 2022 13:45:22 +0000 (16:45 +0300)]
[SCEV] `getSequentialMinMaxExpr()`: keep only the first instance of an operand

Having the same operand more than once doesn't change the outcome here,
neither reduction-wise nor poison-wise.
We must keep the first instance specifically though.

2 years ago[SCEV] Add test for umin_seq with duplicate operands
Roman Lebedev [Tue, 11 Jan 2022 13:24:29 +0000 (16:24 +0300)]
[SCEV] Add test for umin_seq with duplicate operands

2 years ago[SPIR-V] Remove unused variable
Anastasia Stulova [Tue, 11 Jan 2022 13:45:33 +0000 (13:45 +0000)]
[SPIR-V] Remove unused variable

2 years ago[InstSimplify] Add additional GEP tests with undef bases.
Florian Hahn [Tue, 11 Jan 2022 13:43:53 +0000 (13:43 +0000)]
[InstSimplify] Add additional GEP tests with undef bases.

2 years ago[lldb] Remove non address bits from memory read arguments
David Spickett [Wed, 3 Nov 2021 12:10:40 +0000 (12:10 +0000)]
[lldb] Remove non address bits from memory read arguments

Addresses on AArch64 can have top byte tags, memory tags and pointer
authentication signatures in the upper bits.

While testing memory tagging I found that memory read couldn't
read a range if the two addresses had different tags. The same
could apply to signed pointers given the right circumstance.

(lldb) memory read mte_buf_alt_tag mte_buf+16
error: end address (0x900fffff7ff8010) must be greater than the start
address (0xa00fffff7ff8000).

Or it would try to read a lot more memory than expected.

(lldb) memory read mte_buf mte_buf_alt_tag+16
error: Normally, 'memory read' will not read over 1024 bytes of data.
error: Please use --force to override this restriction just once.
error: or set target.max-memory-read-size if you will often need a
larger limit.

Fix this by removing non address bits before we calculate the read
range. A test is added for AArch64 Linux that confirms this by using
the top byte ignore feature.

This means that if you do read with a tagged pointer the output
does not include those tags. This is potentially confusing but I think
overall it's better that we don't pretend that we're reading memory
from a range that the process is unable to map.

(lldb) p ptr1
(char *) $4 = 0x3400fffffffff140 "\x80\xf1\xff\xff\xff\xff"
(lldb) p ptr2
(char *) $5 = 0x5600fffffffff140 "\x80\xf1\xff\xff\xff\xff"
(lldb) memory read ptr1 ptr2+16
0xfffffffff140: 80 f1 ff ff ff ff 00 00 38 70 bc f7 ff ff 00 00  ........8p......

Reviewed By: omjavaid, danielkiss

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

2 years ago[SPIR-V] Add linking using spirv-link.
Anastasia Stulova [Tue, 11 Jan 2022 11:21:30 +0000 (11:21 +0000)]
[SPIR-V] Add linking using spirv-link.

Add support of linking files compiled into SPIR-V objects
using spirv-link.

Command line inteface examples:

clang --target=spirv64 test1.cl test2.cl

clang  --target=spirv64 test1.cl -o test1.o
clang  --target=spirv64 test1.o test2.cl -o test_app.out

This works independently from the SPIR-V generation method
(via an external tool or an internal backend) and applies
to either approach that is being used.

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

2 years ago[lldb/qemu] Implement GetMmapArgumentList
Pavel Labath [Mon, 10 Jan 2022 15:34:39 +0000 (16:34 +0100)]
[lldb/qemu] Implement GetMmapArgumentList

By forwarding it to the host platform.

2 years ago[SCEV] Reenable umin_seq support and fix the `computeSCEVAtScope()`
Roman Lebedev [Tue, 11 Jan 2022 12:51:43 +0000 (15:51 +0300)]
[SCEV] Reenable umin_seq support and fix the `computeSCEVAtScope()`

This reverts commit f62f47f5e1f641b41d3b7d593c058ebec2883534.

2 years ago[NFC][SCEV] Add reproducers for umin_seq crashes
Roman Lebedev [Tue, 11 Jan 2022 12:33:53 +0000 (15:33 +0300)]
[NFC][SCEV] Add reproducers for umin_seq crashes

As reported in https://reviews.llvm.org/D116766#3233042

2 years ago[LSR] Use pointer args instead of undef for uglygep*.ll tests.
Florian Hahn [Tue, 11 Jan 2022 12:35:55 +0000 (12:35 +0000)]
[LSR] Use pointer args instead of undef for uglygep*.ll tests.

Make the test more robust by replacing undef by pointer arguments. This
ensures that the GEPs cannot be folded to undef.

2 years agoRevert "[Clang][AArch64][ARM] PMUv3.4 Option Added"
David Green [Tue, 11 Jan 2022 12:33:53 +0000 (12:33 +0000)]
Revert "[Clang][AArch64][ARM] PMUv3.4 Option Added"

It turns out this is conflating a few different PMU extensions. And on
Arm ended up breaking M-Profile code generation. Reverting for the
moment whilst we sort out the details.

This reverts commit d17fb46e894501568a1bf3b11a5d920817444630.

2 years ago[Clang][Sema] Fix attribute mismatch warning for ObjC class properties
Egor Zhdan [Wed, 29 Dec 2021 22:02:21 +0000 (22:02 +0000)]
[Clang][Sema] Fix attribute mismatch warning for ObjC class properties

If a class declares an instance property, and an inheritor class declares a class property with the same name, Clang Sema currently treats the latter as an overridden property, and compares the attributes of the two properties to check for a mismatch. The resulting diagnostics might be misleading, since neither of the properties actually overrides the another one.

rdar://86018435

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

2 years ago[CodeGen] Avoid deprecated Address constructor
Nikita Popov [Tue, 11 Jan 2022 12:01:28 +0000 (13:01 +0100)]
[CodeGen] Avoid deprecated Address constructor

2 years ago[SVE][CodeGen] Use splice instruction when lowering VECTOR_SPLICE
David Sherwood [Thu, 16 Dec 2021 08:57:18 +0000 (08:57 +0000)]
[SVE][CodeGen] Use splice instruction when lowering VECTOR_SPLICE

For certain negative indices passed to the VECTOR_SPLICE operation
we can actually directly use the SVE splice instruction by creating
the appropriate predicate. The predicate needs to be constructed in
such a way that all but the last -idx elements are false. We can do
this efficiently using a combination of 'ptrue' (with the appropriate
fixed pattern, e.g. vl1, vl2, etc.) and 'rev'. The advantage of using
these instructions to generate the predicate is they do not set any
flags, unlike the whilelo instruction. This is critical when the splice
operation is in a loop, since we want MachineLICM to hoist the
predicate generation out of the loop.

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

2 years agoARM: make FastISel & GISel pass -1 to ADJCALLSTACKUP to signal no callee pop.
Tim Northover [Fri, 7 Jan 2022 13:49:18 +0000 (13:49 +0000)]
ARM: make FastISel & GISel pass -1 to ADJCALLSTACKUP to signal no callee pop.

The interface for these instructions changed with support for mandatory tail
calls, and now -1 indicates the CalleePopAmount argument is not valid.
Unfortunately I didn't realise FastISel or GISel did calls at the time so
didn't update them.

2 years ago[SemaTemplateInstantiate] Use cast<> instead of dyn_cast<> to avoid dereference of...
Simon Pilgrim [Tue, 11 Jan 2022 11:12:12 +0000 (11:12 +0000)]
[SemaTemplateInstantiate] Use cast<> instead of dyn_cast<> to avoid dereference of nullptr

The pointer is always dereferenced immediately below, so assert the cast is correct instead of returning nullptr

2 years ago[MemoryBuiltins] Remove unused isOpNewLikeFn() (NFC)
Nikita Popov [Tue, 11 Jan 2022 11:27:23 +0000 (12:27 +0100)]
[MemoryBuiltins] Remove unused isOpNewLikeFn() (NFC)

This function is no longer used since
2cafbcb560d9e6e2300941d088e754b01d56595b.

2 years ago[MemoryBuiltins] Remove unused isStrdupLikeFn() function (NFC)
Nikita Popov [Tue, 11 Jan 2022 11:25:39 +0000 (12:25 +0100)]
[MemoryBuiltins] Remove unused isStrdupLikeFn() function (NFC)

This function is no longer used after
dcbc91f40c2e6ff578667020f7c6a05c25149865.

2 years ago[DSE] Check for noalias calls rather than alloc functions
Nikita Popov [Tue, 11 Jan 2022 11:08:44 +0000 (12:08 +0100)]
[DSE] Check for noalias calls rather than alloc functions

For these "visible on unwind/ret" checks we only care about the
fact that no other code has access to the pointer (unless it
escapes). A noalias call is sufficient for this, it does not
have to be a known allocation function.

This is basically the same change as D116728, but for DSE rather
than LICM.

2 years ago[LSR] Remove duplicated test address-space-loop.ll.
Florian Hahn [Tue, 11 Jan 2022 11:18:28 +0000 (11:18 +0000)]
[LSR] Remove duplicated test address-space-loop.ll.

llvm/test/Transforms/LoopStrengthReduce/uglygep-address-space.ll has
exactly the same checks and input. Remove the duplicated test.

2 years ago[mlir][linalg][bufferize] Fix CallOp bufferization
Matthias Springer [Tue, 11 Jan 2022 11:04:55 +0000 (20:04 +0900)]
[mlir][linalg][bufferize] Fix CallOp bufferization

Previously, CallOps did not have any aliasing OpResult/OpOperand pairs. Therefore, CallOps were mostly ignored by the analysis and buffer copies were not inserted when necessary.

This commit introduces the following changes:
* Function bbArgs writable by default. A function can now be bufferized without inspecting its callers.
* Callers must introduce buffer copies of function arguments when necessary. If a function is external, the caller must conservatively assume that a function argument is modified by the callee after bufferization. If the function is not external, the caller inspects the callee to determine if a function argument is modified.

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

2 years ago[DSE] Add additional tests for noalias calls (NFC)
Nikita Popov [Tue, 11 Jan 2022 10:55:59 +0000 (11:55 +0100)]
[DSE] Add additional tests for noalias calls (NFC)

Currently this is special-cased to TLI alloc functions only.

2 years agoReland "[AST] Add RParen loc for decltype AutoTypeloc."
Haojian Wu [Mon, 10 Jan 2022 14:19:05 +0000 (15:19 +0100)]
Reland "[AST] Add RParen loc for decltype AutoTypeloc."

Reland 55d96ac and 37ec65e with a clang-tidy fix.

2 years ago[ADT] Add an in-place version of toHex()
Hans Wennborg [Mon, 10 Jan 2022 18:45:13 +0000 (19:45 +0100)]
[ADT] Add an in-place version of toHex()

and use that to simplify MD5's hex string code which was previously
using a string stream, as well as Clang's
CGDebugInfo::computeChecksum().

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

2 years ago[DSE] Make test more robust (NFC)
Nikita Popov [Tue, 11 Jan 2022 10:49:08 +0000 (11:49 +0100)]
[DSE] Make test more robust (NFC)

If the allocation is not captured, then all the stores before the
ret are dead anyway.

2 years ago[ADT] Use a lookup table in hexdigit() and call that from toHex()
Hans Wennborg [Tue, 11 Jan 2022 09:08:25 +0000 (10:08 +0100)]
[ADT] Use a lookup table in hexdigit() and call that from toHex()

A lookup table, which toHex() was using, seems like the better approach.
Having two implementations is redundant, so put the lookup table in
hexdigit() and make toHex() call that.

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

2 years ago[SemaOverload] compareConversionFunctions - use castAs<> instead of getAs<> to avoid...
Simon Pilgrim [Mon, 10 Jan 2022 17:44:18 +0000 (17:44 +0000)]
[SemaOverload] compareConversionFunctions - use castAs<> instead of getAs<> to avoid dereference of nullptr

The pointer is dereferenced immediately below, so assert the cast is correct instead of returning nullptr

2 years ago[SemaOverload] Use castAs<> instead of getAs<> to avoid dereference of nullptr
Simon Pilgrim [Mon, 10 Jan 2022 17:31:35 +0000 (17:31 +0000)]
[SemaOverload] Use castAs<> instead of getAs<> to avoid dereference of nullptr

The pointer is always dereferenced inside BuildSimilarlyQualifiedPointerType, so assert the cast is correct instead of returning nullptr

2 years ago[clang] [test] Fix clang-cl unused argument tests on paths that start with /U
Martin Storsjö [Tue, 11 Jan 2022 10:22:42 +0000 (12:22 +0200)]
[clang] [test] Fix clang-cl unused argument tests on paths that start with /U

This reinstates a test that was temporarily removed in
e26bbae30218a35d76a79fe90b0e41dd0f71b779, in a form that works on
Darwin.

Use -LD instead of -link as a linker argument that is unused when
compiling, that produces warnings normally. -LD can be placed anywhere
in the command line, so that the command line ends with "-- %s", making
paths starting with /U correctly interpreted as paths, not options.

2 years ago[LICM] Regenerate test checks (NFC)
Nikita Popov [Tue, 11 Jan 2022 09:55:50 +0000 (10:55 +0100)]
[LICM] Regenerate test checks (NFC)

2 years ago[MLIR] Update allocs to memref.allocs in documentation.
Julian Gross [Tue, 11 Jan 2022 10:04:15 +0000 (11:04 +0100)]
[MLIR] Update allocs to memref.allocs in documentation.

Changed the remaining appearances of alloc to memref.alloc in several
documentation sections, since they lead to misunderstandings, if they
are used.

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

2 years ago[RISCV] Generate 32 bits jumptable entries when code model is small
wangpc [Tue, 11 Jan 2022 10:19:05 +0000 (18:19 +0800)]
[RISCV] Generate 32 bits jumptable entries when code model is small

The code can only address the whole RV32 address space or the lower 2 GiB
of the RV64 address space in small code model, so 32 bits entry is enough.
Cache hit ratio and code size have some improvements.

Reviewed By: asb

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

2 years ago[flang] Add tests for converting arrays and refs to arrays. NFC
Diana Picus [Wed, 22 Dec 2021 09:06:37 +0000 (09:06 +0000)]
[flang] Add tests for converting arrays and refs to arrays. NFC

Cover more of the code paths from LLVMTypeConverter::convertPointerLike
and LLVMTypeConverter::convertSequenceType.

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

2 years ago[clangd] Save more getFileID in Selection
Sam McCall [Tue, 11 Jan 2022 10:01:02 +0000 (11:01 +0100)]
[clangd] Save more getFileID in Selection

This saves about 10% of SelectionVisitor::pop().

2 years ago[SCEVExpander] Use IntToPtr for temporary instruction.
Florian Hahn [Tue, 11 Jan 2022 09:40:21 +0000 (09:40 +0000)]
[SCEVExpander] Use IntToPtr for temporary instruction.

Use PtrToInt instead Add when creating temporary instructions. The add
might get folded away with more sophisticated folding.

2 years ago[IR] Change vector.splice intrinsic to reject out-of-bounds indices
David Sherwood [Fri, 17 Dec 2021 09:39:21 +0000 (09:39 +0000)]
[IR] Change vector.splice intrinsic to reject out-of-bounds indices

I've changed the definition of the experimental.vector.splice
instrinsic to reject indices that are known to be or possibly
out-of-bounds. In practice, this means changing the definition so that
the index is now only valid in the range [-VL, VL-1] where VL is the
known minimum vector length. We use the vscale_range attribute to
take the minimum vscale value into account so that we can permit
more indices when the attribute is present.

The splice intrinsic is currently only ever generated by the vectoriser,
which will never attempt to splice vectors with out-of-bounds values.
Changing the definition also makes things simpler for codegen since we
can always assume that the index is valid.

This patch was created in response to review comments on D115863

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

2 years ago[clangd] Small optimization in SelectionTree
Sam McCall [Tue, 11 Jan 2022 09:15:12 +0000 (10:15 +0100)]
[clangd] Small optimization in SelectionTree

This seems to be strictly faster in all cases. Before fixing D116978 it
was one of the hot paths, and may become one again.

2 years ago[clang] [test] Remove newly added tests that fail on Darwin
Martin Storsjö [Tue, 11 Jan 2022 09:06:29 +0000 (11:06 +0200)]
[clang] [test] Remove newly added tests that fail on Darwin

These tests were recently added in
50ec1306d060e46e0d53c9f5d8a052e1b0d10d3b. The clang-cl invocations
interpret the source path, %s, which begins with /Users, as a cl
option /U. Normally this is worked around by passing -- before
the arguments that must be interpreted as files, not options, but
in the current test, the -link option must be passed last, after any
file names.

2 years ago[LoopVersioning] Check the full generated runtime checks in lcssa.ll.
Florian Hahn [Tue, 11 Jan 2022 08:37:29 +0000 (08:37 +0000)]
[LoopVersioning] Check the full generated runtime checks in lcssa.ll.

This makes improvements in follow-up patches more obvious.

2 years ago[mlir][GPU] Fix attribute name of DL specification
Diego Caballero [Tue, 11 Jan 2022 08:30:33 +0000 (08:30 +0000)]
[mlir][GPU] Fix attribute name of DL specification

D115722 added a DL spec to GPU modules. It happens that the DL
default interface implementation is sensitive to the name of the
DL spec attribute. This patch is fixing the name of the attribute
to be the expected one.

Reviewed By: ftynse

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

2 years ago[CodeGen] Make element type in emitArrayDestroy() predictable
Nikita Popov [Tue, 4 Jan 2022 14:24:14 +0000 (15:24 +0100)]
[CodeGen] Make element type in emitArrayDestroy() predictable

When calling emitArrayDestroy(), the pointer will usually have
ConvertTypeForMem(EltType) as the element type, as one would expect.
However, globals with initializers sometimes don't use the same
types as values normally would, e.g. here the global uses
{ double, i32 } rather than %struct.T as element type.

Add an early cast to the global destruction path to avoid this
special case. The cast would happen lateron anyway, it only gets
moved to an earlier point.

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

2 years ago[CSKY] Add CSKYConstantIslands Pass to lift or duplicate constant pool entry
Zi Xuan Wu [Tue, 11 Jan 2022 08:13:21 +0000 (16:13 +0800)]
[CSKY] Add CSKYConstantIslands Pass to lift or duplicate constant pool entry

Loading constants inline is expensive on CSKY and it's in general better
to place the constant nearby in code space and then it can be loaded with a
simple 16/32 bit load instruction like lrw.

It needs lift or duplicates constant pool entry to make constant nearby so that lrw instruction can reach.

2 years ago[RISCV] Override TargetLowering::BuildSDIVPow2 to generate SELECT
wangpc [Tue, 11 Jan 2022 07:52:00 +0000 (15:52 +0800)]
[RISCV] Override TargetLowering::BuildSDIVPow2 to generate SELECT

When `Zbt` is enabled, we can generate SELECT for division by power
of 2, so that there is no data dependency.

Reviewed By: craig.topper

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

2 years ago[clang] Add --start-no-unused-arguments/--end-no-unused-arguments to silence some...
Martin Storsjö [Sat, 1 Jan 2022 13:54:29 +0000 (15:54 +0200)]
[clang] Add --start-no-unused-arguments/--end-no-unused-arguments to silence some unused argument warnings

When passing a set of flags to configure defaults for a specific
target (similar to the cmake settings `CLANG_DEFAULT_RTLIB`,
`CLANG_DEFAULT_UNWINDLIB`, `CLANG_DEFAULT_CXX_STDLIB` and
`CLANG_DEFAULT_LINKER`, but without hardcoding them in the binary),
some of the flags may cause warnings (e.g. `-stdlib=` when compiling C
code). Allow requesting selectively ignoring unused arguments among
some of the arguments on the command line, without needing to resort
to `-Qunused-arguments` or `-Wno-unused-command-line-argument`.

Fix up the existing diagnostics.c testcase. It was added in
response to PR12181 to fix handling of
`-Werror=unused-command-line-argument`, but the command line option
in the test (`-fzyzzybalubah`) now triggers "error: unknown argument"
instead of the intended warning. Change it into a linker input
(`-lfoo`) which triggers the intended diagnostic. Extend the
existing test case to check more cases and make sure that it keeps
testing the intended case.

Add testing of the new option to this existing test.

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

2 years ago[gn build] Port 8d23b7420c92
LLVM GN Syncbot [Tue, 11 Jan 2022 06:50:34 +0000 (06:50 +0000)]
[gn build] Port 8d23b7420c92

2 years ago[libc++][ranges] Implement `uninitialized_copy{,_n}` and `uninitialized_move{,_n}`.
Konstantin Varlamov [Tue, 11 Jan 2022 06:49:37 +0000 (22:49 -0800)]
[libc++][ranges] Implement `uninitialized_copy{,_n}` and `uninitialized_move{,_n}`.

Also implement `in_out_result` which is a prerequisite.

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

2 years ago[NFC][XCOFF][llvm-readobj] replace binaries with YAMLs (only tests for Symbols).
Esme-Yi [Tue, 11 Jan 2022 06:17:16 +0000 (06:17 +0000)]
[NFC][XCOFF][llvm-readobj] replace binaries with YAMLs (only tests for Symbols).

Summary: Since yaml2obj now supports converting AuxSymbols, we can use YAMLs as input for symbol-related tests of llvm-readobj instead of binaries.

Reviewed By: jhenderson, shchenz

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