21626 Commits

Author SHA1 Message Date
Vasileios Porpodas
4e971efad4 Recommit "[SLP][AArch64] Implement lookahead operand reordering score of splat loads for AArch64"
This reverts commit 7052a0ad689b990265ec79bd2b0a7d6e8c131bfe.
2022-04-22 15:44:02 -07:00
Valery N Dmitriev
ada8973fba [SLP][NFC] Pre-commit test showing deficiency in current roots selection algorithm.
Test case to show not quite optimal SLP vectorization.

Reviewed By: Vasileios Porpodas (vporpo)
Differential Revision: https://reviews.llvm.org/D124293
2022-04-22 14:47:02 -07:00
Florian Hahn
ce3bb82e45
[LICM] Add test for writeonly fn with noalias call.
Add an additional test for D123473.
2022-04-22 21:37:08 +01:00
Florian Hahn
b341c44010
[SimpleLoopUnswitch] Check if freeze is needed for partial unswitching.
We only need to insert a Freeze instruction if any of the conditions
may be poison. Similar checks are already done in the other places
SimpleLoopUnswitch creates Freeze instruction.

Reviewed By: aeubanks, efriedma

Differential Revision: https://reviews.llvm.org/D124259
2022-04-22 21:24:55 +01:00
Florian Hahn
1fa0bb8a80
[SimpleLoopUnswitch] Add test where all conds are guaranteed non poison.
Extra test for D124259.
2022-04-22 18:09:05 +01:00
Simon Pilgrim
ffe13960b5 [InstCombine] Fold (A & 2^C1) + A => A & (2^C1 - 1) iff bit C1 in A is a sign bit (PR21929)
Alive2: https://alive2.llvm.org/ce/z/Ygq26C

This is the final missing fold to handle the modulo2 simplification: https://github.com/llvm/llvm-project/issues/22303

Fixes #22303

