35 Commits

Author SHA1 Message Date
Sam Parker
c78c8e252f [ARM] Negative constants mishandled in ARM CGP
During type promotion, sometimes we convert negative an add with a
negative constant into a sub with a positive constant. The loop that
performs this transformation has two issues:
- it iterates over a set, causing non-determinism.
- it breaks, instead of continuing, when it finds the first
  non-negative operand.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354557 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-21 09:33:18 +00:00
Sam Parker
52cd80dbc1 [ARM CGP] Fix ConvertTruncs
ConvertTruncs is used to replace a trunc for an AND mask, however
this function wasn't working as expected. By performing the change
later, we can create a wide type integer mask instead of a narrow -1
value, which could then be simply removed (incorrectly). Because we
now perform this action later, it's necessary to cache the trunc type
before we perform the promotion.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354108 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-15 09:04:39 +00:00
Sam Parker
1bba626c44 [ARM][CGP] Check trunc type before replacing
In the last stage of type promotion, we replace any zext that uses a
new trunc with the operand of the trunc. This is okay when we only
allowed one type to be optimised, but now its the case that the trunc
maybe needed to produce a more narrow type than the one we were
optimising for. So we need to check this before doing the replacement.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351935 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-23 09:18:44 +00:00
Chandler Carruth
6b547686c5 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-19 08:50:56 +00:00
Sam Parker
1412721733 [ARM] Remove trunc sinks in ARM CGP
Truncs are treated as sources if their produce a value of the same
type as the one we currently trying to promote. Truncs used to be
considered as a sink if their operand was the same value type.
    
We now allow smaller types in the search, so we should search through
truncs that produce a smaller value. These truncs can then be
converted to an AND mask.
    
This leaves sinks as being:
  - points where the value in the register is being observed, such as
    an icmp, switch or store.
  - points where value types have to match, such as calls and returns.
  - zext are included to ease the transformation and are generally
    removed later on.
    
During this change, it also became apart from truncating sinks was
broken: if a sink used a source, its type information had already
been lost by the time the truncation happens. So I've changed the
method of caching the type information.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347191 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-19 11:34:40 +00:00
Sam Parker
72e06ac443 [ARM] Don't promote i1 types in ARM CGP
Now that we have mixed type sizes, i1 values need to be explicitly
handled as we want to avoid promoting these values.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346499 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-09 15:06:33 +00:00
Sam Parker
8e070ff595 [ARM] Enable mixed types in ARM CGP
Previously, during the search, all values had to have the same
'TypeSize', which is equal to number of bits of the integer type of
the icmp operand. All values in the tree had to match this size;
meaning that, if we searched from i16, we wouldn't accept i8s. A
change in type size requires zext and truncs to perform the casts so,
to allow mixed narrow types, the handling of these instructions is
now slightly different:

- we allow casts if their result or operand is <= TypeSize.
- zexts are sinks if their result > TypeSize.
- truncs are still sinks if their operand == TypeSize.
- truncs are still sources if their result == TypeSize.

The transformation bails on finding an icmp that operates on data
smaller than the current TypeSize.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346480 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-09 09:28:27 +00:00
Sam Parker
4bf0a8ee3f [ARM] Turn assert into condition in ARMCGP
Turn the assert in PrepareConstants into a conditon so that we can
handle mul instructions with negative immediates.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346126 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-05 11:26:04 +00:00
Sam Parker
76d01007ee [ARM][ARMCGP] Remove unecessary zexts and truncs
r345840 slightly changed the way promotion happens which could
result in zext and truncs having the same source and destination
types. This fixes that issue.

We can now also remove the zext and trunc in the following case:
(zext (trunc (promoted op)), i32)

This means that we can no longer treat a value, that is only used by
a sink, to be safe to promote.

I've also added in some extra asserts and replaced a cast for a
dyn_cast.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346125 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-05 10:58:37 +00:00
Sam Parker
376ec2b8fb [ARM] Attempt to fix ppc64be buildbot
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345850 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-01 16:44:45 +00:00
Sam Parker
b74f1454d8 [ARM][CGP] Negative constant operand handling
While mutating instructions, we sign extended negative constant
operands for binary operators that can safely overflow. This was to
allow instructions, such as add nuw i8 %a, -2, to still be able to
perform a subtraction. However, the code to handle constants doesn't
take into consideration that instructions, such as sub nuw i8 -2, %a,
require the i8 -2 to be converted into i32 254.

