llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-driver

@llvm/pr-subscribers-flang-fir-hlfir

Author: Tatsuhito Abe (tatsuhito-fj)

<details>
<summary>Changes</summary>

Add a scope option to SimplifyHLFIRIntrinsics and adjust the pipeline to enable 
SUM expansion at -O0 while keeping other intrinsic expansions conditional on 
array expression optimization. This makes simple summation the default for SUM 
expansion across optimization levels.

Previously, floating-point SUM used the runtime's Kahan summation at -O0, 
whereas -O1 and higher generally generated loops with simple sequential 
addition. This expansion substituted a different algorithm rather than inlining 
the runtime implementation, causing numerical results to depend on the 
optimization level.

Add -fcompensated-sum to preserve the runtime's compensated algorithm for REAL 
and COMPLEX SUM. When enabled, exclude SUM from HLFIR intrinsic simplification 
and prevent SimplifyIntrinsics from replacing real SUM runtime calls with 
uncompensated reduction loops.

Fixes #<!-- -->176282

---

Patch is 33.24 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/244546.diff


19 Files Affected:

- (modified) clang/include/clang/Options/FlangOptions.td (+3) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+2) 
- (modified) flang/include/flang/Frontend/CodeGenOptions.def (+1) 
- (modified) flang/include/flang/Optimizer/HLFIR/Passes.h (+11) 
- (modified) flang/include/flang/Optimizer/HLFIR/Passes.td (+24-1) 
- (modified) flang/include/flang/Optimizer/Transforms/Passes.td (+5-1) 
- (modified) flang/include/flang/Tools/CrossToolHelpers.h (+2) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+3) 
- (modified) flang/lib/Frontend/FrontendActions.cpp (+1) 
- (modified) flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp 
(+50-38) 
- (modified) flang/lib/Optimizer/Passes/Pipelines.cpp (+18-6) 
- (modified) flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp (+3) 
- (modified) flang/test/Driver/array-runtime.f90 (+23-9) 
- (added) flang/test/Driver/compensated-sum.f90 (+14) 
- (modified) flang/test/Driver/mlir-debug-pass-pipeline.f90 (+5) 
- (added) flang/test/HLFIR/simplify-hlfir-intrinsics-scope.fir (+36) 
- (modified) 
flang/test/Integration/OpenMP/parallel-private-reduction-worstcase.f90 (+31-16) 
- (added) flang/test/Integration/compensated-sum.f90 (+60) 
- (added) flang/test/Transforms/simplifyintrinsics-compensated-sum.fir (+39) 


``````````diff
diff --git a/clang/include/clang/Options/FlangOptions.td 
b/clang/include/clang/Options/FlangOptions.td
index ad39d052bee6af..e1b8c2c42e6e6a 100644
--- a/clang/include/clang/Options/FlangOptions.td
+++ b/clang/include/clang/Options/FlangOptions.td
@@ -335,6 +335,9 @@ def fcheck_integer_mod_zero_divisor
     : Flag<["-"], "fcheck-integer-mod-zero-divisor">, Group<f_Group>,
       HelpText<"Check for a zero divisor in integer MOD and MODULO">;
 
