platform/upstream/llvm.git
4 years agoAdd a llvm-gsymutil tool that can convert object files to GSYM and perform lookups.
Greg Clayton [Thu, 20 Feb 2020 01:31:27 +0000 (17:31 -0800)]
Add a llvm-gsymutil tool that can convert object files to GSYM and perform lookups.

Summary:
This patch creates the llvm-gsymutil binary that can convert object files to GSYM using the --convert <path> option. It can also dump and lookup addresses within GSYM files that have been saved to disk.

To dump a file:

llvm-gsymutil /path/to/a.gsym

To perform address lookups, like with atos, on GSYM files:

llvm-gsymutil --address 0x1000 --address 0x1100 /path/to/a.gsym

To convert a mach-o or ELF file, including any DWARF debug info contained within the object files:

llvm-gsymutil --convert /path/to/a.out --out-file /path/to/a.out.gsym

Conversion highlights:
- convert DWARF debug info in mach-o or ELF files to GSYM
- convert symbols in symbol table to GSYM and don't convert symbols that overlap with DWARF debug info
- extract UUID from object files
- extract .text (read + execute) section address ranges and filter out any DWARF or symbols that don't fall in those ranges.
- if .text sections are extracted, and if the last gsym::FunctionInfo object has no size, cap the size to the end of the section the function was contained in

Dumping GSYM files will dump all sections of the GSYM file in textual format.

Reviewers: labath, aadsm, serhiy.redko, jankratochvil, xiaobai, wallace, aprantl, JDevlieghere, jdoerfert

Subscribers: mgorny, hiraditya, llvm-commits

Tags: #llvm

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

4 years ago[SimpleLoopUnswitch] Fix introduction of UB when hoisted condition may be undef or...
Juneyoung Lee [Wed, 26 Feb 2020 02:33:34 +0000 (11:33 +0900)]
[SimpleLoopUnswitch] Fix introduction of UB when hoisted condition may be undef or poison

