30 Commits

Author SHA1 Message Date
Jeremy Morse
f33f66be7d [NFC][RemoveDIs] Always use iterators for inserting PHIs
It's becoming potentially unsafe to insert a PHI instruction using a plain
Instruction pointer. Switch all the remaining sites that create and insert
PHIs to use iterators instead. For example, the code in
ComplexDeinterleavingPass.cpp is definitely at-risk of mixing PHIs and
debug-info.
2024-03-05 17:00:12 +00:00
Florian Hahn
4c9223c770
[ComplexDeinterleaving] Use MapVector to fix codegen non-determinism. 2023-09-06 15:57:35 +01:00
Igor Kirillov
e2cb07c322 [CodeGen] Fix incorrect insertion point selection for reduction nodes in ComplexDeinterleavingPass
When replacing ComplexDeinterleavingPass::ReductionOperation, we can do it
either from the Real or Imaginary part. The correct way is to take whichever
is later in the BasicBlock, but before the patch, we just always took the
Real part.

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

Differential Revision: https://reviews.llvm.org/D159209
2023-08-31 10:38:01 +00:00
Igor Kirillov
46b2ad0224 [CodeGen] Improve speed of ComplexDeinterleaving pass
Cache all results of running `identifyNode`, even those that do not identify
potential complex operations. This patch prevents ComplexDeinterleaving pass
from repeatedly trying to identify Nodes for the same pair of instructions.

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

Differential Revision: https://reviews.llvm.org/D156916
2023-08-04 14:11:43 +00:00
Igor Kirillov
c15557d64e [CodeGen] Extend ComplexDeinterleaving pass to recognise patterns using integer types
AArch64 introduced CMLA and CADD instructions as part of SVE2. This
change allows to generate such instructions when this architecture
feature is available.

Differential Revision: https://reviews.llvm.org/D153808
2023-07-19 11:01:19 +00:00
Igor Kirillov
0aecf7ff0d [CodeGen] Fix incorrectly detected reduction bug in ComplexDeinterleaving pass
Using ACLE intrinsics, it is possible to create a loop that the
deinterleaving pass incorrectly classified as a reduction loop.
For example, for fixed-width vectors the loop was like below:

vector.body:
  %a = phi <4 x float> [ %init.a, %entry ], [ %updated.a, %vector.body ]
  %b = phi <4 x float> [ %init.b, %entry ], [ %updated.b, %vector.body ]
  ...
; Does not depend on %a or %b:
  %updated.a = ...
  %updated.b = ...

Differential Revision: https://reviews.llvm.org/D154598
2023-07-10 12:54:38 +00:00
Igor Kirillov
7f20407cee [CodeGen] Add support for Splats in ComplexDeinterleaving pass
This commit allows generating of complex number intrinsics for expressions
with constants or loops invariants, which are represented as splats.
For instance, after vectorizing loops in the following code snippets,
the ComplexDeinterleaving pass will be able to generate complex number
intrinsics:

```
complex<> x = ...;
for (int i = 0; i < N; ++i)
    c[i] = a[i] * b[i] * x;
```

or

```
for (int i = 0; i < N; ++i)
    c[i] = a[i] * b[i] * (11.0 + 3.0i);
```

Differential Revision: https://reviews.llvm.org/D153355
2023-07-05 17:02:52 +00:00
Igor Kirillov
b4f9c3a933 [CodeGen] Refactor ComplexDeinterleaving to run identification on Values instead of Instructions
This change will make it easier to add identification of complex constants
in future patches.

Differential Revision: https://reviews.llvm.org/D153446
2023-07-03 10:35:14 +00:00
Wang, Xin10
c78acc9275 [NFC]Fix possibly derefer nullptr in ComplexDeinterleavingPass.cpp
Fix static analyzer reports issue, add assert to avoid analyzer report.

Reviewed By: igor.kirillov

Differential Revision: https://reviews.llvm.org/D153942
2023-06-28 23:26:09 -04:00
Igor Kirillov
1fce8df53a Fix the ComplexDeinterleaving bug when handling mixed reductions.
Add a missing check that ensures that ComplexDeinterleaving for reduction
is only analyzed for Real and Imaginary Instructions of the same type.

