diff --git a/flang/include/flang/Optimizer/Transforms/Passes.h b/flang/include/flang/Optimizer/Transforms/Passes.h --- a/flang/include/flang/Optimizer/Transforms/Passes.h +++ b/flang/include/flang/Optimizer/Transforms/Passes.h @@ -23,6 +23,7 @@ namespace fir { std::unique_ptr createExternalNameConversionPass(); +std::unique_ptr createMemDataFlowOptPass(); /// Support for inlining on FIR. bool canLegallyInline(mlir::Operation *op, mlir::Region *reg, diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -24,4 +24,17 @@ let constructor = "::fir::createExternalNameConversionPass()"; } +def MemRefDataFlowOpt : FunctionPass<"fir-memref-dataflow-opt"> { + let summary = + "Perform store/load forwarding and potentially removing dead stores."; + let description = [{ + This pass performs store to load forwarding to eliminate memory accesses and + potentially the entire allocation if all the accesses are forwarded. + }]; + let constructor = "::fir::createMemDataFlowOptPass()"; + let dependentDialects = [ + "fir::FIROpsDialect", "mlir::StandardOpsDialect" + ]; +} + #endif // FLANG_OPTIMIZER_TRANSFORMS_PASSES diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt b/flang/lib/Optimizer/Transforms/CMakeLists.txt --- a/flang/lib/Optimizer/Transforms/CMakeLists.txt +++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt @@ -1,6 +1,7 @@ add_flang_library(FIRTransforms Inliner.cpp ExternalNameConversion.cpp + MemRefDataFlowOpt.cpp DEPENDS FIRDialect diff --git a/flang/lib/Optimizer/Transforms/MemRefDataFlowOpt.cpp b/flang/lib/Optimizer/Transforms/MemRefDataFlowOpt.cpp new file mode 100644 --- /dev/null +++ b/flang/lib/Optimizer/Transforms/MemRefDataFlowOpt.cpp @@ -0,0 +1,130 @@ +//===- MemRefDataFlowOpt.cpp - Memory DataFlow Optimization pass ----------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "PassDetail.h" +#include "flang/Optimizer/Dialect/FIRDialect.h" +#include "flang/Optimizer/Dialect/FIROps.h" +#include "flang/Optimizer/Dialect/FIRType.h" +#include "flang/Optimizer/Transforms/Passes.h" +#include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/IR/Dominance.h" +#include "mlir/IR/Operation.h" +#include "mlir/Transforms/Passes.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" + +#define DEBUG_TYPE "fir-memref-dataflow-opt" + +namespace { + +template +static std::vector getSpecificUsers(mlir::Value v) { + std::vector ops; + for (mlir::Operation *user : v.getUsers()) + if (auto op = dyn_cast(user)) + ops.push_back(op); + return ops; +} + +/// This is based on MLIR's MemRefDataFlowOpt which is specialized on AffineRead +/// and AffineWrite interface +template +class LoadStoreForwarding { +public: + LoadStoreForwarding(mlir::DominanceInfo *di) : domInfo(di) {} + + // FIXME: This algorithm has a bug. It ignores escaping references between a + // store and a load. + llvm::Optional findStoreToForward(ReadOp loadOp, + std::vector &&storeOps) { + llvm::SmallVector candidateSet; + + for (fir::StoreOp storeOp : storeOps) + if (domInfo->dominates(storeOp, loadOp)) + candidateSet.push_back(storeOp); + + if (candidateSet.empty()) + return {}; + + llvm::Optional nearestStore; + for (auto candidate : candidateSet) { + auto nearerThan = [&](WriteOp otherStore) { + if (candidate == otherStore) + return false; + auto rv = domInfo->properlyDominates(candidate, otherStore); + if (rv) { + LLVM_DEBUG(llvm::dbgs() + << "candidate " << candidate << " is not the nearest to " + << loadOp << " because " << otherStore << " is closer\n"); + } + return rv; + }; + if (!llvm::any_of(candidateSet, nearerThan)) { + nearestStore = mlir::cast(candidate); + break; + } + } + if (!nearestStore) { + LLVM_DEBUG( + llvm::dbgs() + << "load " << loadOp << " has " << candidateSet.size() + << " store candidates, but this algorithm can't find a best.\n"); + } + return nearestStore; + } + + llvm::Optional findReadForWrite(WriteOp writeOp, + std::vector &&readOps) { + for (ReadOp readOp : readOps) { + if (domInfo->dominates(writeOp, readOp)) + return readOp; + } + return {}; + } + +private: + mlir::DominanceInfo *domInfo; +}; + +class MemDataFlowOpt : public fir::MemRefDataFlowOptBase { +public: + void runOnFunction() override { + mlir::FuncOp f = getFunction(); + + auto *domInfo = &getAnalysis(); + LoadStoreForwarding lsf(domInfo); + f.walk([&](fir::LoadOp loadOp) { + auto maybeStore = lsf.findStoreToForward( + loadOp, getSpecificUsers(loadOp.memref())); + if (maybeStore) { + fir::StoreOp storeOp = maybeStore.getValue(); + LLVM_DEBUG(llvm::dbgs() << "FlangMemDataFlowOpt: In " << f.getName() + << " erasing load " << loadOp + << " with value from " << storeOp << '\n'); + loadOp.getResult().replaceAllUsesWith(storeOp.value()); + loadOp.erase(); + } + }); + f.walk([&](fir::AllocaOp alloca) { + for (auto &storeOp : getSpecificUsers(alloca.getResult())) { + if (!lsf.findReadForWrite( + storeOp, getSpecificUsers(storeOp.memref()))) { + LLVM_DEBUG(llvm::dbgs() << "FlangMemDataFlowOpt: In " << f.getName() + << " erasing store " << storeOp << '\n'); + storeOp.erase(); + } + } + }); + } +}; +} // namespace + +std::unique_ptr fir::createMemDataFlowOptPass() { + return std::make_unique(); +} diff --git a/flang/test/Fir/memref-data-flow.fir b/flang/test/Fir/memref-data-flow.fir new file mode 100644 --- /dev/null +++ b/flang/test/Fir/memref-data-flow.fir @@ -0,0 +1,1158 @@ +// RUN: fir-opt --split-input-file --fir-memref-dataflow-opt %s | FileCheck %s + +func @_QPf1dc(%arg0: !fir.ref>, %arg1: !fir.ref>, %arg2: !fir.ref>) { + %c1_i64 = constant 1 : i64 + %c60 = constant 60 : index + %c0 = constant 0 : index + %c1 = constant 1 : index + %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFf1dcEi"} + %1 = fir.alloca !fir.array<60xi32> {bindc_name = "t1", uniq_name = "_QFf1dcEt1"} + br ^bb1(%c1, %c60 : index, index) +^bb1(%2: index, %3: index): // 2 preds: ^bb0, ^bb2 + %4 = cmpi sgt, %3, %c0 : index + cond_br %4, ^bb2, ^bb3 +^bb2: // pred: ^bb1 + %5 = fir.convert %2 : (index) -> i32 + fir.store %5 to %0 : !fir.ref + %6 = fir.load %0 : !fir.ref + %7 = fir.convert %6 : (i32) -> i64 + %8 = subi %7, %c1_i64 : i64 + %9 = fir.coordinate_of %arg0, %8 : (!fir.ref>, i64) -> !fir.ref + %10 = fir.load %9 : !fir.ref + %11 = addi %10, %10 : i32 + %12 = fir.coordinate_of %1, %8 : (!fir.ref>, i64) -> !fir.ref + fir.store %11 to %12 : !fir.ref + %13 = addi %2, %c1 : index + %14 = subi %3, %c1 : index + br ^bb1(%13, %14 : index, index) +^bb3: // pred: ^bb1 + %15 = fir.convert %2 : (index) -> i32 + fir.store %15 to %0 : !fir.ref + br ^bb4(%c1, %c60 : index, index) +^bb4(%16: index, %17: index): // 2 preds: ^bb3, ^bb5 + %18 = cmpi sgt, %17, %c0 : index + cond_br %18, ^bb5, ^bb6 +^bb5: // pred: ^bb4 + %19 = fir.convert %16 : (index) -> i32 + fir.store %19 to %0 : !fir.ref + %20 = fir.load %0 : !fir.ref + %21 = fir.convert %20 : (i32) -> i64 + %22 = subi %21, %c1_i64 : i64 + %23 = fir.coordinate_of %1, %22 : (!fir.ref>, i64) -> !fir.ref + %24 = fir.load %23 : !fir.ref + %25 = fir.coordinate_of %arg1, %22 : (!fir.ref>, i64) -> !fir.ref + %26 = fir.load %25 : !fir.ref + %27 = muli %24, %26 : i32 + %28 = fir.coordinate_of %arg2, %22 : (!fir.ref>, i64) -> !fir.ref + fir.store %27 to %28 : !fir.ref + %29 = addi %16, %c1 : index + %30 = subi %17, %c1 : index + br ^bb4(%29, %30 : index, index) +^bb6: // pred: ^bb4 + %31 = fir.convert %16 : (index) -> i32 + fir.store %31 to %0 : !fir.ref + return +} + +// CHECK: func @_QPf1dc(%[[VAL_0:.*]]: !fir.ref>, %[[VAL_1:.*]]: !fir.ref>, %[[VAL_2:.*]]: !fir.ref>) { +// CHECK: %[[VAL_3:.*]] = constant 1 : i64 +// CHECK: %[[VAL_4:.*]] = constant 60 : index +// CHECK: %[[VAL_5:.*]] = constant 0 : index +// CHECK: %[[VAL_6:.*]] = constant 1 : index +// CHECK: %[[VAL_7:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFf1dcEi"} +// CHECK: %[[VAL_8:.*]] = fir.alloca !fir.array<60xi32> {bindc_name = "t1", uniq_name = "_QFf1dcEt1"} +// CHECK: br ^bb1(%[[VAL_6]], %[[VAL_4]] : index, index) +// CHECK: ^bb1(%[[VAL_9:.*]]: index, %[[VAL_10:.*]]: index): +// CHECK: %[[VAL_11:.*]] = cmpi sgt, %[[VAL_10]], %[[VAL_5]] : index +// CHECK: cond_br %[[VAL_11]], ^bb2, ^bb3 +// CHECK: ^bb2: +// CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_9]] : (index) -> i32 +// CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_12]] : (i32) -> i64 +// CHECK: %[[VAL_14:.*]] = subi %[[VAL_13]], %[[VAL_3]] : i64 +// CHECK: %[[VAL_15:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_14]] : (!fir.ref>, i64) -> !fir.ref +// CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_15]] : !fir.ref +// CHECK: %[[VAL_17:.*]] = addi %[[VAL_16]], %[[VAL_16]] : i32 +// CHECK: %[[VAL_18:.*]] = fir.coordinate_of %[[VAL_8]], %[[VAL_14]] : (!fir.ref>, i64) -> !fir.ref +// CHECK: fir.store %[[VAL_17]] to %[[VAL_18]] : !fir.ref +// CHECK: %[[VAL_19:.*]] = addi %[[VAL_9]], %[[VAL_6]] : index +// CHECK: %[[VAL_20:.*]] = subi %[[VAL_10]], %[[VAL_6]] : index +// CHECK: br ^bb1(%[[VAL_19]], %[[VAL_20]] : index, index) +// CHECK: ^bb3: +// CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_9]] : (index) -> i32 +// CHECK: br ^bb4(%[[VAL_6]], %[[VAL_4]] : index, index) +// CHECK: ^bb4(%[[VAL_22:.*]]: index, %[[VAL_23:.*]]: index): +// CHECK: %[[VAL_24:.*]] = cmpi sgt, %[[VAL_23]], %[[VAL_5]] : index +// CHECK: cond_br %[[VAL_24]], ^bb5, ^bb6 +// CHECK: ^bb5: +// CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_22]] : (index) -> i32 +// CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (i32) -> i64 +// CHECK: %[[VAL_27:.*]] = subi %[[VAL_26]], %[[VAL_3]] : i64 +// CHECK: %[[VAL_28:.*]] = fir.coordinate_of %[[VAL_8]], %[[VAL_27]] : (!fir.ref>, i64) -> !fir.ref +// CHECK: %[[VAL_29:.*]] = fir.load %[[VAL_28]] : !fir.ref +// CHECK: %[[VAL_30:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_27]] : (!fir.ref>, i64) -> !fir.ref +// CHECK: %[[VAL_31:.*]] = fir.load %[[VAL_30]] : !fir.ref +// CHECK: %[[VAL_32:.*]] = muli %[[VAL_29]], %[[VAL_31]] : i32 +// CHECK: %[[VAL_33:.*]] = fir.coordinate_of %[[VAL_2]], %[[VAL_27]] : (!fir.ref>, i64) -> !fir.ref +// CHECK: fir.store %[[VAL_32]] to %[[VAL_33]] : !fir.ref +// CHECK: %[[VAL_34:.*]] = addi %[[VAL_22]], %[[VAL_6]] : index +// CHECK: %[[VAL_35:.*]] = subi %[[VAL_23]], %[[VAL_6]] : index +// CHECK: br ^bb4(%[[VAL_34]], %[[VAL_35]] : index, index) +// CHECK: ^bb6: +// CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_22]] : (index) -> i32 +// CHECK: return +// CHECK: } + +// ----- + +func @_QPf1dv(%arg0: !fir.ref>, %arg1: !fir.ref>, %arg2: !fir.ref>, %arg3: !fir.ref) { + %c1_i64 = constant 1 : i64 + %c0 = constant 0 : index + %c1 = constant 1 : index + %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFf1dvEi"} + %1 = fir.load %arg3 : !fir.ref + %2 = fir.convert %1 : (i32) -> index + %3 = fir.alloca !fir.array, %2 {bindc_name = "t1", uniq_name = "_QFf1dvEt1"} + br ^bb1(%c1, %2 : index, index) +^bb1(%4: index, %5: index): // 2 preds: ^bb0, ^bb2 + %6 = cmpi sgt, %5, %c0 : index + cond_br %6, ^bb2, ^bb3 +^bb2: // pred: ^bb1 + %7 = fir.convert %4 : (index) -> i32 + fir.store %7 to %0 : !fir.ref + %8 = fir.load %0 : !fir.ref + %9 = fir.convert %8 : (i32) -> i64 + %10 = subi %9, %c1_i64 : i64 + %11 = fir.coordinate_of %arg0, %10 : (!fir.ref>, i64) -> !fir.ref + %12 = fir.load %11 : !fir.ref + %13 = addi %12, %12 : i32 + %14 = fir.coordinate_of %3, %10 : (!fir.ref>, i64) -> !fir.ref + fir.store %13 to %14 : !fir.ref + %15 = addi %4, %c1 : index + %16 = subi %5, %c1 : index + br ^bb1(%15, %16 : index, index) +^bb3: // pred: ^bb1 + %17 = fir.convert %4 : (index) -> i32 + fir.store %17 to %0 : !fir.ref + %18 = fir.load %arg3 : !fir.ref + %19 = fir.convert %18 : (i32) -> index + br ^bb4(%c1, %19 : index, index) +^bb4(%20: index, %21: index): // 2 preds: ^bb3, ^bb5 + %22 = cmpi sgt, %21, %c0 : index + cond_br %22, ^bb5, ^bb6 +^bb5: // pred: ^bb4 + %23 = fir.convert %20 : (index) -> i32 + fir.store %23 to %0 : !fir.ref + %24 = fir.load %0 : !fir.ref + %25 = fir.convert %24 : (i32) -> i64 + %26 = subi %25, %c1_i64 : i64 + %27 = fir.coordinate_of %3, %26 : (!fir.ref>, i64) -> !fir.ref + %28 = fir.load %27 : !fir.ref + %29 = fir.coordinate_of %arg1, %26 : (!fir.ref>, i64) -> !fir.ref + %30 = fir.load %29 : !fir.ref + %31 = muli %28, %30 : i32 + %32 = fir.coordinate_of %arg2, %26 : (!fir.ref>, i64) -> !fir.ref + fir.store %31 to %32 : !fir.ref + %33 = addi %20, %c1 : index + %34 = subi %21, %c1 : index + br ^bb4(%33, %34 : index, index) +^bb6: // pred: ^bb4 + %35 = fir.convert %20 : (index) -> i32 + fir.store %35 to %0 : !fir.ref + return +} + +// CHECK: func @_QPf1dv(%[[VAL_0:.*]]: !fir.ref>, %[[VAL_1:.*]]: !fir.ref>, %[[VAL_2:.*]]: !fir.ref>, %[[VAL_3:.*]]: !fir.ref) { +// CHECK: %[[VAL_4:.*]] = constant 1 : i64 +// CHECK: %[[VAL_5:.*]] = constant 0 : index +// CHECK: %[[VAL_6:.*]] = constant 1 : index +// CHECK: %[[VAL_7:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFf1dvEi"} +// CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_3]] : !fir.ref +// CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (i32) -> index +// CHECK: %[[VAL_10:.*]] = fir.alloca !fir.array, %[[VAL_9]] {bindc_name = "t1", uniq_name = "_QFf1dvEt1"} +// CHECK: br ^bb1(%[[VAL_6]], %[[VAL_9]] : index, index) +// CHECK: ^bb1(%[[VAL_11:.*]]: index, %[[VAL_12:.*]]: index): +// CHECK: %[[VAL_13:.*]] = cmpi sgt, %[[VAL_12]], %[[VAL_5]] : index +// CHECK: cond_br %[[VAL_13]], ^bb2, ^bb3 +// CHECK: ^bb2: +// CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_11]] : (index) -> i32 +// CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_14]] : (i32) -> i64 +// CHECK: %[[VAL_16:.*]] = subi %[[VAL_15]], %[[VAL_4]] : i64 +// CHECK: %[[VAL_17:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_16]] : (!fir.ref>, i64) -> !fir.ref +// CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_17]] : !fir.ref +// CHECK: %[[VAL_19:.*]] = addi %[[VAL_18]], %[[VAL_18]] : i32 +// CHECK: %[[VAL_20:.*]] = fir.coordinate_of %[[VAL_10]], %[[VAL_16]] : (!fir.ref>, i64) -> !fir.ref +// CHECK: fir.store %[[VAL_19]] to %[[VAL_20]] : !fir.ref +// CHECK: %[[VAL_21:.*]] = addi %[[VAL_11]], %[[VAL_6]] : index +// CHECK: %[[VAL_22:.*]] = subi %[[VAL_12]], %[[VAL_6]] : index +// CHECK: br ^bb1(%[[VAL_21]], %[[VAL_22]] : index, index) +// CHECK: ^bb3: +// CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_11]] : (index) -> i32 +// CHECK: %[[VAL_24:.*]] = fir.load %[[VAL_3]] : !fir.ref +// CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_24]] : (i32) -> index +// CHECK: br ^bb4(%[[VAL_6]], %[[VAL_25]] : index, index) +// CHECK: ^bb4(%[[VAL_26:.*]]: index, %[[VAL_27:.*]]: index): +// CHECK: %[[VAL_28:.*]] = cmpi sgt, %[[VAL_27]], %[[VAL_5]] : index +// CHECK: cond_br %[[VAL_28]], ^bb5, ^bb6 +// CHECK: ^bb5: +// CHECK: %[[VAL_29:.*]] = fir.convert %[[VAL_26]] : (index) -> i32 +// CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_29]] : (i32) -> i64 +// CHECK: %[[VAL_31:.*]] = subi %[[VAL_30]], %[[VAL_4]] : i64 +// CHECK: %[[VAL_32:.*]] = fir.coordinate_of %[[VAL_10]], %[[VAL_31]] : (!fir.ref>, i64) -> !fir.ref +// CHECK: %[[VAL_33:.*]] = fir.load %[[VAL_32]] : !fir.ref +// CHECK: %[[VAL_34:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_31]] : (!fir.ref>, i64) -> !fir.ref +// CHECK: %[[VAL_35:.*]] = fir.load %[[VAL_34]] : !fir.ref +// CHECK: %[[VAL_36:.*]] = muli %[[VAL_33]], %[[VAL_35]] : i32 +// CHECK: %[[VAL_37:.*]] = fir.coordinate_of %[[VAL_2]], %[[VAL_31]] : (!fir.ref>, i64) -> !fir.ref +// CHECK: fir.store %[[VAL_36]] to %[[VAL_37]] : !fir.ref +// CHECK: %[[VAL_38:.*]] = addi %[[VAL_26]], %[[VAL_6]] : index +// CHECK: %[[VAL_39:.*]] = subi %[[VAL_27]], %[[VAL_6]] : index +// CHECK: br ^bb4(%[[VAL_38]], %[[VAL_39]] : index, index) +// CHECK: ^bb6: +// CHECK: %[[VAL_40:.*]] = fir.convert %[[VAL_26]] : (index) -> i32 +// CHECK: return +// CHECK: } + +// ----- + +func @_QPf2dc(%arg0: !fir.ref>, %arg1: !fir.ref>, %arg2: !fir.ref>) { + %c100_i32 = constant 100 : i32 + %c10000_i32 = constant 10000 : i32 + %c1_i64 = constant 1 : i64 + %c3 = constant 3 : index + %c0 = constant 0 : index + %c1 = constant 1 : index + %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFf2dcEi"} + %1 = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFf2dcEj"} + %2 = fir.alloca !fir.array<3x3xi32> {bindc_name = "t1", uniq_name = "_QFf2dcEt1"} + br ^bb1(%c1, %c3 : index, index) +^bb1(%3: index, %4: index): // 2 preds: ^bb0, ^bb5 + %5 = cmpi sgt, %4, %c0 : index + cond_br %5, ^bb2, ^bb6 +^bb2: // pred: ^bb1 + %6 = fir.convert %3 : (index) -> i32 + fir.store %6 to %0 : !fir.ref + br ^bb3(%c1, %c3 : index, index) +^bb3(%7: index, %8: index): // 2 preds: ^bb2, ^bb4 + %9 = cmpi sgt, %8, %c0 : index + cond_br %9, ^bb4, ^bb5 +^bb4: // pred: ^bb3 + %10 = fir.convert %7 : (index) -> i32 + fir.store %10 to %1 : !fir.ref + %11 = fir.load %0 : !fir.ref + %12 = fir.convert %11 : (i32) -> i64 + %13 = subi %12, %c1_i64 : i64 + %14 = fir.load %1 : !fir.ref + %15 = fir.convert %14 : (i32) -> i64 + %16 = subi %15, %c1_i64 : i64 + %17 = fir.coordinate_of %arg0, %13, %16 : (!fir.ref>, i64, i64) -> !fir.ref + %18 = fir.load %17 : !fir.ref + %19 = fir.coordinate_of %arg0, %16, %13 : (!fir.ref>, i64, i64) -> !fir.ref + %20 = fir.load %19 : !fir.ref + %21 = muli %20, %c100_i32 : i32 + %22 = addi %18, %21 : i32 + %23 = fir.coordinate_of %2, %13, %16 : (!fir.ref>, i64, i64) -> !fir.ref + fir.store %22 to %23 : !fir.ref + %24 = addi %7, %c1 : index + %25 = subi %8, %c1 : index + br ^bb3(%24, %25 : index, index) +^bb5: // pred: ^bb3 + %26 = fir.convert %7 : (index) -> i32 + fir.store %26 to %1 : !fir.ref + %27 = addi %3, %c1 : index + %28 = subi %4, %c1 : index + br ^bb1(%27, %28 : index, index) +^bb6: // pred: ^bb1 + %29 = fir.convert %3 : (index) -> i32 + fir.store %29 to %0 : !fir.ref + br ^bb7(%c1, %c3 : index, index) +^bb7(%30: index, %31: index): // 2 preds: ^bb6, ^bb11 + %32 = cmpi sgt, %31, %c0 : index + cond_br %32, ^bb8, ^bb12 +^bb8: // pred: ^bb7 + %33 = fir.convert %30 : (index) -> i32 + fir.store %33 to %0 : !fir.ref + br ^bb9(%c1, %c3 : index, index) +^bb9(%34: index, %35: index): // 2 preds: ^bb8, ^bb10 + %36 = cmpi sgt, %35, %c0 : index + cond_br %36, ^bb10, ^bb11 +^bb10: // pred: ^bb9 + %37 = fir.convert %34 : (index) -> i32 + fir.store %37 to %1 : !fir.ref + %38 = fir.load %0 : !fir.ref + %39 = fir.convert %38 : (i32) -> i64 + %40 = subi %39, %c1_i64 : i64 + %41 = fir.load %1 : !fir.ref + %42 = fir.convert %41 : (i32) -> i64 + %43 = subi %42, %c1_i64 : i64 + %44 = fir.coordinate_of %2, %40, %43 : (!fir.ref>, i64, i64) -> !fir.ref + %45 = fir.load %44 : !fir.ref + %46 = fir.coordinate_of %arg1, %40, %43 : (!fir.ref>, i64, i64) -> !fir.ref + %47 = fir.load %46 : !fir.ref + %48 = muli %47, %c10000_i32 : i32 + %49 = addi %45, %48 : i32 + %50 = fir.coordinate_of %arg2, %40, %43 : (!fir.ref>, i64, i64) -> !fir.ref + fir.store %49 to %50 : !fir.ref + %51 = addi %34, %c1 : index + %52 = subi %35, %c1 : index + br ^bb9(%51, %52 : index, index) +^bb11: // pred: ^bb9 + %53 = fir.convert %34 : (index) -> i32 + fir.store %53 to %1 : !fir.ref + %54 = addi %30, %c1 : index + %55 = subi %31, %c1 : index + br ^bb7(%54, %55 : index, index) +^bb12: // pred: ^bb7 + %56 = fir.convert %30 : (index) -> i32 + fir.store %56 to %0 : !fir.ref + return +} + +// CHECK: func @_QPf2dc(%[[VAL_0:.*]]: !fir.ref>, %[[VAL_1:.*]]: !fir.ref>, %[[VAL_2:.*]]: !fir.ref>) { +// CHECK: %[[VAL_3:.*]] = constant 100 : i32 +// CHECK: %[[VAL_4:.*]] = constant 10000 : i32 +// CHECK: %[[VAL_5:.*]] = constant 1 : i64 +// CHECK: %[[VAL_6:.*]] = constant 3 : index +// CHECK: %[[VAL_7:.*]] = constant 0 : index +// CHECK: %[[VAL_8:.*]] = constant 1 : index +// CHECK: %[[VAL_9:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFf2dcEi"} +// CHECK: %[[VAL_10:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFf2dcEj"} +// CHECK: %[[VAL_11:.*]] = fir.alloca !fir.array<3x3xi32> {bindc_name = "t1", uniq_name = "_QFf2dcEt1"} +// CHECK: br ^bb1(%[[VAL_8]], %[[VAL_6]] : index, index) +// CHECK: ^bb1(%[[VAL_12:.*]]: index, %[[VAL_13:.*]]: index): +// CHECK: %[[VAL_14:.*]] = cmpi sgt, %[[VAL_13]], %[[VAL_7]] : index +// CHECK: cond_br %[[VAL_14]], ^bb2, ^bb6 +// CHECK: ^bb2: +// CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_12]] : (index) -> i32 +// CHECK: br ^bb3(%[[VAL_8]], %[[VAL_6]] : index, index) +// CHECK: ^bb3(%[[VAL_16:.*]]: index, %[[VAL_17:.*]]: index): +// CHECK: %[[VAL_18:.*]] = cmpi sgt, %[[VAL_17]], %[[VAL_7]] : index +// CHECK: cond_br %[[VAL_18]], ^bb4, ^bb5 +// CHECK: ^bb4: +// CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_16]] : (index) -> i32 +// CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_15]] : (i32) -> i64 +// CHECK: %[[VAL_21:.*]] = subi %[[VAL_20]], %[[VAL_5]] : i64 +// CHECK: %[[VAL_22:.*]] = fir.convert %[[VAL_19]] : (i32) -> i64 +// CHECK: %[[VAL_23:.*]] = subi %[[VAL_22]], %[[VAL_5]] : i64 +// CHECK: %[[VAL_24:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_21]], %[[VAL_23]] : (!fir.ref>, i64, i64) -> !fir.ref +// CHECK: %[[VAL_25:.*]] = fir.load %[[VAL_24]] : !fir.ref +// CHECK: %[[VAL_26:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_23]], %[[VAL_21]] : (!fir.ref>, i64, i64) -> !fir.ref +// CHECK: %[[VAL_27:.*]] = fir.load %[[VAL_26]] : !fir.ref +// CHECK: %[[VAL_28:.*]] = muli %[[VAL_27]], %[[VAL_3]] : i32 +// CHECK: %[[VAL_29:.*]] = addi %[[VAL_25]], %[[VAL_28]] : i32 +// CHECK: %[[VAL_30:.*]] = fir.coordinate_of %[[VAL_11]], %[[VAL_21]], %[[VAL_23]] : (!fir.ref>, i64, i64) -> !fir.ref +// CHECK: fir.store %[[VAL_29]] to %[[VAL_30]] : !fir.ref +// CHECK: %[[VAL_31:.*]] = addi %[[VAL_16]], %[[VAL_8]] : index +// CHECK: %[[VAL_32:.*]] = subi %[[VAL_17]], %[[VAL_8]] : index +// CHECK: br ^bb3(%[[VAL_31]], %[[VAL_32]] : index, index) +// CHECK: ^bb5: +// CHECK: %[[VAL_33:.*]] = fir.convert %[[VAL_16]] : (index) -> i32 +// CHECK: %[[VAL_34:.*]] = addi %[[VAL_12]], %[[VAL_8]] : index +// CHECK: %[[VAL_35:.*]] = subi %[[VAL_13]], %[[VAL_8]] : index +// CHECK: br ^bb1(%[[VAL_34]], %[[VAL_35]] : index, index) +// CHECK: ^bb6: +// CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_12]] : (index) -> i32 +// CHECK: br ^bb7(%[[VAL_8]], %[[VAL_6]] : index, index) +// CHECK: ^bb7(%[[VAL_37:.*]]: index, %[[VAL_38:.*]]: index): +// CHECK: %[[VAL_39:.*]] = cmpi sgt, %[[VAL_38]], %[[VAL_7]] : index +// CHECK: cond_br %[[VAL_39]], ^bb8, ^bb12 +// CHECK: ^bb8: +// CHECK: %[[VAL_40:.*]] = fir.convert %[[VAL_37]] : (index) -> i32 +// CHECK: br ^bb9(%[[VAL_8]], %[[VAL_6]] : index, index) +// CHECK: ^bb9(%[[VAL_41:.*]]: index, %[[VAL_42:.*]]: index): +// CHECK: %[[VAL_43:.*]] = cmpi sgt, %[[VAL_42]], %[[VAL_7]] : index +// CHECK: cond_br %[[VAL_43]], ^bb10, ^bb11 +// CHECK: ^bb10: +// CHECK: %[[VAL_44:.*]] = fir.convert %[[VAL_41]] : (index) -> i32 +// CHECK: %[[VAL_45:.*]] = fir.convert %[[VAL_40]] : (i32) -> i64 +// CHECK: %[[VAL_46:.*]] = subi %[[VAL_45]], %[[VAL_5]] : i64 +// CHECK: %[[VAL_47:.*]] = fir.convert %[[VAL_44]] : (i32) -> i64 +// CHECK: %[[VAL_48:.*]] = subi %[[VAL_47]], %[[VAL_5]] : i64 +// CHECK: %[[VAL_49:.*]] = fir.coordinate_of %[[VAL_11]], %[[VAL_46]], %[[VAL_48]] : (!fir.ref>, i64, i64) -> !fir.ref +// CHECK: %[[VAL_50:.*]] = fir.load %[[VAL_49]] : !fir.ref +// CHECK: %[[VAL_51:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_46]], %[[VAL_48]] : (!fir.ref>, i64, i64) -> !fir.ref +// CHECK: %[[VAL_52:.*]] = fir.load %[[VAL_51]] : !fir.ref +// CHECK: %[[VAL_53:.*]] = muli %[[VAL_52]], %[[VAL_4]] : i32 +// CHECK: %[[VAL_54:.*]] = addi %[[VAL_50]], %[[VAL_53]] : i32 +// CHECK: %[[VAL_55:.*]] = fir.coordinate_of %[[VAL_2]], %[[VAL_46]], %[[VAL_48]] : (!fir.ref>, i64, i64) -> !fir.ref +// CHECK: fir.store %[[VAL_54]] to %[[VAL_55]] : !fir.ref +// CHECK: %[[VAL_56:.*]] = addi %[[VAL_41]], %[[VAL_8]] : index +// CHECK: %[[VAL_57:.*]] = subi %[[VAL_42]], %[[VAL_8]] : index +// CHECK: br ^bb9(%[[VAL_56]], %[[VAL_57]] : index, index) +// CHECK: ^bb11: +// CHECK: %[[VAL_58:.*]] = fir.convert %[[VAL_41]] : (index) -> i32 +// CHECK: %[[VAL_59:.*]] = addi %[[VAL_37]], %[[VAL_8]] : index +// CHECK: %[[VAL_60:.*]] = subi %[[VAL_38]], %[[VAL_8]] : index +// CHECK: br ^bb7(%[[VAL_59]], %[[VAL_60]] : index, index) +// CHECK: ^bb12: +// CHECK: %[[VAL_61:.*]] = fir.convert %[[VAL_37]] : (index) -> i32 +// CHECK: return +// CHECK: } + +// ----- + +func @_QPf2dv(%arg0: !fir.ref>, %arg1: !fir.ref>, %arg2: !fir.ref>, %arg3: !fir.ref, %arg4: !fir.ref) { + %c100_i32 = constant 100 : i32 + %c10000_i32 = constant 10000 : i32 + %c0 = constant 0 : index + %c1 = constant 1 : index + %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFf2dvEi"} + %1 = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFf2dvEj"} + %2 = fir.alloca i32 {bindc_name = "s1e", uniq_name = "_QFf2dvEs1e"} + %3 = fir.alloca i32 {bindc_name = "s2e", uniq_name = "_QFf2dvEs2e"} + %4 = fir.load %arg3 : !fir.ref + %5 = fir.convert %4 : (i32) -> index + %6 = fir.load %arg4 : !fir.ref + %7 = fir.convert %6 : (i32) -> index + %8 = fir.alloca !fir.array, %5, %7 {bindc_name = "t", uniq_name = "_QFf2dvEt"} + fir.store %4 to %2 : !fir.ref + %9 = fir.load %arg4 : !fir.ref + fir.store %9 to %3 : !fir.ref + %10 = fir.load %2 : !fir.ref + %11 = fir.convert %10 : (i32) -> index + br ^bb1(%c1, %11 : index, index) +^bb1(%12: index, %13: index): // 2 preds: ^bb0, ^bb5 + %14 = cmpi sgt, %13, %c0 : index + cond_br %14, ^bb2, ^bb6 +^bb2: // pred: ^bb1 + %15 = fir.convert %12 : (index) -> i32 + fir.store %15 to %0 : !fir.ref + %16 = fir.load %3 : !fir.ref + %17 = fir.convert %16 : (i32) -> index + br ^bb3(%c1, %17 : index, index) +^bb3(%18: index, %19: index): // 2 preds: ^bb2, ^bb4 + %20 = cmpi sgt, %19, %c0 : index + cond_br %20, ^bb4, ^bb5 +^bb4: // pred: ^bb3 + %21 = fir.convert %18 : (index) -> i32 + fir.store %21 to %1 : !fir.ref + %22 = fir.convert %arg0 : (!fir.ref>) -> !fir.ref> + %23 = fir.load %0 : !fir.ref + %24 = fir.convert %23 : (i32) -> index + %25 = subi %24, %c1 : index + %26 = fir.load %1 : !fir.ref + %27 = fir.convert %26 : (i32) -> index + %28 = subi %27, %c1 : index + %29 = muli %5, %28 : index + %30 = addi %29, %25 : index + %31 = fir.coordinate_of %22, %30 : (!fir.ref>, index) -> !fir.ref + %32 = fir.load %31 : !fir.ref + %33 = muli %5, %25 : index + %34 = addi %33, %28 : index + %35 = fir.coordinate_of %22, %34 : (!fir.ref>, index) -> !fir.ref + %36 = fir.load %35 : !fir.ref + %37 = muli %36, %c100_i32 : i32 + %38 = addi %32, %37 : i32 + %39 = fir.convert %8 : (!fir.ref>) -> !fir.ref> + %40 = fir.coordinate_of %39, %30 : (!fir.ref>, index) -> !fir.ref + fir.store %38 to %40 : !fir.ref + %41 = addi %18, %c1 : index + %42 = subi %19, %c1 : index + br ^bb3(%41, %42 : index, index) +^bb5: // pred: ^bb3 + %43 = fir.convert %18 : (index) -> i32 + fir.store %43 to %1 : !fir.ref + %44 = addi %12, %c1 : index + %45 = subi %13, %c1 : index + br ^bb1(%44, %45 : index, index) +^bb6: // pred: ^bb1 + %46 = fir.convert %12 : (index) -> i32 + fir.store %46 to %0 : !fir.ref + %47 = fir.load %2 : !fir.ref + %48 = fir.convert %47 : (i32) -> index + br ^bb7(%c1, %48 : index, index) +^bb7(%49: index, %50: index): // 2 preds: ^bb6, ^bb11 + %51 = cmpi sgt, %50, %c0 : index + cond_br %51, ^bb8, ^bb12 +^bb8: // pred: ^bb7 + %52 = fir.convert %49 : (index) -> i32 + fir.store %52 to %0 : !fir.ref + %53 = fir.load %3 : !fir.ref + %54 = fir.convert %53 : (i32) -> index + br ^bb9(%c1, %54 : index, index) +^bb9(%55: index, %56: index): // 2 preds: ^bb8, ^bb10 + %57 = cmpi sgt, %56, %c0 : index + cond_br %57, ^bb10, ^bb11 +^bb10: // pred: ^bb9 + %58 = fir.convert %55 : (index) -> i32 + fir.store %58 to %1 : !fir.ref + %59 = fir.convert %8 : (!fir.ref>) -> !fir.ref> + %60 = fir.load %0 : !fir.ref + %61 = fir.convert %60 : (i32) -> index + %62 = subi %61, %c1 : index + %63 = fir.load %1 : !fir.ref + %64 = fir.convert %63 : (i32) -> index + %65 = subi %64, %c1 : index + %66 = muli %5, %65 : index + %67 = addi %66, %62 : index + %68 = fir.coordinate_of %59, %67 : (!fir.ref>, index) -> !fir.ref + %69 = fir.load %68 : !fir.ref + %70 = fir.convert %arg1 : (!fir.ref>) -> !fir.ref> + %71 = fir.coordinate_of %70, %67 : (!fir.ref>, index) -> !fir.ref + %72 = fir.load %71 : !fir.ref + %73 = muli %72, %c10000_i32 : i32 + %74 = addi %69, %73 : i32 + %75 = fir.convert %arg2 : (!fir.ref>) -> !fir.ref> + %76 = fir.coordinate_of %75, %67 : (!fir.ref>, index) -> !fir.ref + fir.store %74 to %76 : !fir.ref + %77 = addi %55, %c1 : index + %78 = subi %56, %c1 : index + br ^bb9(%77, %78 : index, index) +^bb11: // pred: ^bb9 + %79 = fir.convert %55 : (index) -> i32 + fir.store %79 to %1 : !fir.ref + %80 = addi %49, %c1 : index + %81 = subi %50, %c1 : index + br ^bb7(%80, %81 : index, index) +^bb12: // pred: ^bb7 + %82 = fir.convert %49 : (index) -> i32 + fir.store %82 to %0 : !fir.ref + return +} + +// CHECK: func @_QPf2dv(%[[VAL_0:.*]]: !fir.ref>, %[[VAL_1:.*]]: !fir.ref>, %[[VAL_2:.*]]: !fir.ref>, %[[VAL_3:.*]]: !fir.ref, %[[VAL_4:.*]]: !fir.ref) { +// CHECK: %[[VAL_5:.*]] = constant 100 : i32 +// CHECK: %[[VAL_6:.*]] = constant 10000 : i32 +// CHECK: %[[VAL_7:.*]] = constant 0 : index +// CHECK: %[[VAL_8:.*]] = constant 1 : index +// CHECK: %[[VAL_9:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFf2dvEi"} +// CHECK: %[[VAL_10:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFf2dvEj"} +// CHECK: %[[VAL_11:.*]] = fir.alloca i32 {bindc_name = "s1e", uniq_name = "_QFf2dvEs1e"} +// CHECK: %[[VAL_12:.*]] = fir.alloca i32 {bindc_name = "s2e", uniq_name = "_QFf2dvEs2e"} +// CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_3]] : !fir.ref +// CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (i32) -> index +// CHECK: %[[VAL_15:.*]] = fir.load %[[VAL_4]] : !fir.ref +// CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i32) -> index +// CHECK: %[[VAL_17:.*]] = fir.alloca !fir.array, %[[VAL_14]], %[[VAL_16]] {bindc_name = "t", uniq_name = "_QFf2dvEt"} +// CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_4]] : !fir.ref +// CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_13]] : (i32) -> index +// CHECK: br ^bb1(%[[VAL_8]], %[[VAL_19]] : index, index) +// CHECK: ^bb1(%[[VAL_20:.*]]: index, %[[VAL_21:.*]]: index): +// CHECK: %[[VAL_22:.*]] = cmpi sgt, %[[VAL_21]], %[[VAL_7]] : index +// CHECK: cond_br %[[VAL_22]], ^bb2, ^bb6 +// CHECK: ^bb2: +// CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_20]] : (index) -> i32 +// CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_18]] : (i32) -> index +// CHECK: br ^bb3(%[[VAL_8]], %[[VAL_24]] : index, index) +// CHECK: ^bb3(%[[VAL_25:.*]]: index, %[[VAL_26:.*]]: index): +// CHECK: %[[VAL_27:.*]] = cmpi sgt, %[[VAL_26]], %[[VAL_7]] : index +// CHECK: cond_br %[[VAL_27]], ^bb4, ^bb5 +// CHECK: ^bb4: +// CHECK: %[[VAL_28:.*]] = fir.convert %[[VAL_25]] : (index) -> i32 +// CHECK: %[[VAL_29:.*]] = fir.convert %[[VAL_0]] : (!fir.ref>) -> !fir.ref> +// CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_23]] : (i32) -> index +// CHECK: %[[VAL_31:.*]] = subi %[[VAL_30]], %[[VAL_8]] : index +// CHECK: %[[VAL_32:.*]] = fir.convert %[[VAL_28]] : (i32) -> index +// CHECK: %[[VAL_33:.*]] = subi %[[VAL_32]], %[[VAL_8]] : index +// CHECK: %[[VAL_34:.*]] = muli %[[VAL_14]], %[[VAL_33]] : index +// CHECK: %[[VAL_35:.*]] = addi %[[VAL_34]], %[[VAL_31]] : index +// CHECK: %[[VAL_36:.*]] = fir.coordinate_of %[[VAL_29]], %[[VAL_35]] : (!fir.ref>, index) -> !fir.ref +// CHECK: %[[VAL_37:.*]] = fir.load %[[VAL_36]] : !fir.ref +// CHECK: %[[VAL_38:.*]] = muli %[[VAL_14]], %[[VAL_31]] : index +// CHECK: %[[VAL_39:.*]] = addi %[[VAL_38]], %[[VAL_33]] : index +// CHECK: %[[VAL_40:.*]] = fir.coordinate_of %[[VAL_29]], %[[VAL_39]] : (!fir.ref>, index) -> !fir.ref +// CHECK: %[[VAL_41:.*]] = fir.load %[[VAL_40]] : !fir.ref +// CHECK: %[[VAL_42:.*]] = muli %[[VAL_41]], %[[VAL_5]] : i32 +// CHECK: %[[VAL_43:.*]] = addi %[[VAL_37]], %[[VAL_42]] : i32 +// CHECK: %[[VAL_44:.*]] = fir.convert %[[VAL_17]] : (!fir.ref>) -> !fir.ref> +// CHECK: %[[VAL_45:.*]] = fir.coordinate_of %[[VAL_44]], %[[VAL_35]] : (!fir.ref>, index) -> !fir.ref +// CHECK: fir.store %[[VAL_43]] to %[[VAL_45]] : !fir.ref +// CHECK: %[[VAL_46:.*]] = addi %[[VAL_25]], %[[VAL_8]] : index +// CHECK: %[[VAL_47:.*]] = subi %[[VAL_26]], %[[VAL_8]] : index +// CHECK: br ^bb3(%[[VAL_46]], %[[VAL_47]] : index, index) +// CHECK: ^bb5: +// CHECK: %[[VAL_48:.*]] = fir.convert %[[VAL_25]] : (index) -> i32 +// CHECK: %[[VAL_49:.*]] = addi %[[VAL_20]], %[[VAL_8]] : index +// CHECK: %[[VAL_50:.*]] = subi %[[VAL_21]], %[[VAL_8]] : index +// CHECK: br ^bb1(%[[VAL_49]], %[[VAL_50]] : index, index) +// CHECK: ^bb6: +// CHECK: %[[VAL_51:.*]] = fir.convert %[[VAL_20]] : (index) -> i32 +// CHECK: %[[VAL_52:.*]] = fir.convert %[[VAL_13]] : (i32) -> index +// CHECK: br ^bb7(%[[VAL_8]], %[[VAL_52]] : index, index) +// CHECK: ^bb7(%[[VAL_53:.*]]: index, %[[VAL_54:.*]]: index): +// CHECK: %[[VAL_55:.*]] = cmpi sgt, %[[VAL_54]], %[[VAL_7]] : index +// CHECK: cond_br %[[VAL_55]], ^bb8, ^bb12 +// CHECK: ^bb8: +// CHECK: %[[VAL_56:.*]] = fir.convert %[[VAL_53]] : (index) -> i32 +// CHECK: %[[VAL_57:.*]] = fir.convert %[[VAL_18]] : (i32) -> index +// CHECK: br ^bb9(%[[VAL_8]], %[[VAL_57]] : index, index) +// CHECK: ^bb9(%[[VAL_58:.*]]: index, %[[VAL_59:.*]]: index): +// CHECK: %[[VAL_60:.*]] = cmpi sgt, %[[VAL_59]], %[[VAL_7]] : index +// CHECK: cond_br %[[VAL_60]], ^bb10, ^bb11 +// CHECK: ^bb10: +// CHECK: %[[VAL_61:.*]] = fir.convert %[[VAL_58]] : (index) -> i32 +// CHECK: %[[VAL_62:.*]] = fir.convert %[[VAL_17]] : (!fir.ref>) -> !fir.ref> +// CHECK: %[[VAL_63:.*]] = fir.convert %[[VAL_56]] : (i32) -> index +// CHECK: %[[VAL_64:.*]] = subi %[[VAL_63]], %[[VAL_8]] : index +// CHECK: %[[VAL_65:.*]] = fir.convert %[[VAL_61]] : (i32) -> index +// CHECK: %[[VAL_66:.*]] = subi %[[VAL_65]], %[[VAL_8]] : index +// CHECK: %[[VAL_67:.*]] = muli %[[VAL_14]], %[[VAL_66]] : index +// CHECK: %[[VAL_68:.*]] = addi %[[VAL_67]], %[[VAL_64]] : index +// CHECK: %[[VAL_69:.*]] = fir.coordinate_of %[[VAL_62]], %[[VAL_68]] : (!fir.ref>, index) -> !fir.ref +// CHECK: %[[VAL_70:.*]] = fir.load %[[VAL_69]] : !fir.ref +// CHECK: %[[VAL_71:.*]] = fir.convert %[[VAL_1]] : (!fir.ref>) -> !fir.ref> +// CHECK: %[[VAL_72:.*]] = fir.coordinate_of %[[VAL_71]], %[[VAL_68]] : (!fir.ref>, index) -> !fir.ref +// CHECK: %[[VAL_73:.*]] = fir.load %[[VAL_72]] : !fir.ref +// CHECK: %[[VAL_74:.*]] = muli %[[VAL_73]], %[[VAL_6]] : i32 +// CHECK: %[[VAL_75:.*]] = addi %[[VAL_70]], %[[VAL_74]] : i32 +// CHECK: %[[VAL_76:.*]] = fir.convert %[[VAL_2]] : (!fir.ref>) -> !fir.ref> +// CHECK: %[[VAL_77:.*]] = fir.coordinate_of %[[VAL_76]], %[[VAL_68]] : (!fir.ref>, index) -> !fir.ref +// CHECK: fir.store %[[VAL_75]] to %[[VAL_77]] : !fir.ref +// CHECK: %[[VAL_78:.*]] = addi %[[VAL_58]], %[[VAL_8]] : index +// CHECK: %[[VAL_79:.*]] = subi %[[VAL_59]], %[[VAL_8]] : index +// CHECK: br ^bb9(%[[VAL_78]], %[[VAL_79]] : index, index) +// CHECK: ^bb11: +// CHECK: %[[VAL_80:.*]] = fir.convert %[[VAL_58]] : (index) -> i32 +// CHECK: %[[VAL_81:.*]] = addi %[[VAL_53]], %[[VAL_8]] : index +// CHECK: %[[VAL_82:.*]] = subi %[[VAL_54]], %[[VAL_8]] : index +// CHECK: br ^bb7(%[[VAL_81]], %[[VAL_82]] : index, index) +// CHECK: ^bb12: +// CHECK: %[[VAL_83:.*]] = fir.convert %[[VAL_53]] : (index) -> i32 +// CHECK: return +// CHECK: } + +// ----- + +func @_QPf3dc(%arg0: !fir.ref>, %arg1: !fir.ref>, %arg2: !fir.ref>) { + %c100_i32 = constant 100 : i32 + %c10000_i32 = constant 10000 : i32 + %c1_i64 = constant 1 : i64 + %c3 = constant 3 : index + %c0 = constant 0 : index + %c1 = constant 1 : index + %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFf3dcEi"} + %1 = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFf3dcEj"} + %2 = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFf3dcEk"} + %3 = fir.alloca !fir.array<3x3x3xi32> {bindc_name = "t1", uniq_name = "_QFf3dcEt1"} + br ^bb1(%c1, %c3 : index, index) +^bb1(%4: index, %5: index): // 2 preds: ^bb0, ^bb8 + %6 = cmpi sgt, %5, %c0 : index + cond_br %6, ^bb2, ^bb9 +^bb2: // pred: ^bb1 + %7 = fir.convert %4 : (index) -> i32 + fir.store %7 to %0 : !fir.ref + br ^bb3(%c1, %c3 : index, index) +^bb3(%8: index, %9: index): // 2 preds: ^bb2, ^bb7 + %10 = cmpi sgt, %9, %c0 : index + cond_br %10, ^bb4, ^bb8 +^bb4: // pred: ^bb3 + %11 = fir.convert %8 : (index) -> i32 + fir.store %11 to %1 : !fir.ref + br ^bb5(%c1, %c3 : index, index) +^bb5(%12: index, %13: index): // 2 preds: ^bb4, ^bb6 + %14 = cmpi sgt, %13, %c0 : index + cond_br %14, ^bb6, ^bb7 +^bb6: // pred: ^bb5 + %15 = fir.convert %12 : (index) -> i32 + fir.store %15 to %2 : !fir.ref + %16 = fir.load %0 : !fir.ref + %17 = fir.convert %16 : (i32) -> i64 + %18 = subi %17, %c1_i64 : i64 + %19 = fir.load %1 : !fir.ref + %20 = fir.convert %19 : (i32) -> i64 + %21 = subi %20, %c1_i64 : i64 + %22 = fir.load %2 : !fir.ref + %23 = fir.convert %22 : (i32) -> i64 + %24 = subi %23, %c1_i64 : i64 + %25 = fir.coordinate_of %arg0, %18, %21, %24 : (!fir.ref>, i64, i64, i64) -> !fir.ref + %26 = fir.load %25 : !fir.ref + %27 = fir.coordinate_of %arg0, %24, %21, %18 : (!fir.ref>, i64, i64, i64) -> !fir.ref + %28 = fir.load %27 : !fir.ref + %29 = muli %28, %c100_i32 : i32 + %30 = addi %26, %29 : i32 + %31 = fir.coordinate_of %3, %18, %21, %24 : (!fir.ref>, i64, i64, i64) -> !fir.ref + fir.store %30 to %31 : !fir.ref + %32 = addi %12, %c1 : index + %33 = subi %13, %c1 : index + br ^bb5(%32, %33 : index, index) +^bb7: // pred: ^bb5 + %34 = fir.convert %12 : (index) -> i32 + fir.store %34 to %2 : !fir.ref + %35 = addi %8, %c1 : index + %36 = subi %9, %c1 : index + br ^bb3(%35, %36 : index, index) +^bb8: // pred: ^bb3 + %37 = fir.convert %8 : (index) -> i32 + fir.store %37 to %1 : !fir.ref + %38 = addi %4, %c1 : index + %39 = subi %5, %c1 : index + br ^bb1(%38, %39 : index, index) +^bb9: // pred: ^bb1 + %40 = fir.convert %4 : (index) -> i32 + fir.store %40 to %0 : !fir.ref + br ^bb10(%c1, %c3 : index, index) +^bb10(%41: index, %42: index): // 2 preds: ^bb9, ^bb17 + %43 = cmpi sgt, %42, %c0 : index + cond_br %43, ^bb11, ^bb18 +^bb11: // pred: ^bb10 + %44 = fir.convert %41 : (index) -> i32 + fir.store %44 to %0 : !fir.ref + br ^bb12(%c1, %c3 : index, index) +^bb12(%45: index, %46: index): // 2 preds: ^bb11, ^bb16 + %47 = cmpi sgt, %46, %c0 : index + cond_br %47, ^bb13, ^bb17 +^bb13: // pred: ^bb12 + %48 = fir.convert %45 : (index) -> i32 + fir.store %48 to %1 : !fir.ref + br ^bb14(%c1, %c3 : index, index) +^bb14(%49: index, %50: index): // 2 preds: ^bb13, ^bb15 + %51 = cmpi sgt, %50, %c0 : index + cond_br %51, ^bb15, ^bb16 +^bb15: // pred: ^bb14 + %52 = fir.convert %49 : (index) -> i32 + fir.store %52 to %2 : !fir.ref + %53 = fir.load %0 : !fir.ref + %54 = fir.convert %53 : (i32) -> i64 + %55 = subi %54, %c1_i64 : i64 + %56 = fir.load %1 : !fir.ref + %57 = fir.convert %56 : (i32) -> i64 + %58 = subi %57, %c1_i64 : i64 + %59 = fir.load %2 : !fir.ref + %60 = fir.convert %59 : (i32) -> i64 + %61 = subi %60, %c1_i64 : i64 + %62 = fir.coordinate_of %3, %55, %58, %61 : (!fir.ref>, i64, i64, i64) -> !fir.ref + %63 = fir.load %62 : !fir.ref + %64 = fir.coordinate_of %arg1, %55, %58, %61 : (!fir.ref>, i64, i64, i64) -> !fir.ref + %65 = fir.load %64 : !fir.ref + %66 = muli %65, %c10000_i32 : i32 + %67 = addi %63, %66 : i32 + %68 = fir.coordinate_of %arg2, %55, %58, %61 : (!fir.ref>, i64, i64, i64) -> !fir.ref + fir.store %67 to %68 : !fir.ref + %69 = addi %49, %c1 : index + %70 = subi %50, %c1 : index + br ^bb14(%69, %70 : index, index) +^bb16: // pred: ^bb14 + %71 = fir.convert %49 : (index) -> i32 + fir.store %71 to %2 : !fir.ref + %72 = addi %45, %c1 : index + %73 = subi %46, %c1 : index + br ^bb12(%72, %73 : index, index) +^bb17: // pred: ^bb12 + %74 = fir.convert %45 : (index) -> i32 + fir.store %74 to %1 : !fir.ref + %75 = addi %41, %c1 : index + %76 = subi %42, %c1 : index + br ^bb10(%75, %76 : index, index) +^bb18: // pred: ^bb10 + %77 = fir.convert %41 : (index) -> i32 + fir.store %77 to %0 : !fir.ref + return +} + +// CHECK: func @_QPf3dc(%[[VAL_0:.*]]: !fir.ref>, %[[VAL_1:.*]]: !fir.ref>, %[[VAL_2:.*]]: !fir.ref>) { +// CHECK: %[[VAL_3:.*]] = constant 100 : i32 +// CHECK: %[[VAL_4:.*]] = constant 10000 : i32 +// CHECK: %[[VAL_5:.*]] = constant 1 : i64 +// CHECK: %[[VAL_6:.*]] = constant 3 : index +// CHECK: %[[VAL_7:.*]] = constant 0 : index +// CHECK: %[[VAL_8:.*]] = constant 1 : index +// CHECK: %[[VAL_9:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFf3dcEi"} +// CHECK: %[[VAL_10:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFf3dcEj"} +// CHECK: %[[VAL_11:.*]] = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFf3dcEk"} +// CHECK: %[[VAL_12:.*]] = fir.alloca !fir.array<3x3x3xi32> {bindc_name = "t1", uniq_name = "_QFf3dcEt1"} +// CHECK: br ^bb1(%[[VAL_8]], %[[VAL_6]] : index, index) +// CHECK: ^bb1(%[[VAL_13:.*]]: index, %[[VAL_14:.*]]: index): +// CHECK: %[[VAL_15:.*]] = cmpi sgt, %[[VAL_14]], %[[VAL_7]] : index +// CHECK: cond_br %[[VAL_15]], ^bb2, ^bb9 +// CHECK: ^bb2: +// CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_13]] : (index) -> i32 +// CHECK: br ^bb3(%[[VAL_8]], %[[VAL_6]] : index, index) +// CHECK: ^bb3(%[[VAL_17:.*]]: index, %[[VAL_18:.*]]: index): +// CHECK: %[[VAL_19:.*]] = cmpi sgt, %[[VAL_18]], %[[VAL_7]] : index +// CHECK: cond_br %[[VAL_19]], ^bb4, ^bb8 +// CHECK: ^bb4: +// CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_17]] : (index) -> i32 +// CHECK: br ^bb5(%[[VAL_8]], %[[VAL_6]] : index, index) +// CHECK: ^bb5(%[[VAL_21:.*]]: index, %[[VAL_22:.*]]: index): +// CHECK: %[[VAL_23:.*]] = cmpi sgt, %[[VAL_22]], %[[VAL_7]] : index +// CHECK: cond_br %[[VAL_23]], ^bb6, ^bb7 +// CHECK: ^bb6: +// CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_21]] : (index) -> i32 +// CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_16]] : (i32) -> i64 +// CHECK: %[[VAL_26:.*]] = subi %[[VAL_25]], %[[VAL_5]] : i64 +// CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_20]] : (i32) -> i64 +// CHECK: %[[VAL_28:.*]] = subi %[[VAL_27]], %[[VAL_5]] : i64 +// CHECK: %[[VAL_29:.*]] = fir.convert %[[VAL_24]] : (i32) -> i64 +// CHECK: %[[VAL_30:.*]] = subi %[[VAL_29]], %[[VAL_5]] : i64 +// CHECK: %[[VAL_31:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_26]], %[[VAL_28]], %[[VAL_30]] : (!fir.ref>, i64, i64, i64) -> !fir.ref +// CHECK: %[[VAL_32:.*]] = fir.load %[[VAL_31]] : !fir.ref +// CHECK: %[[VAL_33:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_30]], %[[VAL_28]], %[[VAL_26]] : (!fir.ref>, i64, i64, i64) -> !fir.ref +// CHECK: %[[VAL_34:.*]] = fir.load %[[VAL_33]] : !fir.ref +// CHECK: %[[VAL_35:.*]] = muli %[[VAL_34]], %[[VAL_3]] : i32 +// CHECK: %[[VAL_36:.*]] = addi %[[VAL_32]], %[[VAL_35]] : i32 +// CHECK: %[[VAL_37:.*]] = fir.coordinate_of %[[VAL_12]], %[[VAL_26]], %[[VAL_28]], %[[VAL_30]] : (!fir.ref>, i64, i64, i64) -> !fir.ref +// CHECK: fir.store %[[VAL_36]] to %[[VAL_37]] : !fir.ref +// CHECK: %[[VAL_38:.*]] = addi %[[VAL_21]], %[[VAL_8]] : index +// CHECK: %[[VAL_39:.*]] = subi %[[VAL_22]], %[[VAL_8]] : index +// CHECK: br ^bb5(%[[VAL_38]], %[[VAL_39]] : index, index) +// CHECK: ^bb7: +// CHECK: %[[VAL_40:.*]] = fir.convert %[[VAL_21]] : (index) -> i32 +// CHECK: %[[VAL_41:.*]] = addi %[[VAL_17]], %[[VAL_8]] : index +// CHECK: %[[VAL_42:.*]] = subi %[[VAL_18]], %[[VAL_8]] : index +// CHECK: br ^bb3(%[[VAL_41]], %[[VAL_42]] : index, index) +// CHECK: ^bb8: +// CHECK: %[[VAL_43:.*]] = fir.convert %[[VAL_17]] : (index) -> i32 +// CHECK: %[[VAL_44:.*]] = addi %[[VAL_13]], %[[VAL_8]] : index +// CHECK: %[[VAL_45:.*]] = subi %[[VAL_14]], %[[VAL_8]] : index +// CHECK: br ^bb1(%[[VAL_44]], %[[VAL_45]] : index, index) +// CHECK: ^bb9: +// CHECK: %[[VAL_46:.*]] = fir.convert %[[VAL_13]] : (index) -> i32 +// CHECK: br ^bb10(%[[VAL_8]], %[[VAL_6]] : index, index) +// CHECK: ^bb10(%[[VAL_47:.*]]: index, %[[VAL_48:.*]]: index): +// CHECK: %[[VAL_49:.*]] = cmpi sgt, %[[VAL_48]], %[[VAL_7]] : index +// CHECK: cond_br %[[VAL_49]], ^bb11, ^bb18 +// CHECK: ^bb11: +// CHECK: %[[VAL_50:.*]] = fir.convert %[[VAL_47]] : (index) -> i32 +// CHECK: br ^bb12(%[[VAL_8]], %[[VAL_6]] : index, index) +// CHECK: ^bb12(%[[VAL_51:.*]]: index, %[[VAL_52:.*]]: index): +// CHECK: %[[VAL_53:.*]] = cmpi sgt, %[[VAL_52]], %[[VAL_7]] : index +// CHECK: cond_br %[[VAL_53]], ^bb13, ^bb17 +// CHECK: ^bb13: +// CHECK: %[[VAL_54:.*]] = fir.convert %[[VAL_51]] : (index) -> i32 +// CHECK: br ^bb14(%[[VAL_8]], %[[VAL_6]] : index, index) +// CHECK: ^bb14(%[[VAL_55:.*]]: index, %[[VAL_56:.*]]: index): +// CHECK: %[[VAL_57:.*]] = cmpi sgt, %[[VAL_56]], %[[VAL_7]] : index +// CHECK: cond_br %[[VAL_57]], ^bb15, ^bb16 +// CHECK: ^bb15: +// CHECK: %[[VAL_58:.*]] = fir.convert %[[VAL_55]] : (index) -> i32 +// CHECK: %[[VAL_59:.*]] = fir.convert %[[VAL_50]] : (i32) -> i64 +// CHECK: %[[VAL_60:.*]] = subi %[[VAL_59]], %[[VAL_5]] : i64 +// CHECK: %[[VAL_61:.*]] = fir.convert %[[VAL_54]] : (i32) -> i64 +// CHECK: %[[VAL_62:.*]] = subi %[[VAL_61]], %[[VAL_5]] : i64 +// CHECK: %[[VAL_63:.*]] = fir.convert %[[VAL_58]] : (i32) -> i64 +// CHECK: %[[VAL_64:.*]] = subi %[[VAL_63]], %[[VAL_5]] : i64 +// CHECK: %[[VAL_65:.*]] = fir.coordinate_of %[[VAL_12]], %[[VAL_60]], %[[VAL_62]], %[[VAL_64]] : (!fir.ref>, i64, i64, i64) -> !fir.ref +// CHECK: %[[VAL_66:.*]] = fir.load %[[VAL_65]] : !fir.ref +// CHECK: %[[VAL_67:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_60]], %[[VAL_62]], %[[VAL_64]] : (!fir.ref>, i64, i64, i64) -> !fir.ref +// CHECK: %[[VAL_68:.*]] = fir.load %[[VAL_67]] : !fir.ref +// CHECK: %[[VAL_69:.*]] = muli %[[VAL_68]], %[[VAL_4]] : i32 +// CHECK: %[[VAL_70:.*]] = addi %[[VAL_66]], %[[VAL_69]] : i32 +// CHECK: %[[VAL_71:.*]] = fir.coordinate_of %[[VAL_2]], %[[VAL_60]], %[[VAL_62]], %[[VAL_64]] : (!fir.ref>, i64, i64, i64) -> !fir.ref +// CHECK: fir.store %[[VAL_70]] to %[[VAL_71]] : !fir.ref +// CHECK: %[[VAL_72:.*]] = addi %[[VAL_55]], %[[VAL_8]] : index +// CHECK: %[[VAL_73:.*]] = subi %[[VAL_56]], %[[VAL_8]] : index +// CHECK: br ^bb14(%[[VAL_72]], %[[VAL_73]] : index, index) +// CHECK: ^bb16: +// CHECK: %[[VAL_74:.*]] = fir.convert %[[VAL_55]] : (index) -> i32 +// CHECK: %[[VAL_75:.*]] = addi %[[VAL_51]], %[[VAL_8]] : index +// CHECK: %[[VAL_76:.*]] = subi %[[VAL_52]], %[[VAL_8]] : index +// CHECK: br ^bb12(%[[VAL_75]], %[[VAL_76]] : index, index) +// CHECK: ^bb17: +// CHECK: %[[VAL_77:.*]] = fir.convert %[[VAL_51]] : (index) -> i32 +// CHECK: %[[VAL_78:.*]] = addi %[[VAL_47]], %[[VAL_8]] : index +// CHECK: %[[VAL_79:.*]] = subi %[[VAL_48]], %[[VAL_8]] : index +// CHECK: br ^bb10(%[[VAL_78]], %[[VAL_79]] : index, index) +// CHECK: ^bb18: +// CHECK: %[[VAL_80:.*]] = fir.convert %[[VAL_47]] : (index) -> i32 +// CHECK: return +// CHECK: } + +// ----- + +func @_QPf3dv(%arg0: !fir.ref>, %arg1: !fir.ref>, %arg2: !fir.ref>, %arg3: !fir.ref, %arg4: !fir.ref, %arg5: !fir.ref) { + %c100_i32 = constant 100 : i32 + %c10000_i32 = constant 10000 : i32 + %c0 = constant 0 : index + %c1 = constant 1 : index + %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFf3dvEi"} + %1 = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFf3dvEj"} + %2 = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFf3dvEk"} + %3 = fir.alloca i32 {bindc_name = "s1e", uniq_name = "_QFf3dvEs1e"} + %4 = fir.alloca i32 {bindc_name = "s2e", uniq_name = "_QFf3dvEs2e"} + %5 = fir.alloca i32 {bindc_name = "s3e", uniq_name = "_QFf3dvEs3e"} + %6 = fir.load %arg3 : !fir.ref + %7 = fir.convert %6 : (i32) -> index + %8 = fir.load %arg4 : !fir.ref + %9 = fir.convert %8 : (i32) -> index + %10 = fir.load %arg5 : !fir.ref + %11 = fir.convert %10 : (i32) -> index + %12 = fir.alloca !fir.array, %7, %9, %11 {bindc_name = "t1", uniq_name = "_QFf3dvEt1"} + fir.store %6 to %3 : !fir.ref + %13 = fir.load %arg4 : !fir.ref + fir.store %13 to %4 : !fir.ref + %14 = fir.load %arg5 : !fir.ref + fir.store %14 to %5 : !fir.ref + %15 = fir.load %3 : !fir.ref + %16 = fir.convert %15 : (i32) -> index + br ^bb1(%c1, %16 : index, index) +^bb1(%17: index, %18: index): // 2 preds: ^bb0, ^bb8 + %19 = cmpi sgt, %18, %c0 : index + cond_br %19, ^bb2, ^bb9 +^bb2: // pred: ^bb1 + %20 = fir.convert %17 : (index) -> i32 + fir.store %20 to %0 : !fir.ref + %21 = fir.load %4 : !fir.ref + %22 = fir.convert %21 : (i32) -> index + br ^bb3(%c1, %22 : index, index) +^bb3(%23: index, %24: index): // 2 preds: ^bb2, ^bb7 + %25 = cmpi sgt, %24, %c0 : index + cond_br %25, ^bb4, ^bb8 +^bb4: // pred: ^bb3 + %26 = fir.convert %23 : (index) -> i32 + fir.store %26 to %1 : !fir.ref + %27 = fir.load %5 : !fir.ref + %28 = fir.convert %27 : (i32) -> index + br ^bb5(%c1, %28 : index, index) +^bb5(%29: index, %30: index): // 2 preds: ^bb4, ^bb6 + %31 = cmpi sgt, %30, %c0 : index + cond_br %31, ^bb6, ^bb7 +^bb6: // pred: ^bb5 + %32 = fir.convert %29 : (index) -> i32 + fir.store %32 to %2 : !fir.ref + %33 = fir.convert %arg0 : (!fir.ref>) -> !fir.ref> + %34 = fir.load %0 : !fir.ref + %35 = fir.convert %34 : (i32) -> index + %36 = subi %35, %c1 : index + %37 = fir.load %1 : !fir.ref + %38 = fir.convert %37 : (i32) -> index + %39 = subi %38, %c1 : index + %40 = muli %7, %39 : index + %41 = addi %40, %36 : index + %42 = muli %7, %9 : index + %43 = fir.load %2 : !fir.ref + %44 = fir.convert %43 : (i32) -> index + %45 = subi %44, %c1 : index + %46 = muli %42, %45 : index + %47 = addi %46, %41 : index + %48 = fir.coordinate_of %33, %47 : (!fir.ref>, index) -> !fir.ref + %49 = fir.load %48 : !fir.ref + %50 = addi %40, %45 : index + %51 = muli %42, %36 : index + %52 = addi %51, %50 : index + %53 = fir.coordinate_of %33, %52 : (!fir.ref>, index) -> !fir.ref + %54 = fir.load %53 : !fir.ref + %55 = muli %54, %c100_i32 : i32 + %56 = addi %49, %55 : i32 + %57 = fir.convert %12 : (!fir.ref>) -> !fir.ref> + %58 = fir.coordinate_of %57, %47 : (!fir.ref>, index) -> !fir.ref + fir.store %56 to %58 : !fir.ref + %59 = addi %29, %c1 : index + %60 = subi %30, %c1 : index + br ^bb5(%59, %60 : index, index) +^bb7: // pred: ^bb5 + %61 = fir.convert %29 : (index) -> i32 + fir.store %61 to %2 : !fir.ref + %62 = addi %23, %c1 : index + %63 = subi %24, %c1 : index + br ^bb3(%62, %63 : index, index) +^bb8: // pred: ^bb3 + %64 = fir.convert %23 : (index) -> i32 + fir.store %64 to %1 : !fir.ref + %65 = addi %17, %c1 : index + %66 = subi %18, %c1 : index + br ^bb1(%65, %66 : index, index) +^bb9: // pred: ^bb1 + %67 = fir.convert %17 : (index) -> i32 + fir.store %67 to %0 : !fir.ref + %68 = fir.load %3 : !fir.ref + %69 = fir.convert %68 : (i32) -> index + br ^bb10(%c1, %69 : index, index) +^bb10(%70: index, %71: index): // 2 preds: ^bb9, ^bb17 + %72 = cmpi sgt, %71, %c0 : index + cond_br %72, ^bb11, ^bb18 +^bb11: // pred: ^bb10 + %73 = fir.convert %70 : (index) -> i32 + fir.store %73 to %0 : !fir.ref + %74 = fir.load %4 : !fir.ref + %75 = fir.convert %74 : (i32) -> index + br ^bb12(%c1, %75 : index, index) +^bb12(%76: index, %77: index): // 2 preds: ^bb11, ^bb16 + %78 = cmpi sgt, %77, %c0 : index + cond_br %78, ^bb13, ^bb17 +^bb13: // pred: ^bb12 + %79 = fir.convert %76 : (index) -> i32 + fir.store %79 to %1 : !fir.ref + %80 = fir.load %5 : !fir.ref + %81 = fir.convert %80 : (i32) -> index + br ^bb14(%c1, %81 : index, index) +^bb14(%82: index, %83: index): // 2 preds: ^bb13, ^bb15 + %84 = cmpi sgt, %83, %c0 : index + cond_br %84, ^bb15, ^bb16 +^bb15: // pred: ^bb14 + %85 = fir.convert %82 : (index) -> i32 + fir.store %85 to %2 : !fir.ref + %86 = fir.convert %12 : (!fir.ref>) -> !fir.ref> + %87 = fir.load %0 : !fir.ref + %88 = fir.convert %87 : (i32) -> index + %89 = subi %88, %c1 : index + %90 = fir.load %1 : !fir.ref + %91 = fir.convert %90 : (i32) -> index + %92 = subi %91, %c1 : index + %93 = muli %7, %92 : index + %94 = addi %93, %89 : index + %95 = muli %7, %9 : index + %96 = fir.load %2 : !fir.ref + %97 = fir.convert %96 : (i32) -> index + %98 = subi %97, %c1 : index + %99 = muli %95, %98 : index + %100 = addi %99, %94 : index + %101 = fir.coordinate_of %86, %100 : (!fir.ref>, index) -> !fir.ref + %102 = fir.load %101 : !fir.ref + %103 = fir.convert %arg1 : (!fir.ref>) -> !fir.ref> + %104 = fir.coordinate_of %103, %100 : (!fir.ref>, index) -> !fir.ref + %105 = fir.load %104 : !fir.ref + %106 = muli %105, %c10000_i32 : i32 + %107 = addi %102, %106 : i32 + %108 = fir.convert %arg2 : (!fir.ref>) -> !fir.ref> + %109 = fir.coordinate_of %108, %100 : (!fir.ref>, index) -> !fir.ref + fir.store %107 to %109 : !fir.ref + %110 = addi %82, %c1 : index + %111 = subi %83, %c1 : index + br ^bb14(%110, %111 : index, index) +^bb16: // pred: ^bb14 + %112 = fir.convert %82 : (index) -> i32 + fir.store %112 to %2 : !fir.ref + %113 = addi %76, %c1 : index + %114 = subi %77, %c1 : index + br ^bb12(%113, %114 : index, index) +^bb17: // pred: ^bb12 + %115 = fir.convert %76 : (index) -> i32 + fir.store %115 to %1 : !fir.ref + %116 = addi %70, %c1 : index + %117 = subi %71, %c1 : index + br ^bb10(%116, %117 : index, index) +^bb18: // pred: ^bb10 + %118 = fir.convert %70 : (index) -> i32 + fir.store %118 to %0 : !fir.ref + return +} + +// CHECK: func @_QPf3dv(%[[VAL_0:.*]]: !fir.ref>, %[[VAL_1:.*]]: !fir.ref>, %[[VAL_2:.*]]: !fir.ref>, %[[VAL_3:.*]]: !fir.ref, %[[VAL_4:.*]]: !fir.ref, %[[VAL_5:.*]]: !fir.ref) { +// CHECK: %[[VAL_6:.*]] = constant 100 : i32 +// CHECK: %[[VAL_7:.*]] = constant 10000 : i32 +// CHECK: %[[VAL_8:.*]] = constant 0 : index +// CHECK: %[[VAL_9:.*]] = constant 1 : index +// CHECK: %[[VAL_10:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFf3dvEi"} +// CHECK: %[[VAL_11:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFf3dvEj"} +// CHECK: %[[VAL_12:.*]] = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFf3dvEk"} +// CHECK: %[[VAL_13:.*]] = fir.alloca i32 {bindc_name = "s1e", uniq_name = "_QFf3dvEs1e"} +// CHECK: %[[VAL_14:.*]] = fir.alloca i32 {bindc_name = "s2e", uniq_name = "_QFf3dvEs2e"} +// CHECK: %[[VAL_15:.*]] = fir.alloca i32 {bindc_name = "s3e", uniq_name = "_QFf3dvEs3e"} +// CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_3]] : !fir.ref +// CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_16]] : (i32) -> index +// CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_4]] : !fir.ref +// CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_18]] : (i32) -> index +// CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_5]] : !fir.ref +// CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i32) -> index +// CHECK: %[[VAL_22:.*]] = fir.alloca !fir.array, %[[VAL_17]], %[[VAL_19]], %[[VAL_21]] {bindc_name = "t1", uniq_name = "_QFf3dvEt1"} +// CHECK: %[[VAL_23:.*]] = fir.load %[[VAL_4]] : !fir.ref +// CHECK: %[[VAL_24:.*]] = fir.load %[[VAL_5]] : !fir.ref +// CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_16]] : (i32) -> index +// CHECK: br ^bb1(%[[VAL_9]], %[[VAL_25]] : index, index) +// CHECK: ^bb1(%[[VAL_26:.*]]: index, %[[VAL_27:.*]]: index): +// CHECK: %[[VAL_28:.*]] = cmpi sgt, %[[VAL_27]], %[[VAL_8]] : index +// CHECK: cond_br %[[VAL_28]], ^bb2, ^bb9 +// CHECK: ^bb2: +// CHECK: %[[VAL_29:.*]] = fir.convert %[[VAL_26]] : (index) -> i32 +// CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_23]] : (i32) -> index +// CHECK: br ^bb3(%[[VAL_9]], %[[VAL_30]] : index, index) +// CHECK: ^bb3(%[[VAL_31:.*]]: index, %[[VAL_32:.*]]: index): +// CHECK: %[[VAL_33:.*]] = cmpi sgt, %[[VAL_32]], %[[VAL_8]] : index +// CHECK: cond_br %[[VAL_33]], ^bb4, ^bb8 +// CHECK: ^bb4: +// CHECK: %[[VAL_34:.*]] = fir.convert %[[VAL_31]] : (index) -> i32 +// CHECK: %[[VAL_35:.*]] = fir.convert %[[VAL_24]] : (i32) -> index +// CHECK: br ^bb5(%[[VAL_9]], %[[VAL_35]] : index, index) +// CHECK: ^bb5(%[[VAL_36:.*]]: index, %[[VAL_37:.*]]: index): +// CHECK: %[[VAL_38:.*]] = cmpi sgt, %[[VAL_37]], %[[VAL_8]] : index +// CHECK: cond_br %[[VAL_38]], ^bb6, ^bb7 +// CHECK: ^bb6: +// CHECK: %[[VAL_39:.*]] = fir.convert %[[VAL_36]] : (index) -> i32 +// CHECK: %[[VAL_40:.*]] = fir.convert %[[VAL_0]] : (!fir.ref>) -> !fir.ref> +// CHECK: %[[VAL_41:.*]] = fir.convert %[[VAL_29]] : (i32) -> index +// CHECK: %[[VAL_42:.*]] = subi %[[VAL_41]], %[[VAL_9]] : index +// CHECK: %[[VAL_43:.*]] = fir.convert %[[VAL_34]] : (i32) -> index +// CHECK: %[[VAL_44:.*]] = subi %[[VAL_43]], %[[VAL_9]] : index +// CHECK: %[[VAL_45:.*]] = muli %[[VAL_17]], %[[VAL_44]] : index +// CHECK: %[[VAL_46:.*]] = addi %[[VAL_45]], %[[VAL_42]] : index +// CHECK: %[[VAL_47:.*]] = muli %[[VAL_17]], %[[VAL_19]] : index +// CHECK: %[[VAL_48:.*]] = fir.convert %[[VAL_39]] : (i32) -> index +// CHECK: %[[VAL_49:.*]] = subi %[[VAL_48]], %[[VAL_9]] : index +// CHECK: %[[VAL_50:.*]] = muli %[[VAL_47]], %[[VAL_49]] : index +// CHECK: %[[VAL_51:.*]] = addi %[[VAL_50]], %[[VAL_46]] : index +// CHECK: %[[VAL_52:.*]] = fir.coordinate_of %[[VAL_40]], %[[VAL_51]] : (!fir.ref>, index) -> !fir.ref +// CHECK: %[[VAL_53:.*]] = fir.load %[[VAL_52]] : !fir.ref +// CHECK: %[[VAL_54:.*]] = addi %[[VAL_45]], %[[VAL_49]] : index +// CHECK: %[[VAL_55:.*]] = muli %[[VAL_47]], %[[VAL_42]] : index +// CHECK: %[[VAL_56:.*]] = addi %[[VAL_55]], %[[VAL_54]] : index +// CHECK: %[[VAL_57:.*]] = fir.coordinate_of %[[VAL_40]], %[[VAL_56]] : (!fir.ref>, index) -> !fir.ref +// CHECK: %[[VAL_58:.*]] = fir.load %[[VAL_57]] : !fir.ref +// CHECK: %[[VAL_59:.*]] = muli %[[VAL_58]], %[[VAL_6]] : i32 +// CHECK: %[[VAL_60:.*]] = addi %[[VAL_53]], %[[VAL_59]] : i32 +// CHECK: %[[VAL_61:.*]] = fir.convert %[[VAL_22]] : (!fir.ref>) -> !fir.ref> +// CHECK: %[[VAL_62:.*]] = fir.coordinate_of %[[VAL_61]], %[[VAL_51]] : (!fir.ref>, index) -> !fir.ref +// CHECK: fir.store %[[VAL_60]] to %[[VAL_62]] : !fir.ref +// CHECK: %[[VAL_63:.*]] = addi %[[VAL_36]], %[[VAL_9]] : index +// CHECK: %[[VAL_64:.*]] = subi %[[VAL_37]], %[[VAL_9]] : index +// CHECK: br ^bb5(%[[VAL_63]], %[[VAL_64]] : index, index) +// CHECK: ^bb7: +// CHECK: %[[VAL_65:.*]] = fir.convert %[[VAL_36]] : (index) -> i32 +// CHECK: %[[VAL_66:.*]] = addi %[[VAL_31]], %[[VAL_9]] : index +// CHECK: %[[VAL_67:.*]] = subi %[[VAL_32]], %[[VAL_9]] : index +// CHECK: br ^bb3(%[[VAL_66]], %[[VAL_67]] : index, index) +// CHECK: ^bb8: +// CHECK: %[[VAL_68:.*]] = fir.convert %[[VAL_31]] : (index) -> i32 +// CHECK: %[[VAL_69:.*]] = addi %[[VAL_26]], %[[VAL_9]] : index +// CHECK: %[[VAL_70:.*]] = subi %[[VAL_27]], %[[VAL_9]] : index +// CHECK: br ^bb1(%[[VAL_69]], %[[VAL_70]] : index, index) +// CHECK: ^bb9: +// CHECK: %[[VAL_71:.*]] = fir.convert %[[VAL_26]] : (index) -> i32 +// CHECK: %[[VAL_72:.*]] = fir.convert %[[VAL_16]] : (i32) -> index +// CHECK: br ^bb10(%[[VAL_9]], %[[VAL_72]] : index, index) +// CHECK: ^bb10(%[[VAL_73:.*]]: index, %[[VAL_74:.*]]: index): +// CHECK: %[[VAL_75:.*]] = cmpi sgt, %[[VAL_74]], %[[VAL_8]] : index +// CHECK: cond_br %[[VAL_75]], ^bb11, ^bb18 +// CHECK: ^bb11: +// CHECK: %[[VAL_76:.*]] = fir.convert %[[VAL_73]] : (index) -> i32 +// CHECK: %[[VAL_77:.*]] = fir.convert %[[VAL_23]] : (i32) -> index +// CHECK: br ^bb12(%[[VAL_9]], %[[VAL_77]] : index, index) +// CHECK: ^bb12(%[[VAL_78:.*]]: index, %[[VAL_79:.*]]: index): +// CHECK: %[[VAL_80:.*]] = cmpi sgt, %[[VAL_79]], %[[VAL_8]] : index +// CHECK: cond_br %[[VAL_80]], ^bb13, ^bb17 +// CHECK: ^bb13: +// CHECK: %[[VAL_81:.*]] = fir.convert %[[VAL_78]] : (index) -> i32 +// CHECK: %[[VAL_82:.*]] = fir.convert %[[VAL_24]] : (i32) -> index +// CHECK: br ^bb14(%[[VAL_9]], %[[VAL_82]] : index, index) +// CHECK: ^bb14(%[[VAL_83:.*]]: index, %[[VAL_84:.*]]: index): +// CHECK: %[[VAL_85:.*]] = cmpi sgt, %[[VAL_84]], %[[VAL_8]] : index +// CHECK: cond_br %[[VAL_85]], ^bb15, ^bb16 +// CHECK: ^bb15: +// CHECK: %[[VAL_86:.*]] = fir.convert %[[VAL_83]] : (index) -> i32 +// CHECK: %[[VAL_87:.*]] = fir.convert %[[VAL_22]] : (!fir.ref>) -> !fir.ref> +// CHECK: %[[VAL_88:.*]] = fir.convert %[[VAL_76]] : (i32) -> index +// CHECK: %[[VAL_89:.*]] = subi %[[VAL_88]], %[[VAL_9]] : index +// CHECK: %[[VAL_90:.*]] = fir.convert %[[VAL_81]] : (i32) -> index +// CHECK: %[[VAL_91:.*]] = subi %[[VAL_90]], %[[VAL_9]] : index +// CHECK: %[[VAL_92:.*]] = muli %[[VAL_17]], %[[VAL_91]] : index +// CHECK: %[[VAL_93:.*]] = addi %[[VAL_92]], %[[VAL_89]] : index +// CHECK: %[[VAL_94:.*]] = muli %[[VAL_17]], %[[VAL_19]] : index +// CHECK: %[[VAL_95:.*]] = fir.convert %[[VAL_86]] : (i32) -> index +// CHECK: %[[VAL_96:.*]] = subi %[[VAL_95]], %[[VAL_9]] : index +// CHECK: %[[VAL_97:.*]] = muli %[[VAL_94]], %[[VAL_96]] : index +// CHECK: %[[VAL_98:.*]] = addi %[[VAL_97]], %[[VAL_93]] : index +// CHECK: %[[VAL_99:.*]] = fir.coordinate_of %[[VAL_87]], %[[VAL_98]] : (!fir.ref>, index) -> !fir.ref +// CHECK: %[[VAL_100:.*]] = fir.load %[[VAL_99]] : !fir.ref +// CHECK: %[[VAL_101:.*]] = fir.convert %[[VAL_1]] : (!fir.ref>) -> !fir.ref> +// CHECK: %[[VAL_102:.*]] = fir.coordinate_of %[[VAL_101]], %[[VAL_98]] : (!fir.ref>, index) -> !fir.ref +// CHECK: %[[VAL_103:.*]] = fir.load %[[VAL_102]] : !fir.ref +// CHECK: %[[VAL_104:.*]] = muli %[[VAL_103]], %[[VAL_7]] : i32 +// CHECK: %[[VAL_105:.*]] = addi %[[VAL_100]], %[[VAL_104]] : i32 +// CHECK: %[[VAL_106:.*]] = fir.convert %[[VAL_2]] : (!fir.ref>) -> !fir.ref> +// CHECK: %[[VAL_107:.*]] = fir.coordinate_of %[[VAL_106]], %[[VAL_98]] : (!fir.ref>, index) -> !fir.ref +// CHECK: fir.store %[[VAL_105]] to %[[VAL_107]] : !fir.ref +// CHECK: %[[VAL_108:.*]] = addi %[[VAL_83]], %[[VAL_9]] : index +// CHECK: %[[VAL_109:.*]] = subi %[[VAL_84]], %[[VAL_9]] : index +// CHECK: br ^bb14(%[[VAL_108]], %[[VAL_109]] : index, index) +// CHECK: ^bb16: +// CHECK: %[[VAL_110:.*]] = fir.convert %[[VAL_83]] : (index) -> i32 +// CHECK: %[[VAL_111:.*]] = addi %[[VAL_78]], %[[VAL_9]] : index +// CHECK: %[[VAL_112:.*]] = subi %[[VAL_79]], %[[VAL_9]] : index +// CHECK: br ^bb12(%[[VAL_111]], %[[VAL_112]] : index, index) +// CHECK: ^bb17: +// CHECK: %[[VAL_113:.*]] = fir.convert %[[VAL_78]] : (index) -> i32 +// CHECK: %[[VAL_114:.*]] = addi %[[VAL_73]], %[[VAL_9]] : index +// CHECK: %[[VAL_115:.*]] = subi %[[VAL_74]], %[[VAL_9]] : index +// CHECK: br ^bb10(%[[VAL_114]], %[[VAL_115]] : index, index) +// CHECK: ^bb18: +// CHECK: %[[VAL_116:.*]] = fir.convert %[[VAL_73]] : (index) -> i32 +// CHECK: return +// CHECK: }