[flang-commits] [flang] [flang] Inline minval/maxval over elemental/designate (PR #103503)
via flang-commits
flang-commits at lists.llvm.org
Wed Aug 14 19:51:58 PDT 2024
================
@@ -712,17 +757,66 @@ static mlir::Value generateReductionLoop(fir::FirOpBuilder &builder,
/// %c = <reduce count> %i
/// fir.result %c
template <typename Op>
-class ReductionElementalConversion : public mlir::OpRewritePattern<Op> {
+class ReductionConversion : public mlir::OpRewritePattern<Op> {
public:
using mlir::OpRewritePattern<Op>::OpRewritePattern;
llvm::LogicalResult
matchAndRewrite(Op op, mlir::PatternRewriter &rewriter) const override {
mlir::Location loc = op.getLoc();
- hlfir::ElementalOp elemental =
- op.getMask().template getDefiningOp<hlfir::ElementalOp>();
- if (!elemental || op.getDim())
- return rewriter.notifyMatchFailure(op, "Did not find valid elemental");
+ // Select source and validate its arguments.
+ mlir::Value source;
+ bool valid = false;
+ if constexpr (std::is_same_v<Op, hlfir::AnyOp> ||
+ std::is_same_v<Op, hlfir::AllOp> ||
+ std::is_same_v<Op, hlfir::CountOp>) {
+ source = op.getMask();
+ valid = !op.getDim();
+ } else if constexpr (std::is_same_v<Op, hlfir::MaxvalOp> ||
----------------
khaki3 wrote:
I believe we should keep this PR minimum. Supporting all the cases will follow later on.
>The mask operand is not handled
It is complicated, but any/all/count's default argument is named mask. This operand acts as a mask over itself.
https://github.com/llvm/llvm-project/pull/103503
More information about the flang-commits
mailing list