Differential Revision: https://reviews.llvm.org/D123374
2022-04-22 16:59:02 +01:00
Vasileios Porpodas
7052a0ad68 Revert "[SLP][AArch64] Implement lookahead operand reordering score of splat loads for AArch64"
This reverts commit 7ba702644bac6df166a02bbd692c1599a95a7c8b.
2022-04-22 08:24:04 -07:00
Nikita Popov
de1e3c649f [InstCombine] Fix typo in test (NFC) 2022-04-22 16:54:56 +02:00
Vasileios Porpodas
7ba702644b [SLP][AArch64] Implement lookahead operand reordering score of splat loads for AArch64
The original patch (https://reviews.llvm.org/D121354) targets x86 and adjusts
the lookahead score of splat loads ad they can be done by the `movddup`
instruction that combines the load and the broadcast and is cheap to execute.

A similar issue shows up on AArch64. The `ld1r` instruction performs a broadcast
load and is cheap to execute.

This patch implements the TargetTransformInfo hooks for AArch64.

Differential Revision: https://reviews.llvm.org/D123638
2022-04-22 07:29:58 -07:00
Biplob Mishra
237c4bada9 InstCombine: Add tests to show or-and scenarios which can be possibly be combined by ORing the masks 2022-04-22 15:23:57 +01:00
Nikita Popov
074abdcc60 [InstCombine] Add tests for and of icmp ne zero and icmp uge (NFC)
Partially based on the conjugated or tests.
2022-04-22 15:53:33 +02:00
Vasileios Porpodas
ad12f468a3 [SLP][AArch64][NFC] Add test for a follow-up patch that fixes the lookahead cost of splat-loads for AArch64 2022-04-22 05:29:34 -07:00
Nikita Popov
3e1d2c352c [InstCombine] Fix or of commuted foldable predicates
1d90e530442477de247dcb613f5176fe7e9beded switch this code to store
the predicates and operands in variables, but retained a
swapOperands() call here. Thus the commuted cases were no longer
folded. Additionally, as the change was not reported, the next
InstCombine iteration would not pick it up either.
2022-04-22 12:31:26 +02:00
Nikita Popov
2b252c159f [InstCombine] Add commuted or of icmp test (NFC) 2022-04-22 12:28:12 +02:00
Florian Hahn
85eb8b7244
[IndVars] Add test for crash exposed by D114650. 2022-04-22 10:44:29 +01:00
Nikita Popov
e69c21f75b [InstCombine] Add test for atomic load from constant global (NFC) 2022-04-22 11:15:50 +02:00
Sanjay Patel
664ae7bbcc [InstCombine] C0 <<{nsw, nuw} (X - C1) --> (C0 >> C1) << X (2nd try)
The first attempt at this missed a check to make sure the offset
constant was in range and caused many bot failures.

That was missed in the Alive2 proof because on overshift creates
poison rather than the assert from APInt. Here's an alternate
attempt at a proof using count-trailing-zeros:
https://alive2.llvm.org/ce/z/pnXQYR

Original commit message:

This is similar to an existing pre-shift-of-constant fold:
8a9c70fc01e6
...but in this case, we need no-wrap on the shl and a negative
offset:
https://alive2.llvm.org/ce/z/_RVz99
2022-04-21 16:18:46 -04:00
Sanjay Patel
49f950ae26 [InstCombine] add more tests for a planned shift fold; NFC
These are reductions for a missed constraint (the offset
constant must be less than the bitwidth) that caused the
first version of the patch ( 5819f4a42286 ) to be reverted.
2022-04-21 14:08:50 -04:00
chenglin.bi
25aba1abb5 Revert "[InstCombine] Add one use limitation for (X * C2) << C1 --> X * (C2 << C1)"
This reverts commit b543d28df7b067dcda833c717a59faa28c1151a1.
2022-04-22 00:56:20 +08:00
chenglin.bi
b543d28df7 [InstCombine] Add one use limitation for (X * C2) << C1 --> X * (C2 << C1)
Follow up D123453, add one-use limitation for
(X * C2) << C1 --> X * (C2 << C1)
to make consistent with
lshr (mul nuw x, MulC), ShAmtC -> mul nuw x, (MulC >> ShAmtC)

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D124183
2022-04-22 00:32:36 +08:00
Sanjay Patel
8960ba7491 Revert "[InstCombine] C0 <<{nsw, nuw} (X - C1) --> (C0 >> C1) << X"
This reverts commit 5819f4a422865fc9a8ea4dc772769e14010ff6a7.
This caused bots to fail with a crash/assert during the fold,
so some constraint was missed.
2022-04-21 12:15:27 -04:00
chenglin.bi
e077e3a648 [InstCombine] add baseline test for (X * C2) << C1 --> X * (C2 << C1) without one use; NFC 2022-04-22 00:12:06 +08:00
Sanjay Patel
5819f4a422 [InstCombine] C0 <<{nsw, nuw} (X - C1) --> (C0 >> C1) << X
This is similar to an existing pre-shift-of-constant fold:
8a9c70fc01e6
...but in this case, we need no-wrap on the shl and a negative
offset:
https://alive2.llvm.org/ce/z/_RVz99

Fixes #54890
2022-04-21 11:38:27 -04:00
Sanjay Patel
782d0105ba [InstCombine] add tests for C << (X - C1); NFC 2022-04-21 11:38:26 -04:00
Nikita Popov
ead231dec0 [InstCombine] Fix typo in test (NFC)
This is a copy paste mistake, this variant of the test was supposed
to use poison instead of undef.
2022-04-21 15:58:51 +02:00
Nikita Popov
662f57ee21 [InstCombine] Add tests for memset with undef/poison value (NFC) 2022-04-21 15:45:54 +02:00
Nikita Popov
9001edc535 [InstCombine] Split up test for store with undef (NFC) 2022-04-21 15:41:38 +02:00
Simon Pilgrim
ac213375d9 [InstCombine] Add nonpow2 (negative) test for D123374 2022-04-21 13:58:43 +01:00
Nikita Popov
20cf4f8af8 [PhaseOrdering] Remove RUN lines for legacy PM (NFC) 2022-04-21 14:43:00 +02:00
Nikola Tesic
c5600aef88 [Debugify] Limit number of processed functions for original mode
Debugify in OriginalDebugInfo mode, does (DebugInfo) collect-before-pass & check-after-pass
for each instruction, which is pretty expensive. When used to analyze DebugInfo losses
in large projects (like LLVM), this raises the build time unacceptably.
This patch introduces a limit for the number of processed functions per compile unit.
By default, the limit is set to UINT_MAX (practically unlimited), and by using the introduced
option  -debugify-func-limit  the limit could be set to any positive integer number.

Differential revision: https://reviews.llvm.org/D115714
2022-04-21 13:58:17 +02:00
Nikita Popov
15fc293b11 Revert "[GVNSink] Regenerate test checks (NFC)"
This reverts commit 3b132300728e7ed06e59e449ceb8175305869a49.

It looks like GVNSink is currently non-deterministic, due to an
std::sort() on BasicBlock* pointers in ModelledPHI. This becomes
visible in the generated checks.
2022-04-21 10:46:34 +02:00
Nikita Popov
3b13230072 [GVNSink] Regenerate test checks (NFC) 2022-04-21 10:07:09 +02:00
Chuanqi Xu
7eaa84eac3 [NFC] Code cleanups for coroutine after we remvoed legacy passes 2022-04-21 15:32:46 +08:00
Chuanqi Xu
483efc9ad0 [Pipelines] Remove Legacy Passes in Coroutines
The legacy passes are deprecated now and would be removed in near
future. This patch tries to remove legacy passes in coroutines.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D123918
2022-04-21 10:59:11 +08:00
Florian Hahn
bea69b232f
[VPlan] Initial modeling of middle block in VPlan.
This patch extends the scope of VPlan to also include the exit (aka
middle) block.

For now, the exit block remains empty, but handling of exit values will
subsequently be moved to VPlan, by adding recipes to model exit values
in the exit block.

As a first step, this will allow fixing #51366.

Reviewed By: Ayal

Differential Revision: https://reviews.llvm.org/D123457
2022-04-20 19:34:41 +01:00
Paul Kirth
61e36e87df [safestack] Support safestack in stack size diagnostics
Current stack size diagnostics ignore the size of the unsafe stack.
This patch attaches the size of the static portion of the unsafe stack
to the function as metadata, which can be used by the backend to emit
diagnostics regarding stack usage.

Reviewed By: phosek, mcgrathr

Differential Revision: https://reviews.llvm.org/D119996
2022-04-20 18:29:40 +00:00
Florian Hahn
5e54a413de
[LICM] Add additional writeonly tests, check attributes.
Add additional test coverage for D123473.
2022-04-20 18:49:37 +01:00
Craig Topper
e3f6c2d288 [InstCombine] Don't look through bitcast from vector in collectInsertionElements.
We're making a recursive call here and everything in the function
assumes we're looking at scalars. This would be violated if we
looked through a bitcast from vectors.

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D124015
2022-04-20 09:15:32 -07:00
Craig Topper
11db0bb64d [InstCombine] Pre-commit test for D124015
Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D124016
2022-04-20 09:15:32 -07:00
chenglin.bi
1fae4b492d [InstCombine] Fold mul nuw+lshr to a single multiplication when the latter is a factor
if c is divisible by (1 << ShAmtC), we can fold this pattern:
lshr (mul nuw x, c), ShAmtC -> mul nuw x, (c >> ShAmtC)

https://alive2.llvm.org/ce/z/ox4wAt

Fix https://github.com/llvm/llvm-project/issues/54824

Reviewed By: spatel, lebedev.ri, craig.topper

Differential Revision: https://reviews.llvm.org/D123453
2022-04-21 00:13:36 +08:00
Nikita Popov
d727505e40 [SimplifyCFG] Remove one-use limitation in FoldCondBranchOnPHI()
BlockIsSimpleEnoughToThreadThrough() already checks that the phi
(and all other instructions) are not used outside the block, so
this one-use check is not necessary for legality. I also don't
see any reason why it would be necessary for profitability (in
fact, those extra uses will be replaced with constants, which
should be generally profitable).
2022-04-20 15:56:20 +02:00
Nikita Popov
37b1515b0a [SimplifyCFG] Add additional threading tests (NFC) 2022-04-20 15:40:44 +02:00
Max Kazantsev
a0595f8c99 [Test] One more test with potentially malformed phis 2022-04-20 15:50:27 +07:00
chenglin.bi
8242fc7f8a [InstCombine] add tests for mul+lshr; NFC
Baseline tests for D123453(issue #54824)
2022-04-20 16:13:31 +08:00
Max Kazantsev
57d17795b9 [Test] Add one more test for patch [SLP]Improve reductions analysis and emission, part 1.
The original patch leads to malformed phis on this test. Make sure
we're safeguarded from its return until it is fixed.
2022-04-20 13:57:26 +07:00
Fangrui Song
14d9390721 Revert D123198 "[BuildLibCalls] Introduce getOrInsertLibFunc() for use when building libcalls."
test/Transforms/InstCombine/pr39177.ll failed in a -DLLVM_USE_SANITIZER=Undefined build.
```
lib/Transforms/Utils/BuildLibCalls.cpp:1217:17: runtime error: reference binding to null pointer of type 'llvm::Function'
```
`Function &F = *M->getFunction(Name);`

This reverts commit 0f8c626723d2bbd547e78dcab5ab260dfbc437e1.
2022-04-19 22:26:10 -07:00
Paul Kirth
bac6cd5bf8 [misexpect] Re-implement MisExpect Diagnostics
Reimplements MisExpect diagnostics from D66324 to reconstruct its
original checking methodology only using MD_prof branch_weights
metadata.

New checks rely on 2 invariants:

1) For frontend instrumentation, MD_prof branch_weights will always be
   populated before llvm.expect intrinsics are lowered.

2) for IR and sample profiling, llvm.expect intrinsics will always be
   lowered before branch_weights are populated from the IR profiles.