This is a relatively simple fix, but I've taken the time to
reorganise the code a bit - mainly that instructions that can be
promoted are cached and splitting up the Mutate function.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345840 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-01 15:23:42 +00:00
Sam Parker
78e19a9d43 [ARM] Fix for PR39060
When calculating whether a value can safely overflow for use by an
icmp, we weren't checking that the value couldn't wrap around. To do
this we need the icmp to be using a constant, as well as the incoming
add or sub.

bugzilla report: https://bugs.llvm.org/show_bug.cgi?id=39060

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343092 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-26 10:56:00 +00:00
Hans Wennborg
f824ff369c Revert r341932 "[ARM] Enable ARMCodeGenPrepare by default"
This caused miscompilation of WebRTC for Android: PR39060.

> We've had the pass enabled downstream for a couple of weeks and it
> seems to be okay, so enable it by default.
>
> Differential Revision: https://reviews.llvm.org/D51920

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342873 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-24 11:40:07 +00:00
Volodymyr Sapsai
e85b236f17 Revert "[ARM] Cleanup ARM CGP isSupportedValue"
This reverts r342395 as it caused error

> Argument value type does not match pointer operand type!
>   %0 = atomicrmw volatile xchg i8* %_Value1, i32 1 monotonic, !dbg !25
>  i8in function atomic_flag_test_and_set
> fatal error: error in backend: Broken function found, compilation aborted!

on bot http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/

More details are available at https://reviews.llvm.org/D52080


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342431 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-18 00:11:55 +00:00
Sam Parker
a72fb54240 [ARM] Cleanup ARM CGP isSupportedValue
isSupportedValue explicitly checked and accepted many types of value,
primarily for debugging reasons. Remove most of these checks and do a
bit of refactoring now that the pass is more stable. This also enables
ZExts to be sources, but this has very little practical benefit at the
moment extend instructions will still be introduced.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342395 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-17 13:57:39 +00:00
Sam Parker
d377332d77 [ARM] Disallow icmp with negative imm and overflow
We allow overflowing instructions if they're decreasing and only used
by an unsigned compare. Add the extra condition that the icmp cannot
be using a negative immediate.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342392 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-17 13:48:25 +00:00
Sam Parker
94436041e4 [ARM] Allow truncs as sources in ARM CGP
We previously only allowed truncs as sinks, but now allow them as
sources too. We do this by checking that the result type is the
narrow type that we're trying to optimise for.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342141 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-13 15:14:12 +00:00
Sam Parker
a8d062c818 [ARM] Fix FixConst for ARMCodeGenPrepare
Part of FixConsts wrongly assumes either a 8- or 16-bit constant
which can result in the wrong constants being generated during
promotion.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342140 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-13 14:48:10 +00:00
Sam Parker
f8479a89f4 [ARM] Allow bitcasts in ARMCodeGenPrepare
Allow bitcasts in the use-def chains, treating them as sources.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342032 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-12 09:11:48 +00:00
Sam Parker
0d36fb0dfa [ARM] Enable ARMCodeGenPrepare by default
We've had the pass enabled downstream for a couple of weeks and it
seems to be okay, so enable it by default.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341932 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-11 12:45:43 +00:00
Sjoerd Meijer
5a4ec120f8 [ARM][NFC] ARMCodeGenPrepare: some refactoring and algorithm description
Differential Revision: https://reviews.llvm.org/D50846


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339997 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-17 07:34:01 +00:00
Sam Parker
3591e4cd93 [ARM] Ignore GEPs in ARMCodeGenPrepare
While searching through the use-def tree, ignore GetElementPtrInst
instructions because they don't need promoting and neither do their
indices. Otherwise, the wide indices prevent the transformation from
happening.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339871 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-16 12:24:40 +00:00
Sam Parker
fd2bee90f5 [ARM] Allow zext in ARMCodeGenPrepare
Treat zext instructions as roots, like we do for truncs.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339868 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-16 11:54:09 +00:00
Sam Parker
7d16ffe5b7 [ARM] Allow signed icmps in ARMCodeGenPrepare
Originally committed in r339755 which was reverted in r339806 due to
an asan issue. The issue was caused by my assumption that operands to
a CallInst mapped to the FunctionType Params. CallInsts are now
handled by iterating over their ArgOperands instead of Operands.
    