Differential Revision: https://reviews.llvm.org/D153862
2023-06-27 14:40:49 +00:00
Igor Kirillov
04a8070b46 Revert "Revert "[CodeGen] Extend reduction support in ComplexDeinterleaving pass to support predication""
Adds the capability to recognize SelectInst that appear in the IR.
These instructions are generated during scalable vectorization for reduction
and when the code contains conditions inside the loop body or when
"-prefer-predicate-over-epilogue=predicate-dont-vectorize" is set.

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

This reverts commit ab09654832dba5cef8baa6400fdfd3e4d1495624.

Reason: Reapplying after removing unnecessary default case in switch expression.
2023-06-23 10:13:22 +00:00
Vitaly Buka
ab09654832 Revert "[CodeGen] Extend reduction support in ComplexDeinterleaving pass to support predication"
ComplexDeinterleavingPass.cpp:1849:3: error: default label in switch which covers all enumeration values

This reverts commit 116953b82130df1ebd817b3587b16154f659c013.
2023-06-22 11:29:38 -07:00
Igor Kirillov
116953b821 [CodeGen] Extend reduction support in ComplexDeinterleaving pass to support predication
Adds the capability to recognize SelectInst that appear in the IR.
These instructions are generated during scalable vectorization for reduction
and when the code contains conditions inside the loop body or when
"-prefer-predicate-over-epilogue=predicate-dont-vectorize" is set.

Differential Revision: https://reviews.llvm.org/D152558
2023-06-22 16:49:40 +00:00
Kazu Hirata
c97ab93dca [CodeGen] Fix a warning
This patch fixes:

  llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp:1790:3: error:
  default label in switch which covers all enumeration values
  [-Werror,-Wcovered-switch-default]
2023-06-14 10:53:11 -07:00
Igor Kirillov
2cbc265cc9 [CodeGen] Add support for reductions in ComplexDeinterleaving pass
This commit enhances the ComplexDeinterleaving pass to handle unordered
reductions in simple one-block vectorized loops, supporting both
SVE and Neon architectures.

Differential Revision: https://reviews.llvm.org/D152022
2023-06-14 17:27:26 +00:00
Igor Kirillov
1a1e76100e [CodeGen] Improve handling -Ofast generated code by ComplexDeinterleaving pass
Code generated with -Ofast and -O3 -ffp-contract=fast (add
-ffinite-math-only to enable vectorization) can differ significantly.
Code compiled with -O3 can be deinterleaved using patterns as the
instruction order is preserved. However, with the -Ofast flag, there
can be multiple changes in the computation sequence, and even the real
and imaginary parts may not be calculated in parallel.
For more details, refer to
llvm/test/CodeGen/AArch64/complex-deinterleaving-*-fast.ll and
llvm/test/CodeGen/AArch64/complex-deinterleaving-*-contract.ll tests.
This patch implements a more general approach and enables handling most
-Ofast cases.

Differential Revision: https://reviews.llvm.org/D148558
2023-05-31 18:31:38 +00:00
Igor Kirillov
40a81d3100 [CodeGen] Refactor IR generation functions to use IRBuilder in ComplexDeinterleaving pass
This patch updates several functions in LLVM's IR generation code to accept
an IRBuilder object as an argument, rather than an Instruction that indicates
the insertion point for new instructions.
This change is necessary to handle sophisticated -Ofast optimization cases
from D148558 where it's unclear which instructions should be used as the
insertion point for new operations.

Differential Revision: https://reviews.llvm.org/D148703
2023-05-30 16:18:28 +00:00
Elliot Goodrich
ac73c48e09 [llvm] Reduce ComplexDeinterleavingPass.h includes
Remove the unnecessary `"llvm/IR/PatternMatch.h"` include directive from
`ComplexDeinterleavingPass.h` and move it to the corresponding source
file.

Add missing includes that were transitively included by this header to 3
other source files.

