[flang-commits] [flang] [flang] add simplification for ProductOp intrinsic (PR #169575)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Wed Nov 26 07:04:21 PST 2025
================
@@ -931,6 +932,37 @@ class SumAsElementalConverter
mlir::Value genScalarAdd(mlir::Value value1, mlir::Value value2);
};
+/// Reduction converter for Product.
+class ProductAsElementalConverter
+ : public NumericReductionAsElementalConverterBase<hlfir::ProductOp> {
+ using Base = NumericReductionAsElementalConverterBase;
+
+public:
+ ProductAsElementalConverter(hlfir::ProductOp op,
+ mlir::PatternRewriter &rewriter)
+ : Base{op, rewriter} {}
+
+private:
+ virtual llvm::SmallVector<mlir::Value> genReductionInitValues(
+ [[maybe_unused]] mlir::ValueRange oneBasedIndices,
+ [[maybe_unused]] const llvm::SmallVectorImpl<mlir::Value> &extents)
+ final {
+ return {fir::factory::createOneValue(builder, loc, getResultElementType())};
+ }
+ virtual llvm::SmallVector<mlir::Value>
+ reduceOneElement(const llvm::SmallVectorImpl<mlir::Value> ¤tValue,
+ hlfir::Entity array,
+ mlir::ValueRange oneBasedIndices) final {
+ checkReductions(currentValue);
+ hlfir::Entity elementValue =
+ hlfir::loadElementAt(loc, builder, array, oneBasedIndices);
+ return {genScalarMult(currentValue[0], elementValue)};
+ }
+
+ // Generate scalar addition of the two values (of the same data type).
----------------
eugeneepshteyn wrote:
"multiplication"
https://github.com/llvm/llvm-project/pull/169575
More information about the flang-commits
mailing list