24894 Commits

Author SHA1 Message Date
Fangrui Song
f53de29862 [FunctionImport] Change IRMover report_fatal_error to a proper error
Conflicting module flags leads to a proper error for regular LTO but a crash
(report_fatal_error) for ThinLTO. Switch to createStringError to fix the crash
and match regular LTO.
2023-02-23 21:45:14 -08:00
Noah Goldstein
4fcfff4f2d Use analyzeKnownBitsFromAndXorOr in SimplifyDemandedUseBits for and/xor/or
There are extra patterns that have for these three logic operations
that aren't covered in `SimplifyDemandedUseBits`. To avoid duplicating
the code, just use `analyzeKnownBitsFromAndXorOr` in
`SimplifyDemandedUseBits` to get full coverage.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D142429
2023-02-23 19:52:17 -06:00
Leonard Chan
86dbcafd0c [llvm] Teach GlobalDCE about dso_local_equivalent
This way, C++ relative-vtables can also participate in GlobalDCE. This
depends on some TypeMetadataUtils.cpp bits in D134320, but that
dependency can be removed and included here if necessary.

Differential Revision: https://reviews.llvm.org/D135928
2023-02-23 23:13:57 +00:00
Krzysztof Drewniak
5a4f193afa Add tests to reproduce pointer/index width confusion crashes
Some calls to GEPOperator::accumulateConstantOffset(APInt) passed the
pointer bitwidth as the width of the APInt, while the function asserts
that the width of its argument is equal to the index width of the GEP
pointer input. These values are almost always the same, so mixing up
which call to use doesn't usually cause issues. However, when dealing
with data layouts where these values are different, the passes tested
here can crash.

This will be fixed in D143437 .

Differential Revision: https://reviews.llvm.org/D144673
2023-02-23 22:50:43 +00:00
Leonard Chan
db28818476 [llvm] Teach whole program devirtualization about relative vtables
Prior to this patch, WPD was not acting on relative-vtables in C++. This
involves teaching WPD about these things:

- llvm.load.relative which is how relative-vtables are indexed (instead of GEP)
- dso_local_equivalent which is used in the vtable itself when taking the
  offset between a virtual function and vtable
- Update llvm/test/ThinLTO/X86/devirt.ll to use opaque pointers and add
  equivalent tests for RV

Differential Revision: https://reviews.llvm.org/D134320
2023-02-23 22:18:43 +00:00
Sanjay Patel
54e5107498 [InstCombine] add tests for select of div/rem with common operand; NFC
issue #60906
2023-02-23 15:32:39 -05:00
Jonas Paulsson
1387a13e1d [SLP] Check with target before vectorizing GEP Indices.
The target hook prefersVectorizedAddressing() already exists to check with
target if address computations should be vectorized, so it seems like this
should be used in SLPVectorizer as well.

Reviewed By: ABataev, RKSimon

Differential Revision: https://reviews.llvm.org/D144128
2023-02-23 15:31:34 +01:00
khei4
0eb45cd081 (NFC)[ConstantFold][InstSimplify] add tests for folding load for patterned arrays and structs 2023-02-23 23:16:59 +09:00
khei4
a6a0cf7bca Revert "(NFC)[ConstantFold][InstSimplify] add tests for folding load for patterned arrays and structs"
This reverts commit 9636bcd3a0091b0bb77250182ac0c549112f9196.
2023-02-23 19:36:11 +09:00
Matt Arsenault
08f0388711 InstCombine: Fold and/or of fcmp into class
This is motivated by patterns like !isfinite || zero. The AMDGPU math
libraries have a lot of patterns like this, and I'm trying to fix the
code to be more portable and less dependent on directly calling class
intrinsics.

I believe this is the first place where new is.fpclass calls are
introduced. There are more class-like compares that could be
recognized; this is a set I currently care about plus a few extras.