+def fcompensated_sum : Flag<["-"], "fcompensated-sum">, Group<f_Group>,
+  HelpText<"Use compensated algorithm for SUM intrinsic for REAL and COMPLEX 
types">;
+
 defm fp_sum_reassociation
     : BoolOptionWithoutMarshalling<
           "f", "fp-sum-reassociation",
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 522907b58022fb..ed3cbbfe06abf5 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -391,6 +391,8 @@ void Flang::addCodegenOptions(const ArgList &Args,
   Args.AddLastArg(CmdArgs, options::OPT_ffp_sum_reassociation,
                   options::OPT_fno_fp_sum_reassociation);
 
+  Args.AddLastArg(CmdArgs, options::OPT_fcompensated_sum);
+
   Args.addOptInFlag(CmdArgs, options::OPT_funique_internal_linkage_names,
                     options::OPT_fno_unique_internal_linkage_names);
 
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 5043003feec1df..423ff7b0eda288 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -65,6 +65,7 @@ CODEGENOPT(DebugInfoForProfiling, 1, 0)  ///< Emit extra 
debug info to make samp
 CODEGENOPT(PseudoProbeForProfiling, 1, 0) ///< Emit pseudo probes for sample 
profiling.
 CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Append MD5 hash to internal 
linkage symbols.
 CODEGENOPT(ImplicitDefaultMapperAllocatableMembers, 1, 1) ///< Map allocatable 
members in generated OpenMP default mappers.
+CODEGENOPT(CompensatedSum, 1, 0) ///< Use compensated algorithm for SUM for 
REAL and COMPLEX.
 
 CODEGENOPT(Underscoring, 1, 1)
 ENUM_CODEGENOPT(FPMaxminBehavior, Fortran::common::FPMaxminBehavior, 2, 
Fortran::common::FPMaxminBehavior::Legacy)
diff --git a/flang/include/flang/Optimizer/HLFIR/Passes.h 
b/flang/include/flang/Optimizer/HLFIR/Passes.h
index d009a31582470a..3d9e4b12e06ff5 100644
--- a/flang/include/flang/Optimizer/HLFIR/Passes.h
+++ b/flang/include/flang/Optimizer/HLFIR/Passes.h
@@ -21,6 +21,17 @@
 #include <memory>
 
 namespace hlfir {
+  /// Specifies the scope to which SimplifyHLFIRIntrinsics applies.
+  enum class HLFIRIntrinsicSimplificationScope {
+    /// Apply SimplifyHLFIRIntrinsics to all intrinsics.
+    All,
+    /// Apply SimplifyHLFIRIntrinsics only to sum intrinsics.
+    SumOnly,
+    /// Apply SimplifyHLFIRIntrinsics to all intrinsics except sum intrinsics.
+    ExceptSum,
+    /// Do not apply SimplifyHLFIRIntrinsics to any intrinsics.
+    None,
+  };
 #define GEN_PASS_DECL
 #define GEN_PASS_REGISTRATION
 #include "flang/Optimizer/HLFIR/Passes.h.inc"
diff --git a/flang/include/flang/Optimizer/HLFIR/Passes.td 
b/flang/include/flang/Optimizer/HLFIR/Passes.td
index e0221c655834fe..b31f0ca75a6a63 100644
--- a/flang/include/flang/Optimizer/HLFIR/Passes.td
+++ b/flang/include/flang/Optimizer/HLFIR/Passes.td
@@ -75,7 +75,30 @@ def SimplifyHLFIRIntrinsics : 
Pass<"simplify-hlfir-intrinsics"> {
                clEnumValN(Fortran::common::FPMaxminBehavior::Extremum,
                           "extremum", "arith.max/minimumf"),
                clEnumValN(Fortran::common::FPMaxminBehavior::ExtremeNum,
-                          "extremenum", "arith.max/minnumf"))}]>];
+                          "extremenum", "arith.max/minnumf"))}]>,
+                 Option<"scope", "scope",
+                        "::hlfir::HLFIRIntrinsicSimplificationScope",
+                        
/*default=*/"::hlfir::HLFIRIntrinsicSimplificationScope::"
+                                    "All",
+                        "Select which HLFIR intrinsic operations to simplify",
+                        [{::llvm::cl::values(
+                          clEnumValN(
+                            ::hlfir::HLFIRIntrinsicSimplificationScope::All,
+                            "all",
+                            "Simplify all supported HLFIR intrinsic 
operations"),
+                          clEnumValN(
+                            
::hlfir::HLFIRIntrinsicSimplificationScope::SumOnly,
+                            "only-sum",
+                            "Simplify only hlfir.sum operations"),
+                          clEnumValN(
+                            
::hlfir::HLFIRIntrinsicSimplificationScope::ExceptSum,
+                            "except-sum",
+                            "Simplify all supported HLFIR intrinsic operations 
"
+                            "except hlfir.sum"),
+                          clEnumValN(
+                            ::hlfir::HLFIRIntrinsicSimplificationScope::None,
+                            "none",
+                            "Do not simplify any HLFIR intrinsic 
operations"))}]>];
 }
 
 def ExpressionSimplification : Pass<"hlfir-expression-simplification"> {
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td 
b/flang/include/flang/Optimizer/Transforms/Passes.td
index 34354eb3f6fede..55480d2cc308ae 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.td
+++ b/flang/include/flang/Optimizer/Transforms/Passes.td
@@ -298,7 +298,11 @@ def SimplifyIntrinsics : Pass<"simplify-intrinsics", 
"mlir::ModuleOp"> {
   let options = [
     Option<"enableExperimental", "enable-experimental", "bool",
            /*default=*/"false",
-           "Enable experimental code that may not always work correctly">
+           "Enable experimental code that may not always work correctly">,
+    Option<"compensatedSum", "compensated-sum", "bool",
+           /*default=*/"false",
+           "Preserve runtime calls that use compensated summation for "
+           "floating-point SUM">
   ];
 }
 
diff --git a/flang/include/flang/Tools/CrossToolHelpers.h 
b/flang/include/flang/Tools/CrossToolHelpers.h
index 0b11c6be04946c..4f66cff187c998 100644
--- a/flang/include/flang/Tools/CrossToolHelpers.h
+++ b/flang/include/flang/Tools/CrossToolHelpers.h
@@ -150,11 +150,13 @@ struct MLIRToLLVMPassPipelineConfig : public 
FlangEPCallBacks {
     SplitDwarfFile = opts.SplitDwarfFile;
     DwarfDebugFlags = opts.DwarfDebugFlags;
     DebugNameTable = opts.getDebugNameTable();
+    CompensatedSum = opts.CompensatedSum;
   }
 
   llvm::OptimizationLevel OptLevel; ///< optimisation level
   /// Enable HLFIR optimizations; expensive ones still require O3.
   bool optimizeArrayExpression;
+  bool CompensatedSum = false; ///< Preserve compensated real/complex SUM.
   bool StackArrays = false; ///< convert memory allocations to alloca.
   bool EnableSafeTrampoline{false}; ///< Use runtime trampoline pool (W^X).
   bool Underscoring = true; ///< add underscores to function names.
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index efbb938f6b5975..dc4ebdd74cc0ae 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -605,6 +605,9 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
           << arg->getAsString(args) << arg->getValue();
     }
   }
+
+  if (args.hasArg(clang::options::OPT_fcompensated_sum))
+    opts.CompensatedSum = 1;
 }
 
 /// Parses all target input arguments and populates the target
diff --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index d7f6658668a40c..1bf5d4787911ce 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -650,6 +650,7 @@ void CodeGenAction::lowerHLFIRToFIR() {
   if (ci.getInvocation().getLangOpts().OpenMPSimd)
     enableOpenMP = fir::EnableOpenMP::Simd;
   MLIRToLLVMPassPipelineConfig config(level);
+  config.CompensatedSum = opts.CompensatedSum;
   config.fpMaxminBehavior =
       ci.getInvocation().getLoweringOpts().getFPMaxminBehavior();
   // Give plugins a chance to register passes at the extension points.
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp 
b/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp
index 9fbc05dda264a6..34495e836f82f8 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp
@@ -3442,44 +3442,56 @@ class SimplifyHLFIRIntrinsics
         mlir::GreedySimplifyRegionLevel::Disabled);
 
     mlir::RewritePatternSet patterns(context);
-    patterns.insert<TransposeAsElementalConversion>(context);
-    patterns.insert<ReductionConversion<hlfir::SumOp>>(context);
-    patterns.insert<ReductionConversion<hlfir::ProductOp>>(context);
-    patterns.insert<ArrayShiftConversion<hlfir::CShiftOp>>(context);
-    patterns.insert<ArrayShiftConversion<hlfir::EOShiftOp>>(context);
-    patterns.insert<CmpCharOpConversion>(context);
-    patterns.insert<IndexOpConversion>(context);
-    patterns.insert<CharTrimOpConversion>(context);
-    patterns.insert<MatmulConversion<hlfir::MatmulTransposeOp>>(context);
-    patterns.insert<ReductionConversion<hlfir::CountOp>>(context);
-    patterns.insert<ReductionConversion<hlfir::AnyOp>>(context);
-    patterns.insert<ReductionConversion<hlfir::AllOp>>(context);
-    patterns.insert<ExtremumReductionConversion<hlfir::MaxlocOp>>(
-        context, this->fpMaxminBehavior);
-    patterns.insert<ExtremumReductionConversion<hlfir::MinlocOp>>(
-        context, this->fpMaxminBehavior);
-    patterns.insert<ExtremumReductionConversion<hlfir::MaxvalOp>>(
-        context, this->fpMaxminBehavior);
-    patterns.insert<ExtremumReductionConversion<hlfir::MinvalOp>>(
-        context, this->fpMaxminBehavior);
-
-    // If forceMatmulAsElemental is false, then hlfir.matmul inlining
-    // will introduce hlfir.eval_in_mem operation with new memory side
-    // effects. This conflicts with CSE and optimized bufferization, e.g.:
-    //   A(1:N,1:N) =  A(1:N,1:N) - MATMUL(...)
-    // If we introduce hlfir.eval_in_mem before CSE, then the current
-    // MLIR CSE won't be able to optimize the trivial loads of 'N' value
-    // that happen before and after hlfir.matmul.
-    // If 'N' loads are not optimized, then the optimized bufferization
-    // won't be able to prove that the slices of A are identical
-    // on both sides of the assignment.
-    // This is actually the CSE problem, but we can work it around
-    // for the time being.
-    if (forceMatmulAsElemental || this->allowNewSideEffects)
-      patterns.insert<MatmulConversion<hlfir::MatmulOp>>(context);
-
-    patterns.insert<DotProductConversion>(context);
-    patterns.insert<ReshapeAsElementalConversion>(context);
+
+    const bool simplifySum =
+        this->scope == hlfir::HLFIRIntrinsicSimplificationScope::All ||
+        this->scope == hlfir::HLFIRIntrinsicSimplificationScope::SumOnly;
+    const bool simplifyOtherIntrinsics =
+        this->scope == hlfir::HLFIRIntrinsicSimplificationScope::All ||
+        this->scope == hlfir::HLFIRIntrinsicSimplificationScope::ExceptSum;
+
+    if (simplifySum)
+      patterns.insert<ReductionConversion<hlfir::SumOp>>(context);
+
+    if (simplifyOtherIntrinsics) {
+      patterns.insert<TransposeAsElementalConversion>(context);
+      patterns.insert<ReductionConversion<hlfir::ProductOp>>(context);
+      patterns.insert<ArrayShiftConversion<hlfir::CShiftOp>>(context);
+      patterns.insert<ArrayShiftConversion<hlfir::EOShiftOp>>(context);
+      patterns.insert<CmpCharOpConversion>(context);
+      patterns.insert<IndexOpConversion>(context);
+      patterns.insert<CharTrimOpConversion>(context);
+      patterns.insert<MatmulConversion<hlfir::MatmulTransposeOp>>(context);
+      patterns.insert<ReductionConversion<hlfir::CountOp>>(context);
+      patterns.insert<ReductionConversion<hlfir::AnyOp>>(context);
+      patterns.insert<ReductionConversion<hlfir::AllOp>>(context);
+      patterns.insert<ExtremumReductionConversion<hlfir::MaxlocOp>>(
+          context, this->fpMaxminBehavior);
+      patterns.insert<ExtremumReductionConversion<hlfir::MinlocOp>>(
+          context, this->fpMaxminBehavior);
+      patterns.insert<ExtremumReductionConversion<hlfir::MaxvalOp>>(
+          context, this->fpMaxminBehavior);
+      patterns.insert<ExtremumReductionConversion<hlfir::MinvalOp>>(
+          context, this->fpMaxminBehavior);
+
+      // If forceMatmulAsElemental is false, then hlfir.matmul inlining
+      // will introduce hlfir.eval_in_mem operation with new memory side
+      // effects. This conflicts with CSE and optimized bufferization, e.g.:
+      //   A(1:N,1:N) =  A(1:N,1:N) - MATMUL(...)
+      // If we introduce hlfir.eval_in_mem before CSE, then the current
+      // MLIR CSE won't be able to optimize the trivial loads of 'N' value
+      // that happen before and after hlfir.matmul.
+      // If 'N' loads are not optimized, then the optimized bufferization
+      // won't be able to prove that the slices of A are identical
+      // on both sides of the assignment.
+      // This is actually the CSE problem, but we can work it around
+      // for the time being.
+      if (forceMatmulAsElemental || this->allowNewSideEffects)
+        patterns.insert<MatmulConversion<hlfir::MatmulOp>>(context);
+
+      patterns.insert<DotProductConversion>(context);
+      patterns.insert<ReshapeAsElementalConversion>(context);
+    }
 
     if (mlir::failed(mlir::applyPatternsGreedily(
             getOperation(), std::move(patterns), config))) {
diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp 
b/flang/lib/Optimizer/Passes/Pipelines.cpp
index 55a0b85618a707..919f2f6ff4e5ba 100644
--- a/flang/lib/Optimizer/Passes/Pipelines.cpp
+++ b/flang/lib/Optimizer/Passes/Pipelines.cpp
@@ -12,6 +12,7 @@
 #include "flang/Optimizer/Passes/Pipelines.h"
 #include "flang/Optimizer/Builder/MIFCommon.h"
 #include "flang/Optimizer/Dialect/FIROps.h"
+#include "flang/Optimizer/HLFIR/Passes.h"
 #include "flang/Optimizer/OpenACC/Passes.h"
 #include "mlir/Conversion/Passes.h"
 #include "mlir/Dialect/LLVMIR/Transforms/Passes.h"
@@ -208,7 +209,8 @@ void createDefaultFIRPreCFGOptimizerPassPipeline(
   pm.addPass(fir::createSimplifyRegionLite());
   if (pc.OptLevel != llvm::OptimizationLevel::O0) {
     // These passes may increase code size.
-    pm.addPass(fir::createSimplifyIntrinsics());
+    pm.addPass(fir::createSimplifyIntrinsics(
+        {/*enableExperimental=*/false, pc.CompensatedSum}));
     pm.addPass(fir::createAlgebraicSimplificationPass(config));
     if (enableConstantArgumentGlobalisation)
       pm.addPass(fir::createConstantArgumentGlobalisationOpt());
@@ -318,11 +320,21 @@ void createHLFIRToFIRPassPipeline(mlir::PassManager &pm,
     addNestedPassToAllTopLevelOperations<PassConstructor>(
         pm, hlfir::createExpressionSimplification);
     addCanonicalizerPassWithoutRegionSimplification(pm);
-    addNestedPassToAllTopLevelOperations(pm, [&]() {
-      return hlfir::createSimplifyHLFIRIntrinsics(
-          {/*allowNewSideEffects=*/false, config.fpMaxminBehavior});
-    });
   }
+
+  using ScopeKind = hlfir::HLFIRIntrinsicSimplificationScope;
+  ScopeKind scope;
+  if (config.CompensatedSum)
+    scope =
+        config.optimizeArrayExpression ? ScopeKind::ExceptSum : 
ScopeKind::None;
+  else
+    scope =
+        config.optimizeArrayExpression ? ScopeKind::All : ScopeKind::SumOnly;
+
+  addNestedPassToAllTopLevelOperations(pm, [&]() {
+    return hlfir::createSimplifyHLFIRIntrinsics(
+        {/*allowNewSideEffects=*/false, config.fpMaxminBehavior, scope});
+  });
   addNestedPassToAllTopLevelOperations<PassConstructor>(
       pm, hlfir::createInlineElementals);
   addNestedPassToAllTopLevelOperations<PassConstructor>(
@@ -334,7 +346,7 @@ void createHLFIRToFIRPassPipeline(mlir::PassManager &pm,
     // and allow introducing operations with new side effects.
     addNestedPassToAllTopLevelOperations(pm, [&]() {
       return hlfir::createSimplifyHLFIRIntrinsics(
-          {/*allowNewSideEffects=*/true, config.fpMaxminBehavior});
+          {/*allowNewSideEffects=*/true, config.fpMaxminBehavior, scope});
     });
     addNestedPassToAllTopLevelOperations<PassConstructor>(
         pm, hlfir::createPropagateFortranVariableAttributes);
diff --git a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp 
b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
index 78cb92ed9a8fa5..5a983942fef227 100644
--- a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
+++ b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
@@ -1290,6 +1290,9 @@ void SimplifyIntrinsicsPass::runOnOperation() {
         //                int dim, const Descriptor *mask)
         //
         if (funcName.starts_with(RTNAME_STRING(Sum))) {
+          if (this->compensatedSum && call.getNumResults() == 1 &&
+              mlir::isa<mlir::FloatType>(call.getResult(0).getType()))
+            return;
           simplifyIntOrFloatReduction(call, kindMap, genRuntimeSumBody);
           return;
         }
diff --git a/flang/test/Driver/array-runtime.f90 
b/flang/test/Driver/array-runtime.f90
index 9acec878fb3da2..e20f201c800f05 100644
--- a/flang/test/Driver/array-runtime.f90
+++ b/flang/test/Driver/array-runtime.f90
@@ -1,5 +1,6 @@
-! Numeric broadcasts to non-allocatable arrays are expanded even at -O0.
-! Other array operations retain the optimization-level-dependent default.
+! Numeric broadcasts to non-allocatable arrays and SUM reductions are expanded
+! even at -O0. Other array operations retain the optimization-level-dependent
+! default.
 ! RUN: %flang_fc1 -emit-fir -O0 %s -o - | FileCheck %s 
--check-prefixes=ALL,RUNTIME
 ! RUN: %flang_fc1 -emit-fir -O1 %s -o - | FileCheck %s 
--check-prefixes=ALL,EXPAND
 ! RUN: %flang_fc1 -emit-fir -O2 %s -o - | FileCheck %s 
--check-prefixes=ALL,EXPAND
@@ -52,14 +53,27 @@ subroutine array_expression(x, y, z)
 ! EXPAND-NOT: fir.call @_FortranAAssign
 ! ALL: return
 
-function reduction(x)
-  real :: x(:), reduction
-  reduction = sum(x)
+function sum_reduction(x)
+  real :: x(:), sum_reduction
+  sum_reduction = sum(x)
 end function
 
-! ALL-LABEL: func{{(\.func)?}} @_QPreduction(
-! RUNTIME: fir.call @_FortranASumReal4
-! EXPAND-NOT: fir.call @_FortranASum
+! ALL-LABEL: func{{(\.func)?}} @_QPsum_reduction(
+! ALL-NOT: fir.call @_FortranASum
+! ALL: fir.do_loop
+! ALL: arith.addf
+! ALL-NOT: fir.call @_FortranASum
+! ALL: return
+
+function product_reduction(x)
+  real :: x(:), product_reduction
+  product_reduction = product(x)
+end function
+
+! ALL-LABEL: func{{(\.func)?}} @_QPproduct_reduction(
+! RUNTIME: fir.call @_FortranAProductReal4
+! EXPAND-NOT: fir.call @_FortranAProduct
 ! EXPAND: fir.do_loop
-! EXPAND-NOT: fir.call @_FortranASum
+! EXPAND: arith.mulf
+! EXPAND-NOT: fir.call @_FortranAProduct
 ! ALL: return
diff --git a/flang/test/Driver/compensated-sum.f90 
b/flang/test/Driver/compensated-sum.f90
new file mode 100644
index 00000000000000..f9a56b78821a9a
--- /dev/null
+++ b/flang/test/Driver/compensated-sum.f90
@@ -0,0 +1,14 @@
+! Test driver handling of -fcompensated-sum.
+
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
+! RUN:   | FileCheck %s --check-prefix=OMITTED
+
+! RUN: %flang -fsyntax-only -### %s -o %t 2>&1 \
+! RUN:     -fcompensated-sum \
+! RUN:   | FileCheck %s --check-prefix=ENABLED
+
+! OMITTED: "-fc1"
+! OMITTED-NOT: "-fcompensated-sum"
+
+! ENABLED: "-fc1"
+! ENABLED: "-fcompensated-sum"
diff --git a/flang/test/Driver/mlir-debug-pass-pipeline.f90 
b/flang/test/Driver/mlir-debug-pass-pipeline.f90
index 25fdc4ee557809..b395d4974e74b6 100644
--- a/flang/test/Driver/mlir-debug-pass-pipeline.f90
+++ b/flang/test/Driver/mlir-debug-pass-pipeline.f90
@@ -29,22 +29,27 @@
 ! ALL: Fortran::lower::VerifierPass
 ! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 
'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
 ! ALL-NEXT: 'fir.global' Pipeline
+! ALL-NEXT:   SimplifyHLFIRIntrinsics
 ! ALL-NEXT:   InlineElementals
 ! ALL-NEXT:   SeparateAllocatableAssign
 ! ALL-NEXT:   InlineHLFIRAssign
 ! ALL-NEXT: 'func.func' Pipeline
+! ALL-NEXT:   SimplifyHLFIRIntrinsics
 ! ALL-NEXT:   InlineElementals
 ! ALL-NEXT:   SeparateAllocatableAssign
 ! ALL-NEXT:   InlineHLFI...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/244546
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to