Original Message:
  Treat signed icmps as 'sinks', allowing them to be in the use-def
  tree, enabling more promotions to be performed. As a sink, any
  promoted incoming values need to be truncated before being used by
  the signed icmp.
    
  Differential Revision: https://reviews.llvm.org/D50067


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339858 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-16 10:05:39 +00:00
Vitaly Buka
30db32fcf1 Revert "[ARM] Allow signed icmps in ARMCodeGenPrepare"
use-after-poison in check-llvm under asan

This reverts commit r339755.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339806 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-15 20:09:35 +00:00
Sam Parker
3dd5242055 [ARM] TypeSize lower bound for ARMCodeGenPrepare
We only try to promote types with are smaller than 16-bits, but we
also need to check that the type is not less than 8-bits.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339770 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-15 13:29:50 +00:00
Sam Parker
81654d2362 [ARM] Allow signed icmps in ARMCodeGenPrepare
Treat signed icmps as 'sinks', allowing them to be in the use-def
tree, enabling more promotions to be performed. As a sink, any
promoted incoming values need to be truncated before being used by
the signed icmp.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339755 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-15 08:23:03 +00:00
Sam Parker
90048a8206 [ARM] Allow pointer values in ARMCodeGenPrepare
Add pointers to the list of allowed types, but don't try to promote
them. Also fixed a bug with the promotion of undef values, so a new
value is now created instead of mutating in place. We also now only
promote if there's an instruction in the use-def chains other than
the icmp, sinks and sources.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339754 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-15 07:52:35 +00:00
Sam Parker
c709c56b9a [ARM] Disallow zexts in ARMCodeGenPrepare
Enabling ARMCodeGenPrepare by default caused a whole load of
failures. This is due to zexts and truncs not being handled properly.
ZExts are messy so it's just easier to disable for now and truncs
are allowed only as 'sinks'. I still need to figure out why allowing
them as 'sources' causes so many failures. The other main changes are
that we are explicit in the types that we converting to, it's now
always 'TypeSize'. Type support is also now performed while checking
for valid opcodes as it unnecessarily complicated having the checks
are different stages.
    
I've moved the tests around too, so we have the zext and truncs in
their own file as well as the overflowing opcode tests.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339432 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-10 13:57:13 +00:00
Reid Kleckner
1fa19f6800 Revert r338354 "[ARM] Revert r337821"
Disable ARMCodeGenPrepare by default again. It is causing verifier
failues in V8 that look like:

  Duplicate integer as switch case
  switch i32 %trunc, label %if.end13 [
    i32 0, label %cleanup36
    i32 0, label %if.then8
  ], !dbg !4981
  i32 0
  fatal error: error in backend: Broken function found, compilation aborted!

I will continue reducing the test case and send it along.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338452 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-31 23:09:42 +00:00
Sam Parker
a52192cab5 [ARM] Revert r337821
Re-enabling ARMCodeGenPrepare by default after failing to reproduce
the bootstrap issues that I was concerned it was causing.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338354 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-31 09:04:14 +00:00
Sam Parker
99421a402f [ARM] Disable ARMCodeGenPrepare by default
ARM Stage 2 builders have been suspiciously broken since the pass was
committed. Disabling to hopefully fix the bots and give me time to
debug.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337821 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-24 12:04:23 +00:00
Matt Morehouse
ad863f5657 [ARM] Follow-up to r337709.
Fix double-free.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337711 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-23 17:22:53 +00:00
Matt Morehouse
524f8982b8 [ARM] Add doFinalization() to ARMCodeGenPrepare pass.
Attempt to fix the leak introduced in r337687 and make sanitizer
buildbots green again.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337709 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-23 17:00:45 +00:00
Sam Parker
942fbb2330 [ARM] ARMCodeGenPrepare backend pass
Arm specific codegen prepare is implemented to perform type promotion
on icmp operands, which can enable the removal of uxtb and uxth
(unsigned extend) instructions. This is possible because performing
type promotion before ISel alleviates this duty from the DAG builder
which has to perform legalisation, but has a limited view on data
ranges.
    
The pass visits any instruction operand of an icmp and creates a
worklist to traverse the use-def tree to determine whether the values
can simply be promoted. Our concern is values in the registers
overflowing the narrow (i8, i16) data range, so instructions marked
with nuw can be promoted easily. For add and sub instructions, we are
able to use the parallel dsp instructions to operate on scalar data
types and avoid overflowing bits. Underflowing adds and subs are also
permitted when the result is only used by an unsigned icmp.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337687 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-23 12:27:47 +00:00