21 Commits

Author SHA1 Message Date
Tom Eccles
44c0bdb402
[flang][HLFIR] Use GreedyPatternRewriter in LowerHLFIRIntrinsics (#83438)
In #83253 @matthias-springer pointed out that LowerHLFIRIntrinsics.cpp
should not be using rewrite patterns with the dialect conversion driver.

The intention of this pass is to lower HLFIR intrinsic operations into
FIR so it conceptually fits dialect conversion. However, dialect
conversion is much stricter about changing types when replacing
operations. This pass sometimes looses track of array bounds, resulting
in replacements with operations with different but compatible types
(expressions of the same rank and element types but with or without
compile time known array bounds). This is difficult to accommodate with
the dialect conversion driver and so I have changed to use the greedy
pattern rewriter.

There is a lot of test churn because the greedy pattern rewriter also
performs canonicalization.
2024-03-01 10:16:27 +00:00
Matthias Springer
1f74f5f48b
[flang] Fix flang build after #83132 (#83253)
This fix is a temporary workaround. `LowerHLFIRIntrinsics.cpp` should be
using the greedy pattern rewriter or a manual IR traversal. All patterns
in this file are rewrite patterns. The test failure was caused by
`replaceAllUsesWith`, which is not supported by the dialect conversion;
additional asserts were added recently to prevent incorrect API usage.
These trigger now.

Alternatively, turning the patterns into conversion patterns and
specifying a type converter may work.

Failing test case:
`Fortran/gfortran/regression/gfortran-regression-compile-regression__inline_matmul_14_f90.test`
2024-02-28 14:05:06 +01:00
David Green
2812cb065a
[Flang] HLFIR maxloc intrinsic (#75450)
Similar to minloc from #74436, this adds a hlfir maxloc intrinsic so
that we can keep them symmetrical. It's just a bit of copy and pasting.
2023-12-15 09:32:15 +00:00
David Green
34eee5d647
[Flang] Remove kind from CountOp (#75466)
The kind is already represented in the return type of the operation.
Like we did for minloc, this removes the kind parameter from CountOp.
2023-12-15 09:31:52 +00:00
David Green
a216115433
[Flang] Add a HLFIR Minloc intrinsic (#74436)
The adds a hlfir minloc intrinsic, similar to the minval intrinsic
already added, to help in the lowering of minloc. The idea is to later
add maxloc too, and from there add a simplification for producing minloc
with inlined elemental and hopefully less temporaries.
2023-12-12 12:39:21 +00:00
Yusuke MINATO
4eafb5f57c
[flang][hlfir] Add hlfir.minval intrinsic (#66306)
Adds a new HLFIR operation for the MINVAL intrinsic according to the
design set out in flang/docs/HighLevelFIR.md.
2023-09-15 18:30:06 +09:00
Yusuke MINATO
2318bc878a
[flang][hlfir] Add hlfir.maxval intrinsic (#65705)
Adds a new HLFIR operation for the MAXVAL intrinsic according to the
design set out in flang/docs/HighLevelFIR.md.
2023-09-12 17:21:40 +09:00
Slava Zakharin
60f02aa7f7 [flang][hlfir] Fixed KindMapping for HLFIR intrinsics lowering.
hlfir.count lowering was using incorrect default integer kind
by ignoring the kind specified in the ModuleOp.

Reviewed By: tblah

Differential Revision: https://reviews.llvm.org/D156017
2023-07-24 10:12:39 -07:00
Slava Zakharin
8c33630e15 [flang][hlfir] Added missing fir.convert for i1 result of hlfir.dot_product.
Some operations using the result of hlfir.dot_product can tolerate
that the type of the result changes from !fir.logical to i1 during
intrinsics lowering, but some won't. I added a separate LIT case with
fir.store to mimic one of the nag tests.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D155914
2023-07-21 12:56:51 -07:00
Kiran Chandramohan
fe705c3426 [Flang][HLFIR] Intrinsics: Propagate fast math flags
Add a new FirOpBuilder constructor to propagate the fast math flag
from an operation. Use this constructor in the LowerHLFIRIntrinsics
pass.

This fixes the performance issue with the hlfir intrinsics flow
for polyhedron/test_fpu2.

Reviewed By: tblah, vzakhari

Differential Revision: https://reviews.llvm.org/D155438
2023-07-18 09:26:59 +00:00
Jacob Crawley
3f8d8c1aac [flang][hlfir] Add hlfir.count intrinsic
Adds a new HLFIR operation for the COUNT intrinsic according to
the design set out in flang/docs/HighLevel.md. This patch includes all
the necessary changes to create a new HLFIR operation and lower it into
the fir runtime call.

Author was @jacob-crawley. Minor adjustments by @tblah

Differential Revision: https://reviews.llvm.org/D152521
2023-06-19 09:09:26 +00:00
Tom Eccles
7c8ef818f8 [flang][hlfir] allow recursive intrinsic lowering
We need to allow recursive application of intrinsic lowering patterns,
otherwise we cannot lower nested calls of the same intrinsic e.g.
matmul(matmul(a, b), c).

matmul(matmul(a, b), matmul(c, d)) requires hlfir.associate of hlfir
expr with more than one use (TODO).

Differential Revision: https://reviews.llvm.org/D152284
2023-06-10 14:36:07 +00:00
Tom Eccles
ef086a7d1b Revert "[flang][hlfir] allow recursive intrinsic lowering"
This reverts commit 6bcfab3161ea3a90b26dce3f85ba052933060b73.

Reverting because this breaks the build with MSVC
2023-06-07 15:24:31 +00:00
Tom Eccles
6bcfab3161 [flang][hlfir] allow recursive intrinsic lowering
We need to allow recursive application of intrinsic lowering patterns,
otherwise we cannot lower nested calls of the same intrinsic e.g.
matmul(matmul(a, b), c).

matmul(matmul(a, b), matmul(c, d)) requires hlfir.associate of hlfir
expr with more than one use (TODO).

Differential Revision: https://reviews.llvm.org/D152284
2023-06-07 14:36:14 +00:00
Jacob Crawley
9471637f3c [flang][hlfir] Add hlfir.dot_product intrinsic
Adds a new HLFIR operation for the DOT_PRODUCT intrinsic according to
the design set out in flang/docs/HighLevel.md. This patch includes all
the necessary changes to create a new HLFIR operation and lower it into
the fir runtime call.

Differential Revision: https://reviews.llvm.org/D152252
2023-06-07 11:42:14 +00:00
Jacob Crawley
8a6dadaad0 [flang][hlfir] lower hlfir.all into runtime call
Depends on: D151111

Differential Revision: https://reviews.llvm.org/D151415
2023-05-30 14:46:06 +00:00
Jacob Crawley
b5d1ea9d2b [flang][hlfir] lower hlfir.any into fir runtime call
Depends on: D150272

Differential Revision: https://reviews.llvm.org/D150451
2023-05-15 09:32:23 +00:00
Jacob Crawley
7c57195c49 [flang][hlfir] lower hlfir.product into fir runtime call
The shared code for lowering the sum and product operations in
flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp have
been moved into a new class HlfirReductionIntrinsicConverion.

Depends on: D148719

Differential Revision: https://reviews.llvm.org/D149644
2023-05-04 11:23:38 +00:00
Tom Eccles
43eb96cab8 [flang][hlfir] lower hlfir.matmul_transpose to runtime call
Depends on D145960

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D145961
2023-03-17 09:30:04 +00:00
Tom Eccles
3e0f6b2eb4 [flang][hlfir] clean up intrinsic arg extended values
Depends on D145502

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D145503
2023-03-17 09:30:04 +00:00
Tom Eccles
9cbeb97024 [flang][hlfir] move intrinsic lowering out of BufferizeHLFIR
This move is useful for a few reasons:
  - It is easier to see what the intrinsic lowering is doing when the
    operations it creates are not immediately lowered
  - When lowering a HLFIR intrinsic generates an operation which needs
    to be lowered by another pattern matcher in the same pass, MLIR will
    run that other substitution before validating and finalizing the
    original changes. This means that the erasure of operations is not
    yet visible to subsequent matchers, which hugely complicates
    transformations (in this case, hlfir.exprs cannot be rewritten
    because they are still used by the now-erased HLFIR intrinsic op.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D145502
2023-03-17 09:30:04 +00:00