These invariants allow the checking to assume how the existing branch
weights are populated depending on the profiling method used, and emit
the correct diagnostics. If these invariants are ever invalidated, the
MisExpect related checks would need to be updated, potentially by
re-introducing MD_misexpect metadata, and ensuring it always will be
transformed the same way as branch_weights in other optimization passes.

Frontend based profiling is now enabled without using LLVM Args, by
introducing a new CodeGen option, and checking if the -Wmisexpect flag
has been passed on the command line.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D115907
2022-04-19 21:23:48 +00:00
Jonas Paulsson
0f8c626723 [BuildLibCalls] Introduce getOrInsertLibFunc() for use when building libcalls.
A new set of overloaded functions named getOrInsertLibFunc() are now supposed
to be used instead of getOrInsertFunction() when building a libcall from
within an LLVM optimizer(). The idea is that this new function also makes
sure that any mandatory argument attributes are added to the function
prototype (after calling getOrInsertFunction()).

inferLibFuncAttributes() is renamed to inferNonMandatoryLibFuncAttrs() as it
only adds attributes that are not necessary for correctness but merely
helping with later optimizations.

Generally, the front end is responsible for building a correct function
prototype with the needed argument attributes. If the middle end however is
the one creating the call, e.g. when replacing one libcall with another, it
then must take this responsibility.

This continues the work of properly handling argument extension if required
by the target ABI when building a lib call. getOrInsertLibFunc() now does
this for all libcalls currently built by any LLVM optimizer. It is expected
that when in the future a new optimization builds a new libcall with an
integer argument it is to be added to getOrInsertLibFunc() with the proper
handling. Note that not all targets have it in their ABI to sign/zero extend
integer arguments to the full register width, but this will be done
selectively as determined by getExtAttrForI32Param().

Review: Eli Friedman, Nikita Popov, Dávid Bolvanský

Differential Revision: https://reviews.llvm.org/D123198
2022-04-19 21:22:07 +02:00
Sanjay Patel
8a9c70fc01 [InstCombine] C0 shift (X add nuw C) --> (C0 shift C) shift X
With 'nuw' we can convert the increment of the shift amount
into a pre-shift (constant fold) of the shifted constant:
https://alive2.llvm.org/ce/z/FkTyR2

Fixes issue #41976
2022-04-19 15:21:34 -04:00
Sanjay Patel
a9aa14e0cb [InstCombine] add tests for shift-of-add with constants; NFC 2022-04-19 15:21:34 -04:00