Keep the == 0 cases disabled for now. It depends on the denormal
mode. If we just check IEEE mode now, it will break my use case
without another patch I'm working on.
2023-02-23 06:19:40 -04:00
khei4
9636bcd3a0 (NFC)[ConstantFold][InstSimplify] add tests for folding load for patterned arrays and structs 2023-02-23 17:09:54 +09:00
chenglin.bi
c7531a1be9 [LogicCombine] Restore the logic-combine.ll to before optimzed; NFC 2023-02-23 09:00:25 +08:00
chenglin.bi
0c3411bbc5 [LogicCombine] Rename test file complex-logic.ll to logic-combine.ll; NFC 2023-02-23 08:57:08 +08:00
Sanjay Patel
40d772c642 [InstCombine] add one-use check to prevent creating an instruction in shuffle-of-binop
This fold was added with https://reviews.llvm.org/D135876 ,
but we missed the one-use check.

This might be the root cause for issue #60632.
2023-02-22 19:20:32 -05:00
Sanjay Patel
6c2a7817f8 [InstCombine] add test for splat-of-binop; NFC
This shows a missing extra use check.
2023-02-22 19:20:32 -05:00
Arthur Eubanks
86ced82099 Revert "[IRMover] Remove UB implying parameter attributes when necessary"
This reverts commit 451799bb8261bde52bbfef226d019caf1d82aa42.

Causes crashes, see D139209
2023-02-22 09:40:39 -08:00
Daniel Woodworth
a33f018b89 [Local][SimplifyCFG][GVN] Handle !nontemporal in combineMetadata
SimplifyCFG currently drops !nontemporal metadata when sinking
common instructions. With this change, SimplifyCFG and similar
transforms will preserve !nontemporal metadata as long as it is
set on both original instructions.

Differential Revision: https://reviews.llvm.org/D144298
2023-02-22 14:47:00 +01:00
Luke Lau
15f9cf164c [LV][RISCV] Don't interleave scalable vector loops
It's less clear with scalable vectors than fixed length vectors that
interleaving exposes more ILP, as scalable vectors can be thought of a
sort of hardware form of interleaving, especially with larger LMULs.
This also addresses the unexpected additional unrolling that occurs when
using larger LMULs in the loop vectorizer.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D144485
2023-02-22 10:15:11 +00:00
Sanjay Patel
ae2322a0dc [InstSimplify] enhance simplifyWithOpReplaced() to allow more 'select' removal
This is a generalization of a suggestion from issue #60799
that allows removing a redundant guard of an input value
via icmp+select. It should also solve issue #60801.

This only comes into play for a select with an equality
condition where we are trying to substitute a constant into
the false arm of a select. (A 'true' select arm substitution
allows "refinement", so it is not on this code path.)

The constant must be the same in the compare and the select,
and it must be a "binop absorber" (X op C = C). That query
currently includes 'or', 'and', and 'mul', so there are tests
for all of those opcodes.

We then use "impliesPoison" on the false arm binop and the
original "Op" to be replaced to ensure that the select is not
actually blocking poison from leaking. That could be
potentially expensive as we recursively test each operand, but
it is currently limited to a depth of 2. That's enough to catch
our motivating cases, but probably nothing more complicated
(although that seems unlikely).

I don't know how to generalize a proof for Alive2 for this, but
here's a positive and negative test example to help illustrate
the subtle logic differences of poison/undef propagation:
https://alive2.llvm.org/ce/z/Sz5K-c

Differential Revision: https://reviews.llvm.org/D144493
2023-02-21 17:03:40 -05:00
ManuelJBrito
bceafb7f24 [InstCombine] Don't fold freeze poison when it's used in shufflevector
With this patch freeze undef/poison will no longer be folded into a constant if it's used as a
vector operand in a shufflevector.

Differential Revision: https://reviews.llvm.org/D143593
2023-02-21 21:58:27 +00:00
Alexey Bataev
cbcdd747e8 [SLP]Do not swap not counted extractelements.
No need to swap extractelements, which were not excluded from the list
during cost analysis. It leads to incorrect cost calculation and make
vector code more profitable than it is actually is.
2023-02-21 13:16:51 -08:00
Alexey Bataev
677ea15e35 [NFC][SLP]Add a test for optimistic vectorization, NFC. 2023-02-21 11:02:32 -08:00
Sanjay Patel
dbc00b88e9 [InstSimplify] add tests for simplifyWithOpReplaced(); NFC
issue #60799
issue #60801
2023-02-21 12:49:34 -05:00
Tim Neumann
451799bb82 [IRMover] Remove UB implying parameter attributes when necessary
When importing functions from some module X into some module Y, they may reference other functions already present in Y. The signature (especially attributes) of those other functions may have diverged between X and Y (e.g. due to the Dead Argument Elimination optimization). If necessary, modify the attributes to avoid UB.