This reduces the total number of preprocessing tokens across the LLVM
source files in `lib` from (roughly) 1,964,876,961 to 1,935,091,611 - a
reduction of ~1.52%. This should result in a small improvement in
compilation time.
2023-05-20 17:49:18 +01:00
Elliot Goodrich
b7fb2a3fec Revert "[llvm] Reduce ComplexDeinterleavingPass.h includes"
This reverts commit 058ca5c07106d38ad66e3ec4972a613a64e88151.
2023-05-20 14:21:07 +01:00
Elliot Goodrich
058ca5c071 [llvm] Reduce ComplexDeinterleavingPass.h includes
Remove the unnecessary `"llvm/IR/PatternMatch.h"` include directive from
`ComplexDeinterleavingPass.h` and move it to the corresponding source
file.

Add missing includes that were transitively included by this header to 2
other source files.

This reduces the total number of preprocessing tokens across the LLVM
source files in `lib` from (roughly) 1,964,876,961 to 1,935,091,611 - a
reduction of ~1.52%. This should result in a small improvement in
compilation time.

Differential Revision: https://reviews.llvm.org/D150514
2023-05-20 13:36:50 +01:00
Igor Kirillov
6850bc35c6 [CodeGen] Enable AArch64 SVE FCMLA/FCADD instruction generation in ComplexDeinterleaving
This commit adds support for scalable vector types in theComplexDeinterleaving
pass, allowing it to recognize and handle `llvm.vector.interleave2` and
`llvm.vector.deinterleave2` intrinsics for both fixed and scalable vectors

Differential Revision: https://reviews.llvm.org/D147451
2023-04-21 09:58:35 +00:00
Akshay Khadse
aab0ca3e79 Fix uninitialized scalar members in CodeGen
This change fixes some static code analysis warnings.

Reviewed By: LuoYuanke

Differential Revision: https://reviews.llvm.org/D148811
2023-04-21 12:22:34 +08:00
Igor Kirillov
c692e87ab8 [CodeGen] Enable processing of interconnected complex number operations
With this patch, ComplexDeinterleavingPass now has the ability to handle
any number of interconnected operations involving complex numbers.
For example, the patch enables the processing of code like the following:

for (int i = 0; i < 1000; ++i) {
    a[i] =  w[i] * v[i];
    b[i] =  w[i] * u[i];
}

This code has multiple arrays containing complex numbers and a common
subexpression `w` that appears in two expressions.

Differential Revision: https://reviews.llvm.org/D146988
2023-04-18 13:05:49 +00:00
Akshay Khadse
8bf7f86d79 Fix uninitialized pointer members in CodeGen
This change initializes the members TSI, LI, DT, PSI, and ORE pointer feilds of the SelectOptimize class to nullptr.

Reviewed By: LuoYuanke

Differential Revision: https://reviews.llvm.org/D148303
2023-04-17 16:32:46 +08:00
David Green
dc764a2e2d [ComplexDeinterleaving] Propagate fast math flags to symmetric operations.
This is a simple patch to make sure fast math flags are propagated through to
the newly created symmetric operations, which can help with later
simplifications.

Differential Revision: https://reviews.llvm.org/D146409
2023-03-28 12:12:02 +01:00
Nicholas Guy
96615c856d [Codegen][ARM][AArch64] Support symmetric operations on complex numbers
Differential Revision: https://reviews.llvm.org/D142482
2023-03-14 12:11:10 +00:00
Nicholas Guy
49384f1411 Cleanup of Complex Deinterleaving pass (NFCI)
Differential Revision: https://reviews.llvm.org/D143177
2023-03-14 12:11:09 +00:00
Kazu Hirata
4501133d96 Ensure newlines at the end of files (NFC) 2022-12-16 23:36:51 -08:00
Nicholas Guy
a3dc5b534a [ARM][CodeGen] Add integer support for complex deinterleaving
Differential Revision: https://reviews.llvm.org/D139628
2022-12-12 11:38:19 +00:00
Nicholas Guy
d52e2839f3 [ARM][CodeGen] Add support for complex deinterleaving
Adds the Complex Deinterleaving Pass implementing support for complex numbers in a target-independent manner, deferring to the TargetLowering for the given target to create a target-specific intrinsic.

Differential Revision: https://reviews.llvm.org/D114174
2022-11-14 14:02:27 +00:00