107 Commits

Author SHA1 Message Date
Paul Walker
900bea9b1c [LLVM][test] Convert remaining instances of ConstantExpr based splats to use splat().
This is mostly NFC but some output does change due to consistently
inserting into poison rather than undef and using i64 as the index
type for inserts.
2024-02-27 13:37:23 +00:00
Nikita Popov
2d69827c5c [Transforms] Convert tests to opaque pointers (NFC) 2024-02-05 11:57:34 +01:00
Mikael Holmen
ce0a750fe4 [AggressiveInstCombine] Ignore debug instructions when load combining (#70200)
We previously included debug instructions when counting instructions when
looking for loads to combine. This meant that the presence of debug
instructions could affect optimization, as shown in the updated testcase.

This fixes #69925.
2023-10-26 09:58:54 +02:00
Mikael Holmen
34fe8be705 [test][AggressiveInstCombine] Precommit testcase for #69925
We get different results with/without debug info present.
2023-10-26 09:58:54 +02:00
Alexander Kornienko
0b779b0daa Revert "[AggressiveInstCombine] Fold strcmp for short string literals"
This reverts commit 5dde755188e34c0ba5304365612904476c8adfda,
cbfcf90152de5392a36d0a0241eef25f5e159eef and
8981520b19f2d2fe3d2bc80cf26318ee6b5b7473 due to a miscompile introduced in
8981520b19f2d2fe3d2bc80cf26318ee6b5b7473 (see
https://reviews.llvm.org/D154725#4568845 for details)

Differential Revision: https://reviews.llvm.org/D157430
2023-08-08 22:53:45 +02:00
David Green
aa97f6b494 [AIC] Fix the sext cost operands in tryToFPToSat
As pointed out in D125755 the operand of a call to getCastInstrCost had the Src
and Dst the wrong way around.

Differential Revision: https://reviews.llvm.org/D154841
2023-08-07 09:33:18 +01:00
Maksim Kita
cbfcf90152 [AggressiveInstCombine] Fold strcmp for short string literals with size 2
Fold strcmp for short string literals with size 2.
Depends D155742.

Differential Revision: https://reviews.llvm.org/D155743
2023-07-27 18:45:21 +03:00
Maksim Kita
0c8d3db5d2 [AggressiveInstCombine] Fold strcmp for short string literals with size 2 tests
Precommit tests for D155743.

Differential Revision: https://reviews.llvm.org/D155742
2023-07-27 18:45:21 +03:00
Maksim Kita
8981520b19 [AggressiveInstCombine] Fold strcmp for short string literals
Fold strcmp() against 1-char string literals.

This designates AggressiveInstCombine as the pass for libcalls
simplifications that may need to change the control flow graph.

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

Differential Revision: https://reviews.llvm.org/D154725
2023-07-19 17:12:27 +02:00
Maksim Kita
f9d1895d65 [AggressiveInstCombine] Fold strcmp for short string literals tests (NFC)
Precommit tests for D154725.

Differential Revision: https://reviews.llvm.org/D155053
2023-07-19 16:53:48 +02:00
Matt Arsenault
6640df94f9 ValueTracking: Remove CannotBeOrderedLessThanZero
Replace the last user of CannotBeOrderedLessThanZero with new
version. Makes assumes work in this case.
2023-07-11 20:42:18 -04:00
Fangrui Song
d39b4ce3ce [test] Replace aarch64-*-eabi with aarch64
Using "eabi" for aarch64 targets is a common mistake and warned by Clang Driver.
We want to avoid it elsewhere as well. Just use the common "aarch64" without
other triple components.
2023-06-27 20:02:52 -07:00
bipmis
cbc50ba12e [AggressiveInstCombine] Handle the nested GEP/BitCast scenario in Load Merge.
This seems to be an issue currently where there are nested/chained GEP/BitCast Pointers.
The patch generates a new GEP for the wider load to avoid dominance problems.

Differential Revision: https://reviews.llvm.org/D150864
2023-05-24 10:36:11 +01:00
Tobias Hieta
f84bac329b
[NFC][Py Reformat] Reformat lit.local.cfg python files in llvm
This is a follow-up to b71edfaa4ec3c998aadb35255ce2f60bba2940b0
since I forgot the lit.local.cfg files in that one.

Reformatting is done with `black`.

If you end up having problems merging this commit because you
have made changes to a python file, the best way to handle that
is to run git checkout --ours <yourfile> and then reformat it
with black.

If you run into any problems, post to discourse about it and
we will try to help.

RFC Thread below:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Reviewed By: barannikov88, kwk

Differential Revision: https://reviews.llvm.org/D150762
2023-05-17 17:03:15 +02:00
khei4
39a0677784 [AggressiveInstCombine] folding load for constant global patterened arrays and structs by GEP-indices
Differential Revision: https://reviews.llvm.org/D146622
    Fixes https://github.com/llvm/llvm-project/issues/61615
    Reviewed By: nikic
2023-05-12 19:02:28 +09:00
Jordan Rupprecht
e08c397a88 Revert "[AggressiveInstCombine] folding load for constant global patterened arrays and structs by GEP-indices Differential Revision: https://reviews.llvm.org/D146622 Fixes https://github.com/llvm/llvm-project/issues/61615"
This reverts commit 0574a4be879e07b48ba9be8d63eebba49a04dfe8. It causes a compiler crash due to a div by zero.
2023-05-09 10:38:46 -07:00
khei4
0574a4be87 [AggressiveInstCombine] folding load for constant global patterened arrays and structs by GEP-indices Differential Revision: https://reviews.llvm.org/D146622 Fixes https://github.com/llvm/llvm-project/issues/61615 2023-05-09 23:22:21 +09:00
Arthur Eubanks
ed443d81d1 [AggressiveInstCombine] Only fold consecutive shifts of loads with constant shift amounts
This is what the code assumed but never actually checked.

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

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D149896
2023-05-04 13:52:25 -07:00
khei4
434b0badb5 [AggressiveInstCombine] folding load for constant global patterened arrays and structs by alignment
Differential Revision: https://reviews.llvm.org/D144445
Reviewed By: nikic

fix: wrong arrow
2023-03-23 23:31:22 +09:00
khei4
c7a3284de3 [AggressiveInstCombine] Pre-Commit test for D144445 (NFC)
Differential Revision: https://reviews.llvm.org/D145355

tweak: test
2023-03-23 23:31:22 +09:00
chenglin.bi
76df706bca Revert "[LogicCombine 1/?] Implement a general way to simplify logical operations."
This reverts commit 97dcbea63e11d566cff0cd3a758cf1114cf1f633.
2023-03-14 09:00:06 +08:00
chenglin.bi
97dcbea63e [LogicCombine 1/?] Implement a general way to simplify logical operations.
This patch involves boolean ring to simplify logical operations. We can treat `&` as ring multiplication and `^` as ring addition.
So we need to canonicalize all other operations to `*` `+`. Like:
```
a & b -> a * b
a ^ b -> a + b
~a -> a + 1
a | b -> a * b + a + b
c ? a : b -> c * a + (c + 1) * b
```
In the code, we use a mask set to represent an expression. Every value that is not comes from logical operations could be a bit in the mask.
The mask itself is a multiplication chain. The mask set is an addiction chain.
We can calculate two expressions based on boolean algebras.

For now, the initial patch only enabled on and/or/xor,  Later we can enhance the code step by step.

Reference: https://en.wikipedia.org/wiki/Boolean_ring

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D142803
2023-03-02 20:46:16 +08:00
Zhongyunde
15d5c59280 [InstCombine] Improvement the analytics through the dominating condition
Address the dominating condition, the urem fold is benefit from the analytics improvements.
Fix https://github.com/llvm/llvm-project/issues/60546

NOTE: delete the calls in simplifyBinaryIntrinsic and foldICmpWithDominatingICmp
is used to reduce compile time.

Reviewed By: nikic, arsenm, erikdesjardins
Differential Revision: https://reviews.llvm.org/D144248
2023-03-01 17:03:34 +08: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
chenglin.bi
2738dc0bd3 [ComplexLogicCombine] Precommit tests for complex logic combine init patch; NFC 2023-02-17 09:34:15 +08:00
Nikita Popov
cdfb99b069 [AggressiveInstCombine] Convert tests to opaque pointers (NFC) 2022-12-23 09:47:48 +01:00
Paul Walker
f53234cbfd [AggressiveInstCombine] Fix invalid TypeSize conversion when combining loads.
Much of foldLoadsRecursive relies on knowing the size of loaded
data, which is not possible for scalable vector types.  However,
the logic of combining two small loads into one bigger load does
not apply for vector types so rather than converting the algorithm
to use TypeSize I've simply added an early exit for vectors.

Fixes #59510

Differential Revision: https://reviews.llvm.org/D140106
2022-12-17 15:34:27 +00:00
bipmis
e9393789a9 [AggressiveInstCombine] Handle the insert point of the merged load correctly.
This patch updates the load insert point of the merged load in AggressiveInstCombine().
This is done to handle the reported test breaks by handling Alias Analysis correctly.

Differential Revision: https://reviews.llvm.org/D137201
2022-11-29 10:53:51 +00:00
bipmis
ee53abb070 Add more tests for Reverse Load and AA testing 2022-11-28 15:34:26 +00:00
bipmis
150fc73dda [AggressiveInstCombine] Avoid load merge/widen if stores are present b/w loads
This patch is to address the test cases in which the load has to be inserted at a right point. This happens when there is a store b/w the loads.

This patch reverts the loads merge in all cases when stores are present b/w loads and will eventually be replaced with proper fix and test cases.

Differential Revision: https://reviews.llvm.org/D137333
2022-11-03 14:32:07 +00:00
bipmis
3ee1882299 Add another test which breaks the load insert point 2022-11-03 12:28:24 +00:00
bipmis
cc7b03b01e Add tests which need right Insert Point for merged load 2022-11-01 21:49:44 +00:00
bipmis
38f3e44997 [AggressiveInstCombine] Load merge the reverse load pattern of consecutive loads.
This patch extends the load merge/widen in AggressiveInstCombine() to handle reverse load patterns.

Differential Revision: https://reviews.llvm.org/D135137
2022-10-19 11:22:58 +01:00
Bjorn Pettersson
8f527e08a5 [test][AggressiveInstCombine] Use -passes syntax in RUN lines. NFC 2022-10-13 10:44:37 +02:00
bipmis
8344dfab59 Add reverse load pattern tests 2022-10-04 10:39:41 +01:00
bipmis
3b49a9fcf6 [AggressiveInstCombine] Combine consecutive loads which are being merged to form a wider load.
The patch simplifies some of the patterns as below

1. (ZExt(L1) << shift1) | (ZExt(L2) << shift2) -> ZExt(L3) << shift1
2. (ZExt(L1) << shift1) | ZExt(L2) -> ZExt(L3)

The pattern is indicative of the fact that the loads are being merged to a wider load and the only use of this pattern is with a wider load. In this case for a non-atomic/non-volatile loads reduce the pattern to a combined load which would improve the cost of inlining, unrolling, vectorization etc.

Fix the error reported on reverse load merge.

Differential Revision: https://reviews.llvm.org/D127392
2022-09-28 17:32:47 +01:00
bipmis
48b8dee773 remove LE,BE labels inserted incorrectly 2022-09-28 17:07:26 +01:00
bipmis
1dd7e576d7 Add reverse load tests to test load combine patch 2022-09-28 16:51:23 +01:00
Dmitri Gribenko
954d3cd2c6 Revert "[AggressiveInstCombine] Combine consecutive loads which are being merged to form a wider load."
This reverts commit 3c70c8c1df66500f67f77596b1e76cf0a8447ee5.

After this commit, during the 3-stage bootstrap the second-stage Clang
crashes.
2022-09-23 19:21:09 +02:00
bipmis
3c70c8c1df [AggressiveInstCombine] Combine consecutive loads which are being merged to form a wider load.
The patch simplifies some of the patterns as below

1. (ZExt(L1) << shift1) | (ZExt(L2) << shift2) -> ZExt(L3) << shift1
2. (ZExt(L1) << shift1) | ZExt(L2) -> ZExt(L3)

The pattern is indicative of the fact that the loads are being merged to a wider load and the only use of this pattern is with a wider load. In this case for a non-atomic/non-volatile loads reduce the pattern to a combined load which would improve the cost of inlining, unrolling, vectorization etc.

Differential Revision: https://reviews.llvm.org/D127392
2022-09-23 10:19:50 +01:00
bipmis
dd48c0be55 Add Load merge tests to AggressiveInstCombine 2022-09-22 21:55:54 +01:00
Djordje Todorovic
f0f8b46863 Recommit "[AggressiveInstCombine] Lower Table Based CTTZ
The bug reported on the [0] has been fixed.
The issue was we have not checked if the global variables that
represent cttz tables was constant.
There is a new negative test added in negative-lower-table-based-cttz.ll
that represents this.

[0] https://reviews.llvm.org/rGdf868edee561eb973edd85ec9df41c67aa0bff6b
2022-09-20 13:12:47 +02:00
Djordje Todorovic
b080d0bae8 Revert ""Recommit "[AggressiveInstCombine] Lower Table Based CTTZ"""
This reverts commit df868edee561eb973edd85ec9df41c67aa0bff6b, as it
introduces a bug found by Alive2 (more on the rGdf868edee561).
2022-09-12 08:23:07 +02:00
Djordje Todorovic
df868edee5 "Recommit "[AggressiveInstCombine] Lower Table Based CTTZ""
This reverts commit 053841c5624ca7eacd108a26071d8a1cefe1bebd.

We faced a use-after-free after pushing the D113291, since the
foldSqrt() has a call to eraseFromParent(). The function
should be at the end of the main loop that folds the patterns.
This patch fixes that.
2022-09-09 10:29:39 +02:00
Djordje Todorovic
7aec9ddcfd Revert "Recommit "[AggressiveInstCombine] Lower Table Based CTTZ""
This reverts commit f87993915768772d113bfd524347ce4341b843cf.
2022-09-08 17:01:16 +02:00
Djordje Todorovic
f879939157 Recommit "[AggressiveInstCombine] Lower Table Based CTTZ" 2022-09-08 16:36:46 +02:00
Richard Smith
053841c562 Revert "[AggressiveInstCombine] Lower Table Based CTTZ"
This reverts commit fec01ee3f5244bb9a04bc4310fc892c56c5b6bab.

According to asan, this patch introduces a heap use after free.
2022-09-02 16:19:09 -07:00
Djordje Todorovic
fec01ee3f5 [AggressiveInstCombine] Lower Table Based CTTZ
This patch introduces recognition of table-based ctz implementation
during the AggressiveInstCombine.

This fixes the [0].

[0] https://bugs.llvm.org/show_bug.cgi?id=46434

Differential Revision: https://reviews.llvm.org/D113291
2022-09-02 17:26:55 +02:00
Sanjay Patel
e079bf6558 [AggressiveInstCombine] check sqrt operand to allow more libcall->intrinsic transforms
This should fix issue #56383 (at least when compiled with -O3 because this pass is only
run at -O3 currently).
2022-07-27 11:36:13 -04:00