Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ namespace hlfir {
#include "flang/Optimizer/HLFIR/Passes.h.inc"
} // namespace hlfir

static llvm::cl::opt<bool>
simplifySum("flang-simplify-hlfir-sum",
llvm::cl::desc("Expand hlfir.sum into an inline sequence"),
llvm::cl::init(false));
namespace {

class TransposeAsElementalConversion
Expand Down Expand Up @@ -349,6 +353,8 @@ class SimplifyHLFIRIntrinsics
// expanding the SUM into a total reduction loop nest
// would avoid creating a temporary for the elemental array expression.
target.addDynamicallyLegalOp<hlfir::SumOp>([](hlfir::SumOp sum) {
if (!simplifySum)
return true;
if (mlir::Value dim = sum.getDim()) {
if (auto dimVal = fir::getIntIfConstant(dim)) {
if (!fir::isa_trivial(sum.getType())) {
Expand Down
2 changes: 1 addition & 1 deletion flang/test/HLFIR/simplify-hlfir-intrinsics-sum.fir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: fir-opt --simplify-hlfir-intrinsics %s | FileCheck %s
// RUN: fir-opt --simplify-hlfir-intrinsics -flang-simplify-hlfir-sum %s | FileCheck %s

// box with known extents
func.func @sum_box_known_extents(%arg0: !fir.box<!fir.array<2x3xi32>>) {
Expand Down
Loading