Summary:
Loop unswitch hoists branches on loop-invariant conditions. However, if this
condition is poison/undef and the branch wasn't originally reachable, loop
unswitch introduces UB (since the optimized code will branch on poison/undef and
the original one didn't)).
We fix this problem by freezing the condition to ensure we don't introduce UB.

We will now transform the following:
  while (...) {
    if (C) { A }
    else   { B }
  }

Into:
  C' = freeze(C)
  if (C') {
    while (...) { A }
  } else {
    while (...) { B }
  }

This patch fixes the root cause of the following bug reports (which use the old loop unswitch, but can be reproduced with minor changes in the code and -enable-nontrivial-unswitch):
- https://llvm.org/bugs/show_bug.cgi?id=27506
- https://llvm.org/bugs/show_bug.cgi?id=31652

Reviewers: reames, majnemer, chenli, sanjoy, hfinkel

Reviewed By: reames

Subscribers: hiraditya, jvesely, nhaehnle, filcab, regehr, trentxintong, nlopes, llvm-commits, mzolotukhin

Tags: #llvm

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

4 years ago[PowerPC] Fix the unexpected modification caused by D62993 in LowerSELECT_CC for...
Kang Zhang [Wed, 26 Feb 2020 02:59:03 +0000 (02:59 +0000)]
[PowerPC] Fix the unexpected modification caused by D62993 in LowerSELECT_CC for power9

Summary:
The patch D62993 : `[PowerPC] Emit scalar min/max instructions with unsafe fp math`
has modified the functionality when `Subtarget.hasP9Vector() && (!HasNoInfs || !HasNoNaNs)`,
 this modification is not expected.

Reviewed By: nemanjai

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

4 years ago[MC] Default MCContext::UseNamesOnTempLabels to false and only set it to true for...
Fangrui Song [Tue, 25 Feb 2020 02:09:27 +0000 (18:09 -0800)]
[MC] Default MCContext::UseNamesOnTempLabels to false and only set it to true for MCAsmStreamer

Only MCAsmStreamer (assembly output) needs to keep names of temporary labels created by
MCContext::createTempSymbol().

This change made the rL236642 optimization available for cc2as and
probably some other users.

This eliminates a behavior difference between llvm-mc -filetype=obj and cc1as, which caused
https://reviews.llvm.org/D74006#1890487

Reviewed By: efriedma

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

4 years ago[MC][ARM] Don't create multiple .ARM.exidx associated to one .text
Fangrui Song [Tue, 25 Feb 2020 01:54:39 +0000 (17:54 -0800)]
[MC][ARM] Don't create multiple .ARM.exidx associated to one .text

Fixed an issue exposed by D74006.

In clang cc1as, MCContext::UseNamesOnTempLabels is true.
When parsing a .fnstart directive, FnStart gets redefined to a temporary symbol of a different name (.Ltmp0, .Ltmp1, ...).
MCContext::getELFSection() called by SwitchToEHSection() will create a different .ARM.exidx each time.

llvm-mc uses `Ctx.setUseNamesOnTempLabels(false);` and FnStart is unnamed.
MCContext::getELFSection() called by SwitchToEHSection() will reuse the same .ARM.exidx .

Reviewed By: efriedma

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

4 years ago[Analysis] Fix -Wrange-loop-analysis after D69876
Fangrui Song [Wed, 26 Feb 2020 02:03:47 +0000 (18:03 -0800)]
[Analysis] Fix -Wrange-loop-analysis after D69876

4 years ago[docs] dump-ast-matchers removes const from Matcher args and handles template functio...
Nathan James [Wed, 26 Feb 2020 01:56:21 +0000 (01:56 +0000)]
[docs] dump-ast-matchers removes const from Matcher args and handles template functions slightly better

Reviewers: aaron.ballman, gribozavr2, joerg

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

4 years agoRemove namespace lld { namespace coff { from COFF LLD cpp files
Reid Kleckner [Thu, 20 Feb 2020 01:05:42 +0000 (17:05 -0800)]
Remove namespace lld { namespace coff { from COFF LLD cpp files

Instead, use `using namespace lld(::coff)`, and fully qualify the names
of free functions where they are defined in cpp files.

This effectively reverts d79c3be618 to follow the new style guide added
in 236fcbc21a7a8872.

Reviewed By: MaskRay

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

4 years ago[compiler-rt] Fix a typo in a comment in FuzzedDataProvider.h.
Max Moroz [Wed, 26 Feb 2020 01:10:16 +0000 (17:10 -0800)]
[compiler-rt] Fix a typo in a comment in FuzzedDataProvider.h.

4 years ago[SelectionDAG][PowerPC][AArch64][X86][ARM] Add chain input and output the ISD::FLT_RO...
Craig Topper [Wed, 26 Feb 2020 00:57:42 +0000 (16:57 -0800)]
[SelectionDAG][PowerPC][AArch64][X86][ARM] Add chain input and output the ISD::FLT_ROUNDS_

This node reads the rounding control which means it needs to be ordered properly with operations that change the rounding control. So it needs to be chained to maintain order.

This patch adds a chain input and output to the node and connects it to the chain in SelectionDAGBuilder. I've update all in-tree targets to connect their chain through their lowering code.

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

4 years agoRemove std::shared_ptr::allocate_shared
zoecarver [Wed, 26 Feb 2020 00:50:57 +0000 (16:50 -0800)]
Remove std::shared_ptr::allocate_shared

std::shared_ptr::allocate_shared isn't in the standard. This commit removes it from libc++. It updates std::allocate_shared to use __create_with_cntrl_block.

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

4 years ago[ORC] Remove the JITDylib::SymbolTableEntry::isInMaterializingState() method.
Lang Hames [Wed, 26 Feb 2020 00:04:41 +0000 (16:04 -0800)]
[ORC] Remove the JITDylib::SymbolTableEntry::isInMaterializingState() method.

It was being used inconsistently. Uses have been replaced with direct checks
on the symbol state.

4 years agoFix a null dereference in the LLDB data formatters.
Adrian Prantl [Wed, 26 Feb 2020 00:42:53 +0000 (16:42 -0800)]
Fix a null dereference in the LLDB data formatters.

4 years agoRevert "[libTooling] Add function to determine associated text of a declaration."
Nico Weber [Wed, 26 Feb 2020 00:21:52 +0000 (19:21 -0500)]
Revert "[libTooling] Add function to determine associated text of a declaration."

This reverts commit 9c54f6154f748e707ad2385ddf6d66e812890c6a.
Breaks two tests on Windows, see e.g.
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/14505/steps/stage%201%20check/logs/stdio

4 years ago[GISel][KnownBits] Update a comment regarding the effect of cache on PHIs
Quentin Colombet [Tue, 25 Feb 2020 22:03:21 +0000 (14:03 -0800)]
[GISel][KnownBits] Update a comment regarding the effect of cache on PHIs

Unlike what I claimed in my previous commit. The caching is
actually not NFC on PHIs.

When we put a big enough max depth, we end up simulating loops.
The cache is effectively cutting the simulation short and we
get less information as a result.
E.g.,
```
v0 = G_CONSTANT i8 0xC0
jump
v1 = G_PHI i8 v0, v2
v2 = G_LSHR i8 v1, 1
```

Let say we want the known bits of v1.
- With cache:
Set v1 cache to we know nothing
v1 is v0 & v2
v0 gives us 0xC0
v2 gives us known bits of v1 >> 1
v1 is in the cache
=> v1 is 0, thus v2 is 0x80
Finally v1 is v0 & v2 => 0x80

- Without cache and enough depth to do two iteration of the loop:
v1 is v0 & v2
v0 gives us 0xC0
v2 gives us known bits of v1 >> 1
v1 is v0 & v2
v0 is 0xC0
v2 is v1 >> 1
Reach the max depth for v1...
unwinding
v1 is know nothing
v2 is 0x80
v0 is 0xC0
v1 is 0x80
v2 is 0xC0
v0 is 0xC0
v1 is 0xC0

Thus now v1 is 0xC0 instead of 0x80.

I've added a unittest demonstrating that.

NFC

4 years ago[mlir] [VectorOps] Add vector.print to EDSC
aartbik [Tue, 25 Feb 2020 22:57:35 +0000 (14:57 -0800)]
[mlir] [VectorOps] Add vector.print to EDSC

Summary: This prepares using the operation in model builder runner.

Reviewers: nicolasvasilache, andydavis1

Reviewed By: nicolasvasilache

Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

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

4 years ago[NFC][libc++] Refactor some future tests to reduce code duplication
Louis Dionne [Tue, 25 Feb 2020 23:15:56 +0000 (18:15 -0500)]
[NFC][libc++] Refactor some future tests to reduce code duplication

The same test was being repeated over and over again.
That's what functions are for.

4 years ago[mlir][DenseElementsAttr] Fix storage size for bfloat16 when parsing from hex.
River Riddle [Tue, 25 Feb 2020 22:56:24 +0000 (14:56 -0800)]
[mlir][DenseElementsAttr] Fix storage size for bfloat16 when parsing from hex.

Summary: bfloat16 is stored internally as a double, so we can't direct use Type::getIntOrFloatBitWidth.

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

4 years agoRe-land Unwind past an interrupt handler correctly on arm or at pc==0
Jason Molenda [Tue, 25 Feb 2020 22:55:47 +0000 (14:55 -0800)]
Re-land Unwind past an interrupt handler correctly on arm or at pc==0

Updated the patch to only fetch $pc on a Return Address-using
target only if we're in a trap frame *and* if there is a saved
location for $pc in the trap frame's unwind rules.  If not,
we fall back to fetching the Return Address register (eg $lr).

Original commit msg:

    Unwind past an interrupt handler correctly on arm or at pc==0

    Fix RegisterContextLLDB::InitializeNonZerothFrame so that it
    will fetch a FullUnwindPlan instead of falling back to the
    architectural default unwind plan -- GetFullUnwindPlan knows
    how to spot a jmp 0x0 that results in a fault, which may be
    the case when we see a trap handler on the stack.

    Fix RegisterContextLLDB::SavedLocationForRegister so that when
    the pc value is requested from a trap handler frame, where we
    have a complete register context available to us, don't provide
    the Return Address register (lr) instead of the pc.  We have
    an actual pc value here, and it's pointing to the instruction
    that faulted.

    Differential revision: https://reviews.llvm.org/D75007
    <rdar://problem/59416588>

4 years ago[libc++] Avoid including <semaphore.h> on Apple
Louis Dionne [Tue, 25 Feb 2020 22:52:34 +0000 (17:52 -0500)]
[libc++] Avoid including <semaphore.h> on Apple

It turns out that <semaphore.h> is not well-behaved, as it transitively
includes <sys/param.h>, and that one defines several non-reserved macros
that clash with some downstream projects in modular builds. For the time
being, using <sys/semaphore.h> instead gives us the declarations we need
without the macros.

rdar://59744472

4 years agoRevert "[X86MCTargetDesc.h] Speculative fix for macro collision with sys/param.h"
Vedant Kumar [Tue, 25 Feb 2020 22:37:59 +0000 (14:37 -0800)]
Revert "[X86MCTargetDesc.h] Speculative fix for macro collision with sys/param.h"

This reverts commit eee22ec3c3712a1089cbdbe66ccf36dd89be507a.

This is not the correct fix, the root cause seems to be a bug in the
stage1 host clang compiler. See https://reviews.llvm.org/D75091 for more
discussion.

4 years ago[clang] Annotating C++'s `operator new` with more attributes
Roman Lebedev [Tue, 25 Feb 2020 22:37:17 +0000 (01:37 +0300)]
[clang] Annotating C++'s `operator new` with more attributes

Summary:
Right now we annotate C++'s `operator new` with `noalias` attribute,
which very much is healthy for optimizations.

However as per [[ http://eel.is/c++draft/basic.stc.dynamic.allocation | `[basic.stc.dynamic.allocation]` ]],
there are more promises on global `operator new`, namely:
* non-`std::nothrow_t` `operator new` *never* returns `nullptr`
* If `std::align_val_t align` parameter is taken, the pointer will also be `align`-aligned
* ~~global `operator new`-returned pointer is `__STDCPP_DEFAULT_NEW_ALIGNMENT__`-aligned ~~ It's more caveated than that.

Supplying this information may not cause immediate landslide effects
on any specific benchmarks, but it for sure will be healthy for optimizer
in the sense that the IR will better reflect the guarantees provided in the source code.

The caveat is `-fno-assume-sane-operator-new`, which currently prevents emitting `noalias`
attribute, and is automatically passed by Sanitizers ([[ https://bugs.llvm.org/show_bug.cgi?id=16386 | PR16386 ]]) - should it also cover these attributes?
The problem is that the flag is back-end-specific, as seen in `test/Modules/explicit-build-flags.cpp`.
But while it is okay to add `noalias` metadata in backend, we really should be adding at least
the alignment metadata to the AST, since that allows us to perform sema checks on it.

Reviewers: erichkeane, rjmccall, jdoerfert, eugenis, rsmith

Reviewed By: rsmith

Subscribers: xbolva00, jrtc27, atanasyan, nlopes, cfe-commits

Tags: #llvm, #clang

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

4 years ago[Sema] Perform call checking when building CXXNewExpr
Roman Lebedev [Tue, 25 Feb 2020 22:36:44 +0000 (01:36 +0300)]
[Sema] Perform call checking when building CXXNewExpr

Summary:
There was even a TODO for this.
The main motivation is to make use of call-site based
`__attribute__((alloc_align(param_idx)))` validation (D72996).

Reviewers: rsmith, erichkeane, aaron.ballman, jdoerfert

Reviewed By: rsmith

Subscribers: cfe-commits

Tags: #clang

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

4 years ago[llvm][TextAPI] rename test vars, NFC
Cyndy Ishida [Fri, 14 Feb 2020 22:05:59 +0000 (14:05 -0800)]
[llvm][TextAPI] rename test vars, NFC

* Conforms to clang tidy

4 years ago[OpenMP][Opt] Combine `struct ident_t*` during deduplication
Johannes Doerfert [Thu, 20 Feb 2020 20:17:43 +0000 (14:17 -0600)]
[OpenMP][Opt] Combine `struct ident_t*` during deduplication

If we deduplicate OpenMP runtime calls we have multiple `ident_t*` that
represent information like source location. So far, we simply kept the
one used by the replacement call. However, as exposed by PR44893, that
can cause problems if we have stack allocated `ident_t` objects. While
we need to revisit the use of these as well, it is clear that we
eventually want to merge source location information in some way. With
this patch we add the infrastructure to do so but without doing the
actual merge. Instead we pick a global `ident_t` from the replaced
calls, if possible, or create a new one with an unknown location
instead.

Reviewed By: JonChesterfield

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

4 years ago[WebAssembly] Simplify extract_vector lowering
Thomas Lively [Sat, 22 Feb 2020 01:54:47 +0000 (17:54 -0800)]
[WebAssembly] Simplify extract_vector lowering

Summary:
Removes patterns that were not doing useful work, changes the
default extract instructions to be the unsigned versions now that
they are enabled by default, fixes PR44988, and adds tests for
sext_inreg lowering.

Reviewers: aheejin

Reviewed By: aheejin

Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits

Tags: #llvm

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

4 years ago[libTooling] Add function to determine associated text of a declaration.
Yitzhak Mandelbaum [Fri, 3 Jan 2020 14:57:33 +0000 (09:57 -0500)]
[libTooling] Add function to determine associated text of a declaration.

Summary:
This patch adds `getAssociatedRange` which, for a given decl, computes preceding
and trailing text that would conceptually be associated with the decl by the
reader. This includes comments, whitespace, and separators like ';'.

Reviewers: gribozavr

Subscribers: cfe-commits

Tags: #clang

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

4 years ago[ObjC][ARC] Don't move a retain call living outside a loop into the loop
Akira Hatanaka [Tue, 25 Feb 2020 20:20:07 +0000 (12:20 -0800)]
[ObjC][ARC] Don't move a retain call living outside a loop into the loop
body

We started seeing cases where ARC optimizer would move retain calls into
loop bodies, causing imbalance in the number of retain and release
calls, after changes were made to delete inert ARC calls since the inert
calls that used to block code motion are gone.

Fix the bug by setting the CFG hazard flag when visiting a loop header.

rdar://problem/56908836

4 years ago[LIBOMPTARGET]Fix PR44933: fix crash because of the too early deinitialization of...
Alexey Bataev [Wed, 19 Feb 2020 14:41:50 +0000 (09:41 -0500)]
[LIBOMPTARGET]Fix PR44933: fix crash because of the too early deinitialization of libomptarget.

Summary:
Instead of using global variables with unpredicted time of
deinitialization, use dynamically allocated variables with functions
explicitly marked as global constructor/destructor and priority. This
allows to prevent the crash because of the incorrect order of dynamic
libraries deinitialization.

Reviewers: grokos, hfinkel

Subscribers: caomhin, kkwli0, openmp-commits

Tags: #openmp

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

4 years ago[X86] Add test to show incorrect ordering of flt.rounds intrinsic relative to calls...
Craig Topper [Tue, 25 Feb 2020 20:22:38 +0000 (12:22 -0800)]
[X86] Add test to show incorrect ordering of flt.rounds intrinsic relative to calls to fesetround.

We don't order flt.rounds intrinsics relative to side effecting
operations in SelectionDAG. And we CSE multiple calls because of
this.

4 years agoCheck args passed to __builtin_frame_address and __builtin_return_address.
zoecarver [Tue, 25 Feb 2020 20:42:49 +0000 (12:42 -0800)]
Check args passed to __builtin_frame_address and __builtin_return_address.

Verifies that an argument passed to __builtin_frame_address or __builtin_return_address is within the range [0, 0xFFFF]

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

Re-committed after fixed: c93112dc4f745b0455addb54bfe1c2f79b827c6d

4 years agoUse "nop" to avoid size warnings.
Bill Wendling [Tue, 25 Feb 2020 20:31:20 +0000 (12:31 -0800)]
Use "nop" to avoid size warnings.

4 years ago[SCEV][IndVars] Always provide insertion point to the SCEVExpander::isHighCostExpansion()
Roman Lebedev [Tue, 25 Feb 2020 18:53:12 +0000 (21:53 +0300)]
[SCEV][IndVars] Always provide insertion point to the SCEVExpander::isHighCostExpansion()

Summary: This addresses the `llvm/test/Transforms/IndVarSimplify/elim-extend.ll` `@nestedIV` regression from D73728

Reviewers: reames, mkazantsev, wmi, sanjoy

Reviewed By: mkazantsev

Subscribers: hiraditya, llvm-commits

Tags: #llvm

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

4 years ago[SCEV] rewriteLoopExitValues(): even if have hard uses, still rewrite if cheap (PR44668)
Roman Lebedev [Tue, 25 Feb 2020 18:53:00 +0000 (21:53 +0300)]
[SCEV] rewriteLoopExitValues(): even if have hard uses, still rewrite if cheap (PR44668)

Summary:
Replacing uses of IV outside of the loop is likely generally useful,
but `rewriteLoopExitValues()` is cautious, and if it isn't told to always
perform the replacement, and there are hard uses of IV in loop,
it doesn't replace.

In [[ https://bugs.llvm.org/show_bug.cgi?id=44668 | PR44668 ]],
that prevents `-indvars` from replacing uses of induction variable
after the loop, which might be one of the optimization failures
preventing that code from being vectorized.

Instead, now that the cost model is fixed, i believe we should be
a little bit more optimistic, and also perform replacement
if we believe it is within our budget.

Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=44668 | PR44668 ]].

Reviewers: reames, mkazantsev, asbirlea, fhahn, skatkov

Reviewed By: mkazantsev

Subscribers: nikic, hiraditya, zzheng, javed.absar, dmgreen, llvm-commits

Tags: #llvm

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

4 years ago[SCEV] SCEVExpander::isHighCostExpansionHelper(): cost-model min/max (PR44668)
Roman Lebedev [Tue, 25 Feb 2020 18:52:46 +0000 (21:52 +0300)]
[SCEV] SCEVExpander::isHighCostExpansionHelper(): cost-model min/max (PR44668)

Summary:
Previosly we simply always said that `SCEVMinMaxExpr` is too costly to expand.
But this isn't really true, it expands into just a comparison+swap pair.
And again much like with add/mul, there will be one less such pair
than the number of operands. And we need to count the cost of operands themselves.

This does change a number of testcases, and as far as i can tell,
all of these changes are improvements, in the sense that
we fixed up more latches to do the [in]equality comparison.

This concludes cost-modelling changes, no other SCEV expressions exist as of now.

This is a part of addressing [[ https://bugs.llvm.org/show_bug.cgi?id=44668 | PR44668 ]].

Reviewers: reames, mkazantsev, wmi, sanjoy

Reviewed By: mkazantsev

Subscribers: hiraditya, javed.absar, llvm-commits

Tags: #llvm

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

4 years ago[SCEV] SCEVExpander::isHighCostExpansionHelper(): cost-model polynomial recurrence
Roman Lebedev [Tue, 25 Feb 2020 18:52:32 +0000 (21:52 +0300)]
[SCEV] SCEVExpander::isHighCostExpansionHelper(): cost-model polynomial recurrence

Summary:
So, i wouldn't call this *obviously* correct,
but i think i got it right this time :)

Roughly, we have
```
Op0*x^0 + Op1*x^1 + Op2*x^2 ...
```
where `Op_{n} * x^{n}` is called term, and `n` the degree of term.

Due to the way they are stored internally in `SCEVAddRecExpr`,
i believe we can have `Op_{n}` to be `0`, so we should not charge for those.

I think it is most straight-forward to count the cost in 4 steps:
1. First, count it the same way we counted `scAddExpr`, but be sure to skip terms with zero constants.
   Much like with `add` expr we will have one less addition than number of terms.
2. Each non-constant term (term degree >= 1) requires a multiplication between the `Op_{n}` and `x^{n}`.
   But again, only charge for it if it is required - `Op_{n}` must not be 0 (no term) or 1 (no multiplication needed),
   and obviously don't charge constant terms (`x^0 == 1`).
3. We must charge for all the `x^0`..`x^{poly_degree}` themselves.
   Since `x^{poly_degree}` is `x * x * ...  * x`, i.e. `poly_degree` `x`'es multiplied,
   for final `poly_degree` term we again require `poly_degree-1` multiplications.
   Note that all the `x^{0}`..`x^{poly_degree-1}` will be computed for the free along the way there.
4. And finally, the operands themselves.

Here, much like with add/mul exprs, we really don't look for preexisting instructions..

Reviewers: reames, mkazantsev, wmi, sanjoy

Reviewed By: mkazantsev

Subscribers: hiraditya, javed.absar, llvm-commits

Tags: #llvm

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

4 years ago[SCEV] SCEVExpander::isHighCostExpansionHelper(): cost-model add/mul
Roman Lebedev [Tue, 25 Feb 2020 18:52:19 +0000 (21:52 +0300)]
[SCEV] SCEVExpander::isHighCostExpansionHelper(): cost-model add/mul

Summary:
While this resolves the regression from D73722 in `llvm/test/Transforms/IndVarSimplify/exit_value_test2.ll`,
this now regresses `llvm/test/Transforms/IndVarSimplify/elim-extend.ll` `@nestedIV` test,
we no longer can perform that expansion within default budget of `4`, but require budget of `6`.
That regression is being addressed by D73777.

The basic idea here is simple.
```
Op0,  Op1, Op2 ...
 |     |    |
 \--+--/    |
    |       |
    \---+---/
```
I.e. given N operands, we will have N-1 operations,
so we have to add cost of an add (mul) for **every** Op processed,
**except** the first one, plus we need to recurse into *every* Op.

I'm guessing there's already canonicalization that ensures we won't
have `1` operand in `scMulExpr`, and no `0` in `scAddExpr`/`scMulExpr`.

Reviewers: reames, mkazantsev, wmi, sanjoy

Reviewed By: mkazantsev

Subscribers: hiraditya, llvm-commits

Tags: #llvm

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

4 years ago[SCEV] SCEVExpander::isHighCostExpansionHelper(): cost-model plain UDiv
Roman Lebedev [Tue, 25 Feb 2020 18:52:07 +0000 (21:52 +0300)]
[SCEV] SCEVExpander::isHighCostExpansionHelper(): cost-model plain UDiv

Summary:
If we don't believe this UDiv is actually a LShr in disguise, things are much worse.
First, we try to see if this UDiv actually originates from user code,
by looking for `S + 1`, and if found considering this UDiv to be free.
But otherwise, we always considered this UDiv to be high-cost.

However that is no longer the case with TTI-driven cost model:
our default budget is 4, which matches the default cost of UDiv,
so now we allow a single UDiv to not be counted as high-cost.

While that is the case, it is evident this is actually a regression
due to the fact that cost-modelling is incomplete - we did not account
for the `add`, `mul` costs yet. That is being addressed in D73728.

Cost-modelling for UDiv also seems pretty straight-forward:
subtract cost of the UDiv itself, and recurse into both the LHS and RHS.

Reviewers: reames, mkazantsev, wmi, sanjoy

Reviewed By: mkazantsev

Subscribers: hiraditya, llvm-commits

Tags: #llvm

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

4 years ago[NFC][IndVarSimplify] Adjust value names in IndVarSimplify/exit_value_test2.ll
Roman Lebedev [Tue, 25 Feb 2020 19:16:29 +0000 (22:16 +0300)]
[NFC][IndVarSimplify] Adjust value names in IndVarSimplify/exit_value_test2.ll

%tmp prefix confuses auto-update scripts

4 years ago[SCEV] SCEVExpander::isHighCostExpansionHelper(): cost-model UDiv by power-of-two...
Roman Lebedev [Tue, 25 Feb 2020 18:51:22 +0000 (21:51 +0300)]
[SCEV] SCEVExpander::isHighCostExpansionHelper(): cost-model UDiv by power-of-two as LShr

Summary:
Like with casts, we need to subtract the cost of `lshr` instruction
from budget, and recurse into LHS operand.
Seems "pretty obviously correct" to me?

To be noted, there is a number of other shortcuts we //could// cost-model:
* `... + (-1 * ...)` -> `... - ...` <-  likely very frequent case
* `x - (rem x, power-of-2)`, which is currently `(x udiv power-of-2) * power-of-2` -> `x & -log2(power-of-2)`
* `rem x, power-of-2`, which is currently `x - ((x udiv power-of-2) * power-of-2)` -> `x & log2(power-of-2)-1`
* `... * power-of-2` -> `... << log2(power-of-2)` <- likely not very beneficial

Reviewers: reames, mkazantsev, wmi, sanjoy

Reviewed By: mkazantsev

Subscribers: hiraditya, llvm-commits

Tags: #llvm

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

4 years ago[SCEV] SCEVExpander::isHighCostExpansionHelper(): begin cost modelling - model cast...
Roman Lebedev [Tue, 25 Feb 2020 18:51:16 +0000 (21:51 +0300)]
[SCEV] SCEVExpander::isHighCostExpansionHelper(): begin cost modelling - model cast cost

Summary:
This is not a NFC, although it does not change any of the existing tests.
I'm not really sure if we should have specific tests for the cost modelling itself.

This is the first patch that actually makes `SCEVExpander::isHighCostExpansionHelper()`
account for the cost of the SCEV expression, and consider the budget available,
by modelling cast expressions.

I believe the logic itself is "pretty obviously correct" - from budget,
we need to subtract the cost of the cast expression from inner type `Op->getType()`
to the `S->getType()` type, and recurse into the expression we are casting.

Reviewers: reames, mkazantsev, wmi, sanjoy

Reviewed By: mkazantsev

Subscribers: xbolva00, hiraditya, javed.absar, llvm-commits

Tags: #llvm

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

4 years ago[SCEV] SCEVExpander::isHighCostExpansion(): assert if TTI is not provided
Roman Lebedev [Tue, 25 Feb 2020 18:51:12 +0000 (21:51 +0300)]
[SCEV] SCEVExpander::isHighCostExpansion(): assert if TTI is not provided

Summary:
Currently, as per `check-llvm`, we never call `SCEVExpander::isHighCostExpansion()` with null TTI,
so this appears to be a safe restriction.

Reviewers: reames, mkazantsev, wmi, sanjoy

Reviewed By: mkazantsev

Subscribers: javed.absar, hiraditya, llvm-commits

Tags: #llvm

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

4 years ago[NFC][SCEV] SCEVExpander::isHighCostExpansionHelper(): check that we processed expres...
Roman Lebedev [Tue, 25 Feb 2020 18:51:06 +0000 (21:51 +0300)]
[NFC][SCEV] SCEVExpander::isHighCostExpansionHelper(): check that we processed expression first

Summary:
As far as i can tell this is still NFC.
Initially in rL146438 it was added at the top of the function,
later rL238507 dethroned it, and rL244474 did it again.

I'm not sure if we have already checked the cost of this expansion, we should be doing that again.

Reviewers: reames, mkazantsev, wmi, sanjoy, atrick, igor-laevsky

Reviewed By: mkazantsev

Subscribers: hiraditya, llvm-commits

Tags: #llvm

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

4 years ago[NFC][SCEV] Piping to pass new SCEVCheapExpansionBudget option into SCEVExpander...
Roman Lebedev [Tue, 25 Feb 2020 18:51:02 +0000 (21:51 +0300)]
[NFC][SCEV] Piping to pass new SCEVCheapExpansionBudget option into SCEVExpander::isHighCostExpansionHelper()

Summary:
In future patches`SCEVExpander::isHighCostExpansionHelper()` will respect the budget allocated by performing TTI cost modelling.
This is a fully NFC patch to make things reviewable.

Reviewers: reames, mkazantsev, wmi, sanjoy

Reviewed By: mkazantsev

Subscribers: hiraditya, zzheng, javed.absar, llvm-commits

Tags: #llvm

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

4 years ago[NFC][SCEV] Piping to pass TTI into SCEVExpander::isHighCostExpansionHelper()
Roman Lebedev [Tue, 25 Feb 2020 18:50:55 +0000 (21:50 +0300)]
[NFC][SCEV] Piping to pass TTI into SCEVExpander::isHighCostExpansionHelper()

Summary:
Future patches will make use of TTI to perform cost-model-driven `SCEVExpander::isHighCostExpansionHelper()`
This is a fully NFC patch to make things reviewable.

Reviewers: reames, mkazantsev, wmi, sanjoy

Reviewed By: mkazantsev

Subscribers: hiraditya, zzheng, javed.absar, dmgreen, llvm-commits

Tags: #llvm

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

4 years agoAdd 'l' constraint to goto label reference
Bill Wendling [Tue, 25 Feb 2020 19:45:56 +0000 (11:45 -0800)]
Add 'l' constraint to goto label reference

A goto label uses the 'l' constraint, skipping it can cause unexpected
warnings.

4 years ago[libcxx] Fix building for windows after 54fa9ecd3088508
Martin Storsjö [Tue, 25 Feb 2020 07:36:24 +0000 (09:36 +0200)]
[libcxx] Fix building for windows after 54fa9ecd3088508

Move the implementation of __libcpp_thread_poll_with_backoff
and __libcpp_timed_backoff_policy::operator() out of the
_LIBCPP_HAS_THREAD_API_PTHREAD block. None of the code in these
methods is pthreads specific.

Also add "inline _LIBCPP_INLINE_VISIBILITY" to
__libcpp_timed_backoff_policy::operator(), to avoid errors due to
multiple definitions of the operator. Contrary to
__libcpp_thread_poll_with_backoff (which is a template function),
this is a normal non-templated method.

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

4 years ago[PhaseOrdering] add tests for missed CSE; NFC
Sanjay Patel [Tue, 25 Feb 2020 19:23:03 +0000 (14:23 -0500)]
[PhaseOrdering] add tests for missed CSE; NFC

Also add a RUN line for the new pass manager.

4 years agoFix a race between lldb's packet timeout and the profile thread's usleep.
Jim Ingham [Sat, 22 Feb 2020 00:45:29 +0000 (16:45 -0800)]
Fix a race between lldb's packet timeout and the profile thread's usleep.

The debugserver profile thread used to suspend itself between samples with
a usleep.  When you detach or kill, MachProcess::Clear would delay replying
to the incoming packet until pthread_join of the profile thread returned.
If you are unlucky or the suspend delay is long, it could take longer than
the packet timeout for pthread_join to return.  Then you would get an error
about detach not succeeding from lldb - even though in fact the detach was
successful...

I replaced the usleep with PThreadEvents entity.  Then we just call a timed
WaitForEventBits, and when debugserver wants to stop the profile thread, it
can set the event bit, and the sleep will exit immediately.

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

4 years ago[AMDGPU] Implement wave64 DWARF register mapping
Scott Linder [Fri, 8 Nov 2019 20:07:54 +0000 (15:07 -0500)]
[AMDGPU] Implement wave64 DWARF register mapping

Summary:
Implement the DWARF register mapping described in
llvm/docs/AMDGPUUsage.rst

This is currently limited to wave64 VGPRs/AGPRs.

This also includes some minor changes in AMDGPUInstPrinter,
AMDGPUMCTargetDesc, and AMDGPUAsmParser to make generating CFI assembly
text and ELF sections possible to ease testing, although complete CFI
support is not yet implemented.

Tags: #llvm

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

4 years agoSupport emitting .cfi_undefined in CodeGen
Scott Linder [Tue, 25 Feb 2020 14:03:11 +0000 (09:03 -0500)]
Support emitting .cfi_undefined in CodeGen

This will be used by AMDGPU.

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

4 years agoEmit register names in cfi assembly directives
Scott Linder [Tue, 25 Feb 2020 14:01:26 +0000 (09:01 -0500)]
Emit register names in cfi assembly directives

Update .cfi_undefined, .cfi_register, and .cfi_return_column to
print symbolic register arguments.

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

4 years agoMake __builtin_amdgcn_dispatch_ptr dereferenceable and align at 4
Yaxun (Sam) Liu [Fri, 21 Feb 2020 00:02:53 +0000 (19:02 -0500)]
Make __builtin_amdgcn_dispatch_ptr dereferenceable and align at 4

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

4 years ago[X86MCTargetDesc.h] Speculative fix for macro collision with sys/param.h
Vedant Kumar [Tue, 25 Feb 2020 18:49:53 +0000 (10:49 -0800)]
[X86MCTargetDesc.h] Speculative fix for macro collision with sys/param.h

See discussion on https://reviews.llvm.org/D75091 for information about
the build failure and alternatives considered.

4 years ago[MachineInstr] Add a dumpr method
Quentin Colombet [Tue, 25 Feb 2020 01:30:58 +0000 (17:30 -0800)]
[MachineInstr] Add a dumpr method

Add a dump method that recursively prints an instruction and all
the instructions defining its operands and so on.

This is helpful when looking at combiner issue.

NFC

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

4 years ago[PowerPC][NFC] Remove comments mentioning Darwin and VRSAVE from lit test.
Sean Fertile [Tue, 25 Feb 2020 17:41:31 +0000 (12:41 -0500)]
[PowerPC][NFC] Remove comments mentioning Darwin and VRSAVE from lit test.

4 years ago[Codegen] Revert rL354676/rL354677 and followups - introduced PR43446 miscompile
Roman Lebedev [Tue, 25 Feb 2020 17:08:58 +0000 (20:08 +0300)]
[Codegen] Revert rL354676/rL354677 and followups - introduced PR43446 miscompile

This reverts https://reviews.llvm.org/D58468
(rL354676, 44037d7a6377ec8e5542cced73583283334b516b),
and all and any follow-ups to that code block.

https://bugs.llvm.org/show_bug.cgi?id=43446

4 years ago[NFC][Codegen] Add miscompile test for constant store merging from PR43446
Roman Lebedev [Tue, 25 Feb 2020 17:07:15 +0000 (20:07 +0300)]
[NFC][Codegen] Add miscompile test for constant store merging from PR43446

This miscompile was introduced by rL354676 / https://reviews.llvm.org/D58468

https://bugs.llvm.org/show_bug.cgi?id=43446

4 years ago[libc++] Remove incorrect XFAIL in modules test
Louis Dionne [Tue, 25 Feb 2020 17:10:28 +0000 (12:10 -0500)]
[libc++] Remove incorrect XFAIL in modules test

Apparently, the test still works on single-threaded systems.

4 years agoRevert "[LICM] Support hosting of dynamic allocas out of loops"
Philip Reames [Tue, 25 Feb 2020 16:56:53 +0000 (08:56 -0800)]
Revert "[LICM] Support hosting of dynamic allocas out of loops"

This reverts commit 8d22100f66c4170510c6ff028c60672acfe1cff9.

There was a functional regression reported (https://bugs.llvm.org/show_bug.cgi?id=44996).  I'm not actually sure the patch is wrong, but I don't have time to investigate currently, and this line of work isn't something I'm likely to get back to quickly.

4 years agoRevert "[DWARFDebugLine] Avoid dumping prologue members we did not parse"
Pavel Labath [Tue, 25 Feb 2020 16:57:36 +0000 (17:57 +0100)]
Revert "[DWARFDebugLine] Avoid dumping prologue members we did not parse"

The changed test started failing on the windows bots. Reverting while I
investigate.

This reverts commit deb116ee0a5b80f61bc341ed68606dc5ad093569.

4 years agoAMDGPU/GlobalISel: Un-XFAIL a test
Jay Foad [Tue, 25 Feb 2020 16:45:14 +0000 (16:45 +0000)]
AMDGPU/GlobalISel: Un-XFAIL a test

This was missed in 12fe9b26ec88bb2dd40d574a644edca302e804b2

4 years ago[libc++] Revert 03dd205c151 "Adjust max_align_t handling"
Louis Dionne [Tue, 25 Feb 2020 16:42:08 +0000 (11:42 -0500)]
[libc++] Revert 03dd205c151 "Adjust max_align_t handling"

That commit was made without approval from a libc++ reviewer, and it
also broke the build in C++03 mode.

4 years ago[libc++] Proper fix for libc++'s modulemap after D68480
Louis Dionne [Mon, 24 Feb 2020 23:12:44 +0000 (18:12 -0500)]
[libc++] Proper fix for libc++'s modulemap after D68480

Summary:
In libc++, we normally #ifdef out header content instead of #erroring
out when the Standard in use is insufficient for the requirements of
the header.

Reviewers: EricWF

Subscribers: jkorous, dexonsmith, libcxx-commits, teemperor

Tags: #libc

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

4 years agoAMDGPU/GlobalISel: Use packed for G_ADD/G_SUB/G_MUL v2s16
Matt Arsenault [Tue, 18 Feb 2020 03:10:27 +0000 (22:10 -0500)]
AMDGPU/GlobalISel: Use packed for G_ADD/G_SUB/G_MUL v2s16

4 years ago[remark][diagnostics] [codegen] Fix PR44896
Rong Xu [Tue, 25 Feb 2020 16:04:01 +0000 (08:04 -0800)]
[remark][diagnostics] [codegen] Fix PR44896

This patch fixes PR44896. For IR input files, option fdiscard-value-names
should be ignored as we need named values in loadModule().
Commit 60d3947922 sets this option after loadModule() where valued names
already created. This creates an inconsistent state in setNameImpl()
that leads to a seg fault.
This patch forces fdiscard-value-names to be false for IR input files.

This patch also emits a warning of "ignoring -fdiscard-value-names" if
option fdiscard-value-names is explictly enabled in the commandline for
IR input files.

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

4 years ago[Sema][C++] Propagate conversion kind to specialize the diagnostics
Anastasia Stulova [Tue, 25 Feb 2020 14:49:59 +0000 (14:49 +0000)]
[Sema][C++] Propagate conversion kind to specialize the diagnostics

Compute and propagate conversion kind to diagnostics helper in C++
to provide more specific diagnostics about incorrect implicit
conversions in assignments, initializations, params, etc...

Duplicated some diagnostics as errors because C++ is more strict.

Tags: #clang

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

4 years agoMake builtbot happy.
Haojian Wu [Tue, 25 Feb 2020 16:02:08 +0000 (17:02 +0100)]
Make builtbot happy.

Disable the failing rename test, it should not be failed, needs further
investigation.

4 years agoAMDGPU/GlobalISel: Legalize s64 min/max by lowering
Jay Foad [Tue, 25 Feb 2020 10:31:37 +0000 (10:31 +0000)]
AMDGPU/GlobalISel: Legalize s64 min/max by lowering

Reviewers: arsenm, rampitec

Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits

Tags: #llvm

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

4 years ago[ELF] Support archive:file syntax in input section descriptions
Fangrui Song [Tue, 25 Feb 2020 05:52:47 +0000 (21:52 -0800)]
[ELF] Support archive:file syntax in input section descriptions

Fixes https://bugs.llvm.org/show_bug.cgi?id=44450

https://sourceware.org/binutils/docs/ld/Input-Section-Basics.html#Input-Section-Basics
The following two rules are not implemented.

* `archive:` matches every file in the archive.
* `:file` matches a file not in an archive.

Reviewed By: grimar, ruiu

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

4 years ago[clang-rename] Add the USR of incomplete decl to the USRSet.
Haojian Wu [Tue, 25 Feb 2020 15:32:22 +0000 (16:32 +0100)]
[clang-rename] Add the USR of incomplete decl to the USRSet.

Summary:
This fixes a clangd rename issue, which is missing the reference of
an incomplete specialization.

Unfortunately, I didn't reproduce this issue in clang-rename, I guess
the input `FoundDecl` of AdditionalUSRFinder is different in clangd vs
clang-rename, clang-rename uses the underlying CXXRecordDecl of the
ClassTemplateDecl, which is fixed in https://github.com/llvm/llvm-project/commit/5d862c042b52ae2aad37471d0b83b6c678a520e3;
while clangd-rename uses the ClassTemplateDecl.

Reviewers: kbobyrev

Reviewed By: kbobyrev

Subscribers: ilya-biryukov, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

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

4 years ago[analyzer] Add support for CXXInheritedCtorInitExpr.
Artem Dergachev [Mon, 17 Feb 2020 18:42:50 +0000 (21:42 +0300)]
[analyzer] Add support for CXXInheritedCtorInitExpr.

So far we've been dropping coverage every time we've encountered
a CXXInheritedCtorInitExpr. This patch attempts to add some
initial support for it.

Constructors for arguments of a CXXInheritedCtorInitExpr are still
not fully supported.

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

4 years ago[DWARFDebugLine] Avoid dumping prologue members we did not parse
Pavel Labath [Mon, 24 Feb 2020 12:32:31 +0000 (13:32 +0100)]
[DWARFDebugLine] Avoid dumping prologue members we did not parse

Summary:
This patch if motivated by D74560, specifically the subthread about what
to print upon encountering reserved initial length values.

If the debug_line prologue has an unsupported version, we skip parsing
the rest of the data. If we encounter an reserved initial length field,
we don't even parse the version. However, we still print out all members
(with value 0) in the dump function.

This patch introduces early exits in the Prologue::dump function so that
we print only the fields that were parsed successfully. In case of an
unsupported version, we skip printing all subsequent prologue fields --
because we don't even know if this version has those fields. In case of a
reserved unit length, we don't print anything -- if the very first field
of the prologue is invalid, it's hard to say if we even have a prologue
to begin with.

Note that the user will still be able to see the invalid/reserved
initial length value in the error message. I've modified (reordered)
debug_line_invalid.test to show that the error message comes straight
after the debug_line offset. I've also added some flush() calls to the
dumping code to ensure this is the case in all situations (without that,
the warnings could get out of sync if the output was not a terminal -- I
guess this is why std::iostreams have the tie() function).

Reviewers: jhenderson, ikudrin, dblaikie

Subscribers: hiraditya, llvm-commits

Tags: #llvm

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

4 years ago[LLDB] Let DataExtractor deal with two-byte addresses
Ayke van Laethem [Tue, 4 Feb 2020 15:29:01 +0000 (16:29 +0100)]
[LLDB] Let DataExtractor deal with two-byte addresses

AVR usually uses two byte addresses. By making DataExtractor deal with
this, it is possible to load AVR binaries that don't have debug info
associated with them.

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

4 years ago[InstCombine] foldShiftIntoShiftInAnotherHandOfAndInICmp(): fix miscompile (PR44802)
Roman Lebedev [Tue, 25 Feb 2020 14:24:27 +0000 (17:24 +0300)]
[InstCombine] foldShiftIntoShiftInAnotherHandOfAndInICmp(): fix miscompile (PR44802)

Much like with reassociateShiftAmtsOfTwoSameDirectionShifts(),
as input, we have the following pattern:
  icmp eq/ne (and ((x shift Q), (y oppositeshift K))), 0
We want to rewrite that as:
  icmp eq/ne (and (x shift (Q+K)), y), 0  iff (Q+K) u< bitwidth(x)

While we know that originally (Q+K) would not overflow
(because  2 * (N-1) u<= iN -1), we may have looked past extensions of
shift amounts. so it may now overflow in smaller bitwidth.

To ensure that does not happen, we need to ensure that the total maximal
shift amount is still representable in that smaller bitwidth.
If the overflow would happen, (Q+K) u< bitwidth(x) check would be bogus.

https://bugs.llvm.org/show_bug.cgi?id=44802

4 years ago[NFC][InstCombine] Add shift amount reassociation in bittest miscompile example from...
Roman Lebedev [Tue, 25 Feb 2020 14:14:43 +0000 (17:14 +0300)]
[NFC][InstCombine] Add shift amount reassociation in bittest miscompile example from PR44802

https://bugs.llvm.org/show_bug.cgi?id=44802

4 years ago[InstCombine] reassociateShiftAmtsOfTwoSameDirectionShifts(): fix miscompile (PR44802)
Roman Lebedev [Tue, 25 Feb 2020 13:48:36 +0000 (16:48 +0300)]
[InstCombine] reassociateShiftAmtsOfTwoSameDirectionShifts(): fix miscompile (PR44802)

As input, we have the following pattern:
  Sh0 (Sh1 X, Q), K
We want to rewrite that as:
  Sh x, (Q+K)  iff (Q+K) u< bitwidth(x)
While we know that originally (Q+K) would not overflow
(because  2 * (N-1) u<= iN -1), we may have looked past extensions of
shift amounts. so it may now overflow in smaller bitwidth.

To ensure that does not happen, we need to ensure that the total maximal
shift amount is still representable in that smaller bitwidth.
If the overflow would happen, (Q+K) u< bitwidth(x) check would be bogus.

https://bugs.llvm.org/show_bug.cgi?id=44802

4 years ago[NFC][InstCombine] Add shift amount reassociation miscompile example from PR44802
Roman Lebedev [Tue, 25 Feb 2020 13:06:13 +0000 (16:06 +0300)]
[NFC][InstCombine] Add shift amount reassociation miscompile example from PR44802

https://bugs.llvm.org/show_bug.cgi?id=44802

4 years agoMake test not write to the source directory
Benjamin Kramer [Tue, 25 Feb 2020 15:03:06 +0000 (16:03 +0100)]
Make test not write to the source directory

4 years ago[AMDGPU] Precommit some test updates for D68338 "Remove dubious logic in bidirectiona...
Jay Foad [Tue, 25 Feb 2020 14:38:57 +0000 (14:38 +0000)]
[AMDGPU] Precommit some test updates for D68338 "Remove dubious logic in bidirectional list scheduler"

4 years agoclang-cl: Add a `/showIncludes:user` flag.
Nico Weber [Mon, 24 Feb 2020 21:07:16 +0000 (16:07 -0500)]
clang-cl: Add a `/showIncludes:user` flag.

This flag is like /showIncludes, but it only includes user headers and
omits system headers (similar to MD and MMD). The motivation is that
projects that already track system includes though other means can use
this flag to get consistent behavior on Windows and non-Windows, and it
saves tools that output /showIncludes output (e.g. ninja) some work.

implementation-wise, this makes `HeaderIncludesCallback` honor the
existing `IncludeSystemHeaders` bit, and changes the three clients of
`HeaderIncludesCallback` (`/showIncludes`, `-H`, `CC_PRINT_HEADERS=1`)
to pass `-sys-header-deps` to set that bit -- except for
`/showIncludes:user`, which doesn't pass it.

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

4 years ago[analyzer][MallocChecker][NFC] Change the use of IdentifierInfo* to CallDescription
Kristóf Umann [Fri, 20 Sep 2019 09:01:45 +0000 (11:01 +0200)]
[analyzer][MallocChecker][NFC] Change the use of IdentifierInfo* to CallDescription

Exactly what it says on the tin! I decided not to merge this with the patch that
changes all these to a CallDescriptionMap object, so the patch is that much more
trivial.

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

4 years ago[clangd] Migrate Lexer usages in TypeHierarchy to TokenBuffers
Kadir Cetinkaya [Wed, 19 Feb 2020 18:11:01 +0000 (19:11 +0100)]
[clangd] Migrate Lexer usages in TypeHierarchy to TokenBuffers

Summary:
Also fixes a bug, resulting from directly using ND.getEndLoc() for end
location of the range. As ND.getEndLoc() points to the begining of the last
token, whereas it should point one past the end, since LSP ranges are half open
(exclusive on the end).

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

4 years agoStop including sys/param.h from Unix.h
Joerg Sonnenberger [Tue, 25 Feb 2020 14:22:18 +0000 (15:22 +0100)]
Stop including sys/param.h from Unix.h

4 years ago[OpenMP][cmake] ignore warning on unknown CUDA version
Kelvin Li [Mon, 24 Feb 2020 21:11:05 +0000 (16:11 -0500)]
[OpenMP][cmake] ignore warning on unknown CUDA version

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

4 years ago[clang-format] Wrap lines for C# property accessors
Jonathan Coe [Tue, 25 Feb 2020 13:59:52 +0000 (13:59 +0000)]
[clang-format]  Wrap lines for C# property accessors

Summary: Ensure that auto-implemented properties `{ get; private set }` are wrapped on to one line for C# code.

Reviewers: MyDeveloperDay, krasimir

Reviewed By: MyDeveloperDay, krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

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

4 years agoFix DfaEmitter::visitDfaState() crash in MSVC x86 debug builds (PR44945)
Hans Wennborg [Tue, 25 Feb 2020 14:15:25 +0000 (15:15 +0100)]
Fix DfaEmitter::visitDfaState() crash in MSVC x86 debug builds (PR44945)

No functionality change (intended), but this seems to make the code a
bit clearer for the compiler and maybe for human readers too.

4 years ago[RISCV] Fix sysroot tests without GCC on RISC-V hosts with GCC
Luís Marques [Tue, 25 Feb 2020 14:15:16 +0000 (14:15 +0000)]
[RISCV] Fix sysroot tests without GCC on RISC-V hosts with GCC

D68391 added tests that check scenarios where no RISC-V GCC toolchain is
supposed to be detected. When running the tests on RISC-V hosts the system's
GCC toolchain will be detected, and the tests will fail. This patch adds a
`--gcc-toolchain` option pointing to a path where no GCC toolchain is
present, ensuring that the tests are run under the expected conditions, and
therefore are able to pass in all test environments.

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

4 years ago[mlir] NFC: update documentation in ConvertLinalgToLLVM
Alex Zinenko [Tue, 25 Feb 2020 14:14:59 +0000 (15:14 +0100)]
[mlir] NFC: update documentation in ConvertLinalgToLLVM

The documentation was describing an obsolete version of the
transformation.

4 years ago[CodeGen] fix clang test that runs the optimizer pipeline; NFC
Sanjay Patel [Tue, 25 Feb 2020 14:12:12 +0000 (09:12 -0500)]
[CodeGen] fix clang test that runs the optimizer pipeline; NFC

There's already a FIXME note on this file; it can break when the
underlying LLVM behavior changes independently of anything in clang.

4 years ago[PhaseOrdering] add test for missing vector/CSE transforms (PR45015); NFC
Sanjay Patel [Tue, 25 Feb 2020 13:54:58 +0000 (08:54 -0500)]
[PhaseOrdering] add test for missing vector/CSE transforms (PR45015); NFC

4 years ago[Analyzer] Fix for iterator modeling and checkers: handle negative numbers correctly
Adam Balogh [Tue, 18 Feb 2020 10:22:08 +0000 (11:22 +0100)]
[Analyzer] Fix for iterator modeling and checkers: handle negative numbers correctly

Currently, using negative numbers in iterator operations (additions and
subractions) results in advancements with huge positive numbers due to
an error. This patch fixes it.

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

4 years ago[ASTImporter] Improved variable template redecl chain handling.
Balázs Kéri [Tue, 25 Feb 2020 13:47:38 +0000 (14:47 +0100)]
[ASTImporter] Improved variable template redecl chain handling.

Reviewers: martong, a.sidorin, shafik

Reviewed By: martong

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, teemperor, cfe-commits

Tags: #clang

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

4 years ago[VectorCombine] add tests for possible extract->shuffle; NFC
Sanjay Patel [Mon, 24 Feb 2020 22:16:57 +0000 (17:16 -0500)]
[VectorCombine] add tests for possible extract->shuffle; NFC

4 years ago[VectorCombine] make cost calc consistent for binops and cmps
Sanjay Patel [Mon, 24 Feb 2020 22:05:44 +0000 (17:05 -0500)]
[VectorCombine] make cost calc consistent for binops and cmps

Code duplication (subsequently removed by refactoring) allowed
a logic discrepancy to creep in here.

We were being conservative about creating a vector binop -- but
not a vector cmp -- in the case where a vector op has the same
estimated cost as the scalar op. We want to be more aggressive
here because that can allow other combines based on reduced
instruction count/uses.

We can reverse the transform in DAGCombiner (potentially with a
more accurate cost model) if this causes regressions.

AFAIK, this does not conflict with InstCombine. We have a
scalarize transform there, but it relies on finding a constant
operand or a matching insertelement, so that means it eliminates
an extractelement from the sequence (so we won't have 2 extracts
by the time we get here if InstCombine succeeds).

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

4 years ago[DSE,MSSA] Do not attempt to remove un-removable memdefs.
Florian Hahn [Tue, 25 Feb 2020 13:27:22 +0000 (13:27 +0000)]
[DSE,MSSA] Do not attempt to remove un-removable memdefs.

We have to skip MemoryDefs that cannot be removed. This fixes a crash in
the newly added test case and fixes a wrong case in
memset-and-memcpy.ll.

4 years ago[MLIR][GPU] Properly model step in parallel loop to gpu conversion.
Stephan Herhut [Mon, 24 Feb 2020 15:02:50 +0000 (16:02 +0100)]
[MLIR][GPU] Properly model step in parallel loop to gpu conversion.

Summary:
The original patch had TODOs to add support for step computations,
which this commit addresses. The computations are expressed using
affine expressions so that the affine canonicalizers can simplify
the full bound and index computations.

Also cleans up the code a little and exposes the pass in the
header file.

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

4 years ago[mlir] NFC: move AffineOps tests from test/ to test/Dialect
Alex Zinenko [Tue, 25 Feb 2020 13:18:12 +0000 (14:18 +0100)]
[mlir] NFC: move AffineOps tests from test/ to test/Dialect

AffineOps dialect lives under lib/Dialect/AffineOps and so should its
tests.

4 years ago[debuginfo-tests] Warn, not error, if we can't delete working directory
Jeremy Morse [Tue, 25 Feb 2020 13:12:13 +0000 (13:12 +0000)]
[debuginfo-tests] Warn, not error, if we can't delete working directory

On Windows, an error running the debugger typically leaves a process
hanging around in the working directory. When Dexter exits, it can't then
delete the working directory and produces an exception, masking the problem
in the debugger. (This can be worked around by specifying --save-temps).
Rather than hard-erroring, print a warning when we can't delete the working
directory instead.

It'd be much better to improve our error handling, and make the
WorkingDirectory class aware that something's wrong when it enters exit.
However, this is something that's going to mask genuine errors and make
everyones lives harder right now, so I think this non-ideal fix is
important to get in first.

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

4 years ago[lldb][NFC] Move filling namespace map in ClangASTSource to own function
Raphael Isemann [Tue, 25 Feb 2020 12:43:11 +0000 (13:43 +0100)]
[lldb][NFC] Move filling namespace map in ClangASTSource to own function