See the added test and implementation comments for more details.

This was exposed by https://reviews.llvm.org/D133036 before it was reverted. Fixes https://github.com/llvm/llvm-project/issues/58976.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D139209
2023-02-21 18:35:31 +01:00
Florian Hahn
7f51145b1b
[GlobalOpt] Add tests with non-GEP ConstExpr.
Extra tests for CleanupPointerRootUsers with non-GEP constant
expressions for D144468.
2023-02-21 17:17:18 +00:00
Alexey Bataev
5f928a223e [SLP]Properly define incoming block for user PHI nodes.
MainOp of the PHI vectorizable entries contains the proper order of
incoming blocks, not the last instruction in the block.
2023-02-21 08:01:24 -08:00
Nikita Popov
3232f3ed0a [InstCombine] Add additional alloca comparison tests (NFC) 2023-02-21 16:40:01 +01:00
DianQK
b6a0be8ce3
[SimplifyCFG] Check if the return instruction causes undefined behavior
This should fix https://github.com/rust-lang/rust/issues/107681.

Return undefined to a noundef return value is undefined.

Example:

```
define noundef i32 @test_ret_noundef(i1 %cond) {
entry:
  br i1 %cond, label %bb1, label %bb2
bb1:
  br label %bb2
bb2:
  %r = phi i32 [ undef, %entry ], [ 1, %bb1 ]
  ret i32 %r
}
```

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D144319
2023-02-21 21:42:13 +08:00
Nikita Popov
92ef545b8d [IPSCCP] Remove noundef when zapping return values
When replacing return values with undef, we should also drop the
noundef attribute (and other UB implying attributes).

Differential Revision: https://reviews.llvm.org/D144461
2023-02-21 14:38:30 +01:00
Florian Hahn
5c39ec73ef
[GlobalOpt] Add test with large number of stores with non-null loads. 2023-02-21 13:01:10 +00:00
Florian Hahn
9f5ae702ed
[GlobalOpt] Add tests for missed CleanupPointerRootUsers opportunity. 2023-02-21 11:04:09 +00:00
Florian Hahn
38d0e4d180
[GlobalOpt] Add test with many stores of the initializer only. 2023-02-21 10:24:51 +00:00
Nikita Popov
dbc2f65ad5 [IPSCCP] Add tests for noundef attribute on zapped returns (NFC)
We replace the return value with undef without dropping the
noundef attribute.
2023-02-21 10:54:00 +01:00
Nikita Popov
4d192f2d2a [InstSimplify][CaptureTracking] Reduce scope of special case
As described in PR54002, the "icmp of load from global" special
case in CaptureTracking is incorrect, as is the InstSimplify code
that makes use of it.

This moves the special case from CaptureTracking into InstSimplify
to limit its scope to the buggy transform only, and not affect
other code using CaptureTracking as well.
2023-02-21 09:01:55 +01:00
Simon Pilgrim
2ca266dc1a [SLP][X86] minimum-sizes.ll - add AVX512 test coverage
As noticed on D144128, we need better AVX512 coverage for GEP vectorization
2023-02-20 23:31:56 +00:00
Simon Pilgrim
d9bceeedbf [SLP][X86] load-merge.ll - add AVX512 test coverage
As noticed on D144128, we need better AVX512 coverage for GEP vectorization
2023-02-20 23:21:33 +00:00
Luke Lau
0b336e9ef0 [RISCV][NFC] Add test for different LMULs in vectorizer
This is a test for an upcoming patch that proposes to change the default LMUL used by the loop vectorizer from 1 to 2

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D143722
2023-02-20 22:40:40 +00:00
Sanjay Patel
703423c269 [InstCombine] relax constraint on udiv fold
The pair of div folds was just added with:
4966d8ebe1bbe5bd6a4d28

