[flang-commits] [flang] [flang] Inline minval/maxval over elemental/designate (PR #103503)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Thu Aug 15 08:02:57 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> ||
----------------
vzakhari wrote:
I meant that the `maxval` and `minval` operations may have a mask operand. I do not see this operand being handled anywhere (maybe I missed it). We cannot just ignore it, so I suggest that we disallow the optimization if this operand is present.
https://github.com/llvm/llvm-project/pull/103503
More information about the flang-commits
mailing list