But as noted in the post-commit review, we don't actually need
the no-remainder requirement for an unsigned division (still
need the no-unsigned-wrap though):
https://alive2.llvm.org/ce/z/qHjK3Q
2023-02-20 15:08:32 -05:00
Sanjay Patel
36014a71eb [InstCombine] auto-generate test CHECK lines; NFC
The check line was not enabled until bfb1559fbe2fb656f3,
and then it was excessive, so the test started failing.
2023-02-20 14:04:03 -05:00
Sanjay Patel
4966d8ebe1 [InstCombine] distribute div over add with matching mul-by-constant
((X * C2) + C1) / C2 --> X + C1/C2
https://alive2.llvm.org/ce/z/P66io8
https://alive2.llvm.org/ce/z/vghegw

This could be made more general -- the multiplier could be a
multiple of the divisor -- but this is the pattern from
issue #60754.
2023-02-20 13:45:06 -05:00
Sanjay Patel
f49d19d502 [InstCombine] add tests for div with muladd operand; NFC
issue #60754
2023-02-20 13:45:06 -05:00
Sanjay Patel
595ffc56be [InstCombine] add tests for add with sub-from-constant operand; NFC 2023-02-20 13:45:06 -05:00
Tiwari Abhinav Ashok Kumar
bfb1559fbe [NFC] Fix missing colon in CHECK directives
Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D144412
2023-02-21 00:13:04 +05:30
zhongyunde
ee9a0f30ca [InstCombine] canonicalize urem as cmp+select
Fix https://github.com/llvm/llvm-project/issues/60546

Reviewed By: nikic, efriedma, RKSimon, spatel

Differential Revision: https://reviews.llvm.org/D143883
2023-02-20 23:52:10 +08:00
Nikita Popov
45a0b812fa [InstCombine] Remove early constant fold
InstCombine currently performs a constant folding attempt as part
of the main InstCombine loop, before visiting the instruction.
However, each visit method will also attempt to simplify the
instruction, which will in turn constant fold it. (Additionally,
we also constant fold instructions before the main InstCombine loop
and use a constant folding IR builder, so this is doubly redundant.)

There is one place where InstCombine visit methods currently don't
call into simplification, and that's casts. To be conservative,
I've added an explicit constant folding call there (though it has
no impact on tests).

This makes for a mild compile-time improvement and in particular
mitigates the compile-time regression from enabling load
simplification in be88b5814d9efce131dbc0c8e288907e2e6c89be.

Differential Revision: https://reviews.llvm.org/D144369
2023-02-20 16:48:39 +01:00
zhongyunde
2e0f91739e [test] precommit some tests for D143883 NFC
Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D144372
2023-02-20 23:47:23 +08:00
Nikita Popov
2502dc8a28 [InstCombine] Use CaptureTracking in foldAllocaCmp()
foldAllocaCmp() checks whether the alloca is not captured (ignoring
the icmp). Replace the manual implementation of escape analysis
with CaptureTracking.

The primary practical difference is that CaptureTracking handles
nocapture arguments, while foldAllocaCmp() was using a hardcoded
list.

This is basically just the CaptureTracking refactoring from D120371
without the other changes.
2023-02-20 16:39:19 +01:00
Ricardo Jesus
287267c23a [AArch64] Add SLP test for abs (NFC)
Differential Revision: https://reviews.llvm.org/D144376
2023-02-20 14:50:06 +00:00
Zain Jaffal
fa1eb2eb16 [ConstraintElimination] Add tests to check for or instruction decomposition if a constant operand is < 2^known_zero_bits of the first operand.
Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D142545
2023-02-20 14:39:02 +00:00
Alexey Bataev
708eb1b96d [SLP]Add shuffling of extractelements to avoid extra costs/data movement.
If the scalar must be extracted and then used in the gather node,
instead we can emit shuffle instruction to avoid those extra
extractelements and vector-to-scalar and back data movement.

Part of D110978

Differential Revision: https://reviews.llvm.org/D141940
2023-02-20 06:14:42 -08:00