diff --git a/flang/include/flang/Optimizer/Builder/Character.h b/flang/include/flang/Optimizer/Builder/Character.h --- a/flang/include/flang/Optimizer/Builder/Character.h +++ b/flang/include/flang/Optimizer/Builder/Character.h @@ -66,6 +66,16 @@ fir::CharBoxValue createConcatenate(const fir::CharBoxValue &lhs, const fir::CharBoxValue &rhs); + /// Create {max,min}(lhs,rhs) in temp obtained with fir.alloca + /// TODO: delete this. `createCharExtremum2` is the better solution + fir::CharBoxValue createCharExtremum(bool predIsMin, + const fir::CharBoxValue &lhs, + const fir::CharBoxValue &rhs); + /// Create {max,min}(lhs,rhs) in temp obtained with fir.alloca + fir::CharBoxValue + createCharExtremum2(bool predIsMin, + const std::vector &opExvs); + /// LEN_TRIM intrinsic. mlir::Value createLenTrim(const fir::CharBoxValue &str); diff --git a/flang/include/flang/Optimizer/HLFIR/CMakeLists.txt b/flang/include/flang/Optimizer/HLFIR/CMakeLists.txt --- a/flang/include/flang/Optimizer/HLFIR/CMakeLists.txt +++ b/flang/include/flang/Optimizer/HLFIR/CMakeLists.txt @@ -5,6 +5,8 @@ mlir_tablegen(HLFIRDialect.cpp.inc -gen-dialect-defs -dialect=hlfir) mlir_tablegen(HLFIRAttributes.h.inc -gen-attrdef-decls -attrdefs-dialect=hlfir) mlir_tablegen(HLFIRAttributes.cpp.inc -gen-attrdef-defs -attrdefs-dialect=hlfir) +mlir_tablegen(HLFIREnums.h.inc -gen-enum-decls) +mlir_tablegen(HLFIREnums.cpp.inc -gen-enum-defs) set(LLVM_TARGET_DEFINITIONS HLFIROps.td) mlir_tablegen(HLFIROpInterfaces.h.inc -gen-op-interface-decls) diff --git a/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h b/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h --- a/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h +++ b/flang/include/flang/Optimizer/HLFIR/HLFIRDialect.h @@ -26,6 +26,8 @@ #include "flang/Optimizer/HLFIR/HLFIRDialect.h.inc" +#include "flang/Optimizer/HLFIR/HLFIREnums.h.inc" + #define GET_TYPEDEF_CLASSES #include "flang/Optimizer/HLFIR/HLFIRTypes.h.inc" diff --git a/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td b/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td --- a/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td +++ b/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td @@ -15,6 +15,7 @@ #define FORTRAN_DIALECT_HLFIR_OP_BASE include "mlir/IR/AttrTypeBase.td" +include "mlir/IR/EnumAttr.td" include "mlir/IR/OpBase.td" include "flang/Optimizer/Dialect/FIRTypes.td" @@ -133,4 +134,12 @@ def AnyFortranLogicalOrI1ArrayObject : Type; +def hlfir_CharExtremumPredicateAttr : I32EnumAttr< + "CharExtremumPredicate", "", + [ + I32EnumAttrCase<"min", 0>, + I32EnumAttrCase<"max", 1> + ]> { + let cppNamespace = "hlfir"; +} #endif // FORTRAN_DIALECT_HLFIR_OP_BASE diff --git a/flang/include/flang/Optimizer/HLFIR/HLFIROps.td b/flang/include/flang/Optimizer/HLFIR/HLFIROps.td --- a/flang/include/flang/Optimizer/HLFIR/HLFIROps.td +++ b/flang/include/flang/Optimizer/HLFIR/HLFIROps.td @@ -1303,4 +1303,28 @@ let hasCanonicalizeMethod = 1; } +def hlfir_CharExtremumOp : hlfir_Op<"char_extremum", []> { + let summary = "Find max/min from given character strings"; + let description = [{ + Find the minimum or maximum of two or more character strings of a same character kind and return the string with the minimum or maximum number of characters. Example: + + %0 = hlfir.char_extremum min, %arg0, %arg1 : (!fir.ref>, !fir.ref>) -> !hlfir.expr> + }]; + + let arguments = (ins hlfir_CharExtremumPredicateAttr:$predicate, + Variadic:$strings + ); + + let results = (outs AnyScalarCharacterExpr); + + let assemblyFormat = [{ + $predicate `,` $strings attr-dict `:` functional-type(operands, results) + }]; + + let builders = [OpBuilder<(ins "hlfir::CharExtremumPredicate":$predicate, "mlir::ValueRange":$strings)>]; + + let hasVerifier = 1; +} + + #endif // FORTRAN_DIALECT_HLFIR_OPS diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp --- a/flang/lib/Lower/ConvertCall.cpp +++ b/flang/lib/Lower/ConvertCall.cpp @@ -1311,13 +1311,18 @@ hlfir::Entity actual = arg->getOriginalActual(); mlir::Value valArg; - fir::ArgLoweringRule argRules = - fir::lowerIntrinsicArgumentAs(*argLowering, i); - if (!argRules.handleDynamicOptional && - argRules.lowerAs != fir::LowerIntrinsicArgAs::Inquired) - valArg = hlfir::derefPointersAndAllocatables(loc, builder, actual); - else - valArg = actual.getBase(); + // if intrinsic handler has no lowering rules + if (!argLowering) { + valArg = hlfir::loadTrivialScalar(loc, builder, actual); + } else { + fir::ArgLoweringRule argRules = + fir::lowerIntrinsicArgumentAs(*argLowering, i); + if (!argRules.handleDynamicOptional && + argRules.lowerAs != fir::LowerIntrinsicArgAs::Inquired) + valArg = hlfir::derefPointersAndAllocatables(loc, builder, actual); + else + valArg = actual.getBase(); + } operands.emplace_back(valArg); } @@ -1411,6 +1416,21 @@ return {hlfir::EntityWithAttributes{transposeOp.getResult()}}; } + if ((intrinsicName == "min" || intrinsicName == "max") && + hlfir::getFortranElementType(callContext.resultType.value()) + .isa()) { + llvm::SmallVector operands = getOperandVector(loweredActuals); + assert(operands.size() >= 2); + + hlfir::CharExtremumPredicate pred = (intrinsicName == "min") + ? hlfir::CharExtremumPredicate::min + : hlfir::CharExtremumPredicate::max; + hlfir::CharExtremumOp charExtremumOp = + builder.create(loc, pred, + mlir::ValueRange{operands}); + return {hlfir::EntityWithAttributes{charExtremumOp.getResult()}}; + } + // TODO add hlfir operations for other transformational intrinsics here // fallback to calling the intrinsic via fir.call diff --git a/flang/lib/Optimizer/Builder/Character.cpp b/flang/lib/Optimizer/Builder/Character.cpp --- a/flang/lib/Optimizer/Builder/Character.cpp +++ b/flang/lib/Optimizer/Builder/Character.cpp @@ -784,3 +784,94 @@ mlir::Type lenType = mlir::IntegerType::get(context, 64); return mlir::TupleType::get(context, {funcPointerType, lenType}); } + +// TODO: remove this. `createCharExtremum2` is the better solution. +fir::CharBoxValue fir::factory::CharacterExprHelper::createCharExtremum( + bool predIsMin, const fir::CharBoxValue &lhs, + const fir::CharBoxValue &rhs) { + auto lhsLen = builder.createConvert(loc, builder.getCharacterLengthType(), + lhs.getLen()); + auto rhsLen = builder.createConvert(loc, builder.getCharacterLengthType(), + rhs.getLen()); + mlir::Value lhsBigger = builder.create( + loc, mlir::arith::CmpIPredicate::ugt, lhsLen, rhsLen); + mlir::Value lhsCBB = getCharBoxBuffer(lhs); + mlir::Value rhsCBB = getCharBoxBuffer(rhs); + mlir::Value biggestChar = + builder.create(loc, lhsBigger, lhsCBB, rhsCBB); + mlir::Value biggestLen = + builder.create(loc, lhsBigger, lhsLen, rhsLen); + auto temp = createCharacterTemp(biggestChar.getType(), biggestLen); + auto lowerBound = + builder.createIntegerConstant(loc, builder.getIndexType(), 0); + auto one = builder.createIntegerConstant(loc, biggestLen.getType(), 1); + auto upperBound = builder.create(loc, biggestLen, one); + mlir::Value fromBuff = predIsMin ? builder.create( + loc, lhsBigger, rhsCBB, lhsCBB) + : biggestChar; + auto toBuff = getCharBoxBuffer(temp); + fir::factory::DoLoopHelper{builder, loc}.createLoop( + lowerBound, upperBound, one, + [&](fir::FirOpBuilder &bldr, mlir::Value index) { + auto charVal = createLoadCharAt(fromBuff, index); + createStoreCharAt(toBuff, index, charVal); + }); + return temp; +} + +fir::CharBoxValue fir::factory::CharacterExprHelper::createCharExtremum2( + bool predIsMin, const std::vector &opExvs) { + + auto resultChar = *opExvs[0].getCharBox(); + + auto typeLen = fir::CharacterType::unknownLen(); + auto kind = recoverCharacterType(resultChar.getBuffer().getType()).getFKind(); + auto charTy = fir::CharacterType::get(builder.getContext(), kind, typeLen); + auto type = fir::ReferenceType::get(charTy); + auto buffer = builder.createConvert(loc, type, resultChar.getBuffer()); + fir::CharBoxValue castedResultCBV{buffer, resultChar.getLen()}; + + mlir::Value resultCharCBB = getCharBoxBuffer(castedResultCBV); + mlir::Value biggestLen = + builder.createConvert(loc, builder.getCharacterLengthType(), + (*opExvs[0].getCharBox()).getLen()); + mlir::Value smallestLen = biggestLen; + + for (size_t i = 1; i < opExvs.size(); ++i) { + auto compareChar = *opExvs[i].getCharBox(); + auto castedBuffer = + builder.createConvert(loc, type, compareChar.getBuffer()); + fir::CharBoxValue castedCompareCBV{castedBuffer, compareChar.getLen()}; + auto compareCharCBB = getCharBoxBuffer(castedCompareCBV); + auto compareCharLen = builder.createConvert( + loc, builder.getCharacterLengthType(), compareChar.getLen()); + + mlir::Value lhsBigger = builder.create( + loc, mlir::arith::CmpIPredicate::uge, biggestLen, compareCharLen); + biggestLen = builder.create( + loc, lhsBigger, biggestLen, compareCharLen); + + if (predIsMin) { + auto lhsSmaller = builder.create( + loc, mlir::arith::CmpIPredicate::ult, smallestLen, compareCharLen); + resultCharCBB = builder.create( + loc, lhsSmaller, resultCharCBB, compareCharCBB); + } else + resultCharCBB = builder.create( + loc, lhsBigger, resultCharCBB, compareCharCBB); + } + auto resultLen = predIsMin ? smallestLen : biggestLen; + auto temp = createCharacterTemp(resultCharCBB.getType(), biggestLen); + auto lowerBound = + builder.createIntegerConstant(loc, builder.getIndexType(), 0); + auto one = builder.createIntegerConstant(loc, biggestLen.getType(), 1); + auto upperBound = builder.create(loc, resultLen, one); + auto toBuff = getCharBoxBuffer(temp); + fir::factory::DoLoopHelper{builder, loc}.createLoop( + lowerBound, upperBound, one, + [&](fir::FirOpBuilder &bldr, mlir::Value index) { + auto charVal = createLoadCharAt(resultCharCBB, index); + createStoreCharAt(toBuff, index, charVal); + }); + return temp; +} diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp --- a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp +++ b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp @@ -1266,6 +1266,44 @@ return mlir::failure(); } +//===----------------------------------------------------------------------===// +// CharExtremumOp +//===----------------------------------------------------------------------===// + +mlir::LogicalResult hlfir::CharExtremumOp::verify() { + if (getStrings().size() < 2) + return emitOpError("must be provided at least two string operands"); + unsigned kind = getCharacterKind(getResult().getType()); + for (auto string : getStrings()) + if (kind != getCharacterKind(string.getType())) + return emitOpError("strings must have the same KIND as the result type"); + return mlir::success(); +} + +void hlfir::CharExtremumOp::build(mlir::OpBuilder &builder, + mlir::OperationState &result, + hlfir::CharExtremumPredicate predicate, + mlir::ValueRange strings) { + + fir::CharacterType::LenType resultTypeLen = 0; + assert(!strings.empty() && "must contain operands"); + unsigned kind = getCharacterKind(strings[0].getType()); + for (auto string : strings) + if (auto cstLen = getCharacterLengthIfStatic(string.getType())) { + resultTypeLen = std::max(resultTypeLen, *cstLen); + } else { + resultTypeLen = fir::CharacterType::unknownLen(); + break; + } + auto resultType = hlfir::ExprType::get( + builder.getContext(), hlfir::ExprType::Shape{}, + fir::CharacterType::get(builder.getContext(), kind, resultTypeLen), + false); + + build(builder, result, resultType, predicate, strings); +} + #include "flang/Optimizer/HLFIR/HLFIROpInterfaces.cpp.inc" #define GET_OP_CLASSES -#include "flang/Optimizer/HLFIR/HLFIROps.cpp.inc" +#include "flang/Optimizer/HLFIR/HLFIREnums.cpp.inc" +#include "flang/Optimizer/HLFIR/HLFIROps.cpp.inc" \ No newline at end of file diff --git a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp --- a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp @@ -554,6 +554,103 @@ return mlir::success(); } }; +struct CharExtremumOpConversion + : public mlir::OpConversionPattern { + using mlir::OpConversionPattern::OpConversionPattern; + explicit CharExtremumOpConversion(mlir::MLIRContext *ctx) + : mlir::OpConversionPattern{ctx} {} + // TODO: remove this. this was for use with `createCharExtremum` + /*mlir::LogicalResult + matchAndRewrite(hlfir::CharExtremumOp char_extremum, OpAdaptor adaptor, + mlir::ConversionPatternRewriter &rewriter) const override { + mlir::Location loc = char_extremum->getLoc(); + auto module = char_extremum->getParentOfType(); + auto predicate = char_extremum.getPredicate(); + bool predIsMin = + predicate == hlfir::CharExtremumPredicate::min ? true : false; + fir::FirOpBuilder builder(rewriter, fir::getKindMapping(module)); + assert(adaptor.getStrings().size() >= 2 && + "must have at least two strings operands"); + // It seems like we should be able to handle variadic args with a little + // more effort. For feedback though, see what folks think for the case where + // it's just 2 args. + if (adaptor.getStrings().size() > 2) + TODO(loc, "codegen of optimized chained char_extremum of more than two " + "strings"); + hlfir::Entity lhs = getBufferizedExprStorage(adaptor.getStrings()[0]); + hlfir::Entity rhs = getBufferizedExprStorage(adaptor.getStrings()[1]); + auto [lhsExv, c1] = hlfir::translateToExtendedValue(loc, builder, lhs); + auto [rhsExv, c2] = hlfir::translateToExtendedValue(loc, builder, rhs); + assert(!c1 && !c2 && "expected variables"); + // things are different here! `createConcatenate` drives the bus + fir::ExtendedValue res = + fir::factory::CharacterExprHelper{builder, loc}.createCharExtremum( + predIsMin, *lhsExv.getCharBox(), *rhsExv.getCharBox()); + // Ensure the memory type is the same as the result type. + mlir::Type addrType = fir::ReferenceType::get( + hlfir::getFortranElementType(char_extremum.getResult().getType())); + mlir::Value cast = builder.createConvert(loc, addrType, fir::getBase(res)); + res = fir::substBase(res, cast); + hlfir::Entity hlfirTempRes = + hlfir::Entity{hlfir::genDeclare(loc, builder, res, "tmp", + fir::FortranVariableFlagsAttr{}) + .getBase()}; + mlir::Value bufferizedExpr = + packageBufferizedExpr(loc, builder, hlfirTempRes, false); + rewriter.replaceOp(char_extremum, bufferizedExpr); + return mlir::success(); + }*/ + mlir::LogicalResult + matchAndRewrite(hlfir::CharExtremumOp char_extremum, OpAdaptor adaptor, + mlir::ConversionPatternRewriter &rewriter) const override { + mlir::Location loc = char_extremum->getLoc(); + auto module = char_extremum->getParentOfType(); + auto predicate = char_extremum.getPredicate(); + bool predIsMin = + predicate == hlfir::CharExtremumPredicate::min ? true : false; + fir::FirOpBuilder builder(rewriter, fir::getKindMapping(module)); + assert(adaptor.getStrings().size() >= 2 && + "must have at least two strings operands"); + // It seems like we should be able to handle variadic args with a little + // more effort. For feedback though, see what folks think for the case where + // it's just 2 args. + // if (adaptor.getStrings().size() > 2) + // TODO(loc, "codegen of optimized chained char_extremum of more than two " + // "strings"); + + std::vector /*mlir::ValueRange*/ opExvs( + adaptor.getStrings().size()); + for (size_t i = 0; i < adaptor.getStrings().size(); ++i) { + // auto [charExv, c] = getBufferizedExprStorage(adaptor.getStrings()[i]); + hlfir::Entity currChar = + getBufferizedExprStorage(adaptor.getStrings()[i]); + auto [currCharExv, c] = + hlfir::translateToExtendedValue(loc, builder, currChar); + assert(!c && "expected variables"); + opExvs[i] = currCharExv; + } + // at this point, you should have all the strings converted to + // fir::ExtendedValues + // + + fir::ExtendedValue res = + fir::factory::CharacterExprHelper{builder, loc}.createCharExtremum2( + predIsMin, opExvs); + // Ensure the memory type is the same as the result type. + mlir::Type addrType = fir::ReferenceType::get( + hlfir::getFortranElementType(char_extremum.getResult().getType())); + mlir::Value cast = builder.createConvert(loc, addrType, fir::getBase(res)); + res = fir::substBase(res, cast); + hlfir::Entity hlfirTempRes = + hlfir::Entity{hlfir::genDeclare(loc, builder, res, "tmp", + fir::FortranVariableFlagsAttr{}) + .getBase()}; + mlir::Value bufferizedExpr = + packageBufferizedExpr(loc, builder, hlfirTempRes, false); + rewriter.replaceOp(char_extremum, bufferizedExpr); + return mlir::success(); + } +}; class BufferizeHLFIR : public hlfir::impl::BufferizeHLFIRBase { public: @@ -568,11 +665,12 @@ auto module = this->getOperation(); auto *context = &getContext(); mlir::RewritePatternSet patterns(context); - patterns.insert(context); + patterns + .insert(context); mlir::ConversionTarget target(*context); // Note that YieldElementOp is not marked as an illegal operation. // It must be erased by its parent converter and there is no explicit diff --git a/flang/test/HLFIR/char_extremum-bufferization.fir b/flang/test/HLFIR/char_extremum-bufferization.fir new file mode 100644 --- /dev/null +++ b/flang/test/HLFIR/char_extremum-bufferization.fir @@ -0,0 +1,366 @@ +// Test hlfir.concat operation lowering to operations operating on memory. + +// RUN: fir-opt %s -bufferize-hlfir | FileCheck %s +// XFAIL: * + +func.func @_QPmax1(%arg0: !fir.boxchar<1> {fir.bindc_name = "c1"}, %arg1: !fir.boxchar<1> {fir.bindc_name = "c2"}, %arg2: !fir.boxchar<1> {fir.bindc_name = "c3"}) { + %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %1:2 = hlfir.declare %0#0 typeparams %0#1 {uniq_name = "_QFmax1Ec1"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) + %2:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %3:2 = hlfir.declare %2#0 typeparams %2#1 {uniq_name = "_QFmax1Ec2"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) + %4:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %5:2 = hlfir.declare %4#0 typeparams %4#1 {uniq_name = "_QFmax1Ec3"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) + %6 = hlfir.char_extremum max, %3#0, %5#0 : (!fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> + hlfir.assign %6 to %1#0 : !hlfir.expr>, !fir.boxchar<1> + hlfir.destroy %6 : !hlfir.expr> + return +} + +// func.func @_QPmax1(%arg0: !fir.boxchar<1> {fir.bindc_name = "c1"}, %arg1: !fir.boxchar<1> {fir.bindc_name = "c2"}, %arg2: !fir.boxchar<1> {fir.bindc_name = "c3"}) { +// %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %1:2 = hlfir.declare %0#0 typeparams %0#1 {uniq_name = "_QFmax1Ec1"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %2:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %3:2 = hlfir.declare %2#0 typeparams %2#1 {uniq_name = "_QFmax1Ec2"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %4:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %5:2 = hlfir.declare %4#0 typeparams %4#1 {uniq_name = "_QFmax1Ec3"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %6 = arith.cmpi uge, %2#1, %4#1 : index +// %7 = arith.select %6, %2#1, %4#1 : index +// %8 = arith.select %6, %3#1, %5#1 : !fir.ref> +// %9 = fir.alloca !fir.char<1,?>(%7 : index) {bindc_name = ".chrtmp"} +// %c0 = arith.constant 0 : index +// %c1 = arith.constant 1 : index +// %10 = arith.subi %7, %c1 : index +// fir.do_loop %arg3 = %c0 to %10 step %c1 { +// %15 = fir.convert %8 : (!fir.ref>) -> !fir.ref>> +// %16 = fir.coordinate_of %15, %arg3 : (!fir.ref>>, index) -> !fir.ref> +// %17 = fir.load %16 : !fir.ref> +// %18 = fir.convert %9 : (!fir.ref>) -> !fir.ref>> +// %19 = fir.coordinate_of %18, %arg3 : (!fir.ref>>, index) -> !fir.ref> +// fir.store %17 to %19 : !fir.ref> +// } +// %11:2 = hlfir.declare %9 typeparams %7 {uniq_name = "tmp"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %false = arith.constant false +// %12 = fir.undefined tuple, i1> +// %13 = fir.insert_value %12, %false, [1 : index] : (tuple, i1>, i1) -> tuple, i1> +// %14 = fir.insert_value %13, %11#0, [0 : index] : (tuple, i1>, !fir.boxchar<1>) -> tuple, i1> +// hlfir.assign %11#0 to %1#0 : !fir.boxchar<1>, !fir.boxchar<1> +// return +// } + +func.func @_QPmin1(%arg0: !fir.boxchar<1> {fir.bindc_name = "c1"}, %arg1: !fir.boxchar<1> {fir.bindc_name = "c2"}, %arg2: !fir.boxchar<1> {fir.bindc_name = "c3"}) { + %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %1:2 = hlfir.declare %0#0 typeparams %0#1 {uniq_name = "_QFmin1Ec1"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) + %2:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %3:2 = hlfir.declare %2#0 typeparams %2#1 {uniq_name = "_QFmin1Ec2"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) + %4:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %5:2 = hlfir.declare %4#0 typeparams %4#1 {uniq_name = "_QFmin1Ec3"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) + %6 = hlfir.char_extremum min, %3#0, %5#0 : (!fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> + hlfir.assign %6 to %1#0 : !hlfir.expr>, !fir.boxchar<1> + hlfir.destroy %6 : !hlfir.expr> + return +} + +// func.func @_QPmin1(%arg0: !fir.boxchar<1> {fir.bindc_name = "c1"}, %arg1: !fir.boxchar<1> {fir.bindc_name = "c2"}, %arg2: !fir.boxchar<1> {fir.bindc_name = "c3"}) { +// %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %1:2 = hlfir.declare %0#0 typeparams %0#1 {uniq_name = "_QFmin1Ec1"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %2:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %3:2 = hlfir.declare %2#0 typeparams %2#1 {uniq_name = "_QFmin1Ec2"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %4:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %5:2 = hlfir.declare %4#0 typeparams %4#1 {uniq_name = "_QFmin1Ec3"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %6 = arith.cmpi uge, %2#1, %4#1 : index +// %7 = arith.select %6, %2#1, %4#1 : index +// %8 = arith.cmpi ult, %2#1, %4#1 : index +// %9 = arith.select %8, %3#1, %5#1 : !fir.ref> +// %10 = fir.alloca !fir.char<1,?>(%7 : index) {bindc_name = ".chrtmp"} +// %c0 = arith.constant 0 : index +// %c1 = arith.constant 1 : index +// %11 = arith.subi %2#1, %c1 : index +// fir.do_loop %arg3 = %c0 to %11 step %c1 { +// %16 = fir.convert %9 : (!fir.ref>) -> !fir.ref>> +// %17 = fir.coordinate_of %16, %arg3 : (!fir.ref>>, index) -> !fir.ref> +// %18 = fir.load %17 : !fir.ref> +// %19 = fir.convert %10 : (!fir.ref>) -> !fir.ref>> +// %20 = fir.coordinate_of %19, %arg3 : (!fir.ref>>, index) -> !fir.ref> +// fir.store %18 to %20 : !fir.ref> +// } +// %12:2 = hlfir.declare %10 typeparams %7 {uniq_name = "tmp"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %false = arith.constant false +// %13 = fir.undefined tuple, i1> +// %14 = fir.insert_value %13, %false, [1 : index] : (tuple, i1>, i1) -> tuple, i1> +// %15 = fir.insert_value %14, %12#0, [0 : index] : (tuple, i1>, !fir.boxchar<1>) -> tuple, i1> +// hlfir.assign %12#0 to %1#0 : !fir.boxchar<1>, !fir.boxchar<1> +// return +// } + +func.func @_QPmax2(%arg0: !fir.boxchar<1> {fir.bindc_name = "c1"}, %arg1: !fir.boxchar<1> {fir.bindc_name = "c2"}, %arg2: !fir.boxchar<1> {fir.bindc_name = "c3"}) { + %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %1 = fir.convert %0#0 : (!fir.ref>) -> !fir.ref>> + %c100 = arith.constant 100 : index + %2 = fir.shape %c100 : (index) -> !fir.shape<1> + %3:2 = hlfir.declare %1(%2) typeparams %0#1 {uniq_name = "_QFmax2Ec1"} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.box>>, !fir.ref>>) + %4:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %c10 = arith.constant 10 : index + %5 = fir.convert %4#0 : (!fir.ref>) -> !fir.ref>> + %c100_0 = arith.constant 100 : index + %6 = fir.shape %c100_0 : (index) -> !fir.shape<1> + %7:2 = hlfir.declare %5(%6) typeparams %c10 {uniq_name = "_QFmax2Ec2"} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) + %8:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %c20 = arith.constant 20 : index + %9 = fir.convert %8#0 : (!fir.ref>) -> !fir.ref>> + %c100_1 = arith.constant 100 : index + %10 = fir.shape %c100_1 : (index) -> !fir.shape<1> + %11:2 = hlfir.declare %9(%10) typeparams %c20 {uniq_name = "_QFmax2Ec3"} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) + %c1 = arith.constant 1 : index + %12 = hlfir.designate %7#0 (%c1) typeparams %c10 : (!fir.ref>>, index, index) -> !fir.ref> + %c1_2 = arith.constant 1 : index + %13 = hlfir.designate %11#0 (%c1_2) typeparams %c20 : (!fir.ref>>, index, index) -> !fir.ref> + %14 = hlfir.char_extremum max, %12, %13 : (!fir.ref>, !fir.ref>) -> !hlfir.expr> + %c1_3 = arith.constant 1 : index + %15 = hlfir.designate %3#0 (%c1_3) typeparams %0#1 : (!fir.box>>, index, index) -> !fir.boxchar<1> + hlfir.assign %14 to %15 : !hlfir.expr>, !fir.boxchar<1> + hlfir.destroy %14 : !hlfir.expr> + return +} + +// func.func @_QPmax2(%arg0: !fir.boxchar<1> {fir.bindc_name = "c1"}, %arg1: !fir.boxchar<1> {fir.bindc_name = "c2"}, %arg2: !fir.boxchar<1> {fir.bindc_name = "c3"}) { +// %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %1 = fir.convert %0#0 : (!fir.ref>) -> !fir.ref>> +// %c100 = arith.constant 100 : index +// %2 = fir.shape %c100 : (index) -> !fir.shape<1> +// %3:2 = hlfir.declare %1(%2) typeparams %0#1 {uniq_name = "_QFmax2Ec1"} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.box>>, !fir.ref>>) +// %4:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %c10 = arith.constant 10 : index +// %5 = fir.convert %4#0 : (!fir.ref>) -> !fir.ref>> +// %c100_0 = arith.constant 100 : index +// %6 = fir.shape %c100_0 : (index) -> !fir.shape<1> +// %7:2 = hlfir.declare %5(%6) typeparams %c10 {uniq_name = "_QFmax2Ec2"} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) +// %8:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %c20 = arith.constant 20 : index +// %9 = fir.convert %8#0 : (!fir.ref>) -> !fir.ref>> +// %c100_1 = arith.constant 100 : index +// %10 = fir.shape %c100_1 : (index) -> !fir.shape<1> +// %11:2 = hlfir.declare %9(%10) typeparams %c20 {uniq_name = "_QFmax2Ec3"} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) +// %c1 = arith.constant 1 : index +// %12 = hlfir.designate %7#0 (%c1) typeparams %c10 : (!fir.ref>>, index, index) -> !fir.ref> +// %c1_2 = arith.constant 1 : index +// %13 = hlfir.designate %11#0 (%c1_2) typeparams %c20 : (!fir.ref>>, index, index) -> !fir.ref> +// %14 = fir.convert %12 : (!fir.ref>) -> !fir.ref> +// %15 = fir.convert %13 : (!fir.ref>) -> !fir.ref> +// %16 = arith.cmpi uge, %c10, %c20 : index +// %17 = arith.select %16, %c10, %c20 : index +// %18 = arith.select %16, %14, %15 : !fir.ref> +// %19 = fir.alloca !fir.char<1,?>(%17 : index) {bindc_name = ".chrtmp"} +// %c0 = arith.constant 0 : index +// %c1_3 = arith.constant 1 : index +// %20 = arith.subi %17, %c1_3 : index +// fir.do_loop %arg3 = %c0 to %20 step %c1_3 { +// %27 = fir.convert %18 : (!fir.ref>) -> !fir.ref>> +// %28 = fir.coordinate_of %27, %arg3 : (!fir.ref>>, index) -> !fir.ref> +// %29 = fir.load %28 : !fir.ref> +// %30 = fir.convert %19 : (!fir.ref>) -> !fir.ref>> +// %31 = fir.coordinate_of %30, %arg3 : (!fir.ref>>, index) -> !fir.ref> +// fir.store %29 to %31 : !fir.ref> +// } +// %21 = fir.convert %19 : (!fir.ref>) -> !fir.ref> +// %22:2 = hlfir.declare %21 typeparams %17 {uniq_name = "tmp"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) +// %false = arith.constant false +// %23 = fir.undefined tuple>, i1> +// %24 = fir.insert_value %23, %false, [1 : index] : (tuple>, i1>, i1) -> tuple>, i1> +// %25 = fir.insert_value %24, %22#0, [0 : index] : (tuple>, i1>, !fir.ref>) -> tuple>, i1> +// %c1_4 = arith.constant 1 : index +// %26 = hlfir.designate %3#0 (%c1_4) typeparams %0#1 : (!fir.box>>, index, index) -> !fir.boxchar<1> +// hlfir.assign %22#0 to %26 : !fir.ref>, !fir.boxchar<1> +// return +// } + +func.func @_QPmin2(%arg0: !fir.boxchar<1> {fir.bindc_name = "c1"}, %arg1: !fir.boxchar<1> {fir.bindc_name = "c2"}, %arg2: !fir.boxchar<1> {fir.bindc_name = "c3"}) { + %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %1 = fir.convert %0#0 : (!fir.ref>) -> !fir.ref>> + %c100 = arith.constant 100 : index + %2 = fir.shape %c100 : (index) -> !fir.shape<1> + %3:2 = hlfir.declare %1(%2) typeparams %0#1 {uniq_name = "_QFmin2Ec1"} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.box>>, !fir.ref>>) + %4:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %c10 = arith.constant 10 : index + %5 = fir.convert %4#0 : (!fir.ref>) -> !fir.ref>> + %c100_0 = arith.constant 100 : index + %6 = fir.shape %c100_0 : (index) -> !fir.shape<1> + %7:2 = hlfir.declare %5(%6) typeparams %c10 {uniq_name = "_QFmin2Ec2"} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) + %8:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %c20 = arith.constant 20 : index + %9 = fir.convert %8#0 : (!fir.ref>) -> !fir.ref>> + %c100_1 = arith.constant 100 : index + %10 = fir.shape %c100_1 : (index) -> !fir.shape<1> + %11:2 = hlfir.declare %9(%10) typeparams %c20 {uniq_name = "_QFmin2Ec3"} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) + %c1 = arith.constant 1 : index + %12 = hlfir.designate %7#0 (%c1) typeparams %c10 : (!fir.ref>>, index, index) -> !fir.ref> + %c1_2 = arith.constant 1 : index + %13 = hlfir.designate %11#0 (%c1_2) typeparams %c20 : (!fir.ref>>, index, index) -> !fir.ref> + %14 = hlfir.char_extremum min, %12, %13 : (!fir.ref>, !fir.ref>) -> !hlfir.expr> + %c1_3 = arith.constant 1 : index + %15 = hlfir.designate %3#0 (%c1_3) typeparams %0#1 : (!fir.box>>, index, index) -> !fir.boxchar<1> + hlfir.assign %14 to %15 : !hlfir.expr>, !fir.boxchar<1> + hlfir.destroy %14 : !hlfir.expr> + return +} + +// func.func @_QPmin2(%arg0: !fir.boxchar<1> {fir.bindc_name = "c1"}, %arg1: !fir.boxchar<1> {fir.bindc_name = "c2"}, %arg2: !fir.boxchar<1> {fir.bindc_name = "c3"}) { +// %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %1 = fir.convert %0#0 : (!fir.ref>) -> !fir.ref>> +// %c100 = arith.constant 100 : index +// %2 = fir.shape %c100 : (index) -> !fir.shape<1> +// %3:2 = hlfir.declare %1(%2) typeparams %0#1 {uniq_name = "_QFmin2Ec1"} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.box>>, !fir.ref>>) +// %4:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %c10 = arith.constant 10 : index +// %5 = fir.convert %4#0 : (!fir.ref>) -> !fir.ref>> +// %c100_0 = arith.constant 100 : index +// %6 = fir.shape %c100_0 : (index) -> !fir.shape<1> +// %7:2 = hlfir.declare %5(%6) typeparams %c10 {uniq_name = "_QFmin2Ec2"} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) +// %8:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %c20 = arith.constant 20 : index +// %9 = fir.convert %8#0 : (!fir.ref>) -> !fir.ref>> +// %c100_1 = arith.constant 100 : index +// %10 = fir.shape %c100_1 : (index) -> !fir.shape<1> +// %11:2 = hlfir.declare %9(%10) typeparams %c20 {uniq_name = "_QFmin2Ec3"} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) +// %c1 = arith.constant 1 : index +// %12 = hlfir.designate %7#0 (%c1) typeparams %c10 : (!fir.ref>>, index, index) -> !fir.ref> +// %c1_2 = arith.constant 1 : index +// %13 = hlfir.designate %11#0 (%c1_2) typeparams %c20 : (!fir.ref>>, index, index) -> !fir.ref> +// %14 = fir.convert %12 : (!fir.ref>) -> !fir.ref> +// %15 = fir.convert %13 : (!fir.ref>) -> !fir.ref> +// %16 = arith.cmpi uge, %c10, %c20 : index +// %17 = arith.select %16, %c10, %c20 : index +// %18 = arith.cmpi ult, %c10, %c20 : index +// %19 = arith.select %18, %14, %15 : !fir.ref> +// %20 = fir.alloca !fir.char<1,?>(%17 : index) {bindc_name = ".chrtmp"} +// %c0 = arith.constant 0 : index +// %c1_3 = arith.constant 1 : index +// %21 = arith.subi %c10, %c1_3 : index +// fir.do_loop %arg3 = %c0 to %21 step %c1_3 { +// %28 = fir.convert %19 : (!fir.ref>) -> !fir.ref>> +// %29 = fir.coordinate_of %28, %arg3 : (!fir.ref>>, index) -> !fir.ref> +// %30 = fir.load %29 : !fir.ref> +// %31 = fir.convert %20 : (!fir.ref>) -> !fir.ref>> +// %32 = fir.coordinate_of %31, %arg3 : (!fir.ref>>, index) -> !fir.ref> +// fir.store %30 to %32 : !fir.ref> +// } +// %22 = fir.convert %20 : (!fir.ref>) -> !fir.ref> +// %23:2 = hlfir.declare %22 typeparams %17 {uniq_name = "tmp"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) +// %false = arith.constant false +// %24 = fir.undefined tuple>, i1> +// %25 = fir.insert_value %24, %false, [1 : index] : (tuple>, i1>, i1) -> tuple>, i1> +// %26 = fir.insert_value %25, %23#0, [0 : index] : (tuple>, i1>, !fir.ref>) -> tuple>, i1> +// %c1_4 = arith.constant 1 : index +// %27 = hlfir.designate %3#0 (%c1_4) typeparams %0#1 : (!fir.box>>, index, index) -> !fir.boxchar<1> +// hlfir.assign %23#0 to %27 : !fir.ref>, !fir.boxchar<1> +// return +// } + +func.func @_QPmax3(%arg0: !fir.boxchar<1> {fir.bindc_name = "c1"}, %arg1: !fir.boxchar<1> {fir.bindc_name = "c2"}, %arg2: !fir.boxchar<1> {fir.bindc_name = "c3"}, %arg3: !fir.boxchar<1> {fir.bindc_name = "c4"}) { + %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %1:2 = hlfir.declare %0#0 typeparams %0#1 {uniq_name = "_QFmax3Ec1"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) + %2:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %3:2 = hlfir.declare %2#0 typeparams %2#1 {uniq_name = "_QFmax3Ec2"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) + %4:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %5:2 = hlfir.declare %4#0 typeparams %4#1 {uniq_name = "_QFmax3Ec3"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) + %6:2 = fir.unboxchar %arg3 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %7:2 = hlfir.declare %6#0 typeparams %6#1 {uniq_name = "_QFmax3Ec4"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) + %8 = hlfir.char_extremum max, %3#0, %5#0, %7#0 : (!fir.boxchar<1>, !fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> + hlfir.assign %8 to %1#0 : !hlfir.expr>, !fir.boxchar<1> + hlfir.destroy %8 : !hlfir.expr> + return +} + +// func.func @_QPmax3(%arg0: !fir.boxchar<1> {fir.bindc_name = "c1"}, %arg1: !fir.boxchar<1> {fir.bindc_name = "c2"}, %arg2: !fir.boxchar<1> {fir.bindc_name = "c3"}, %arg3: !fir.boxchar<1> {fir.bindc_name = "c4"}) { +// %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %1:2 = hlfir.declare %0#0 typeparams %0#1 {uniq_name = "_QFmax3Ec1"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %2:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %3:2 = hlfir.declare %2#0 typeparams %2#1 {uniq_name = "_QFmax3Ec2"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %4:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %5:2 = hlfir.declare %4#0 typeparams %4#1 {uniq_name = "_QFmax3Ec3"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %6:2 = fir.unboxchar %arg3 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %7:2 = hlfir.declare %6#0 typeparams %6#1 {uniq_name = "_QFmax3Ec4"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %8 = arith.cmpi uge, %2#1, %4#1 : index +// %9 = arith.select %8, %2#1, %4#1 : index +// %10 = arith.select %8, %3#1, %5#1 : !fir.ref> +// %11 = arith.cmpi uge, %9, %6#1 : index +// %12 = arith.select %11, %9, %6#1 : index +// %13 = arith.select %11, %10, %7#1 : !fir.ref> +// %14 = fir.alloca !fir.char<1,?>(%12 : index) {bindc_name = ".chrtmp"} +// %c0 = arith.constant 0 : index +// %c1 = arith.constant 1 : index +// %15 = arith.subi %12, %c1 : index +// fir.do_loop %arg4 = %c0 to %15 step %c1 { +// %20 = fir.convert %13 : (!fir.ref>) -> !fir.ref>> +// %21 = fir.coordinate_of %20, %arg4 : (!fir.ref>>, index) -> !fir.ref> +// %22 = fir.load %21 : !fir.ref> +// %23 = fir.convert %14 : (!fir.ref>) -> !fir.ref>> +// %24 = fir.coordinate_of %23, %arg4 : (!fir.ref>>, index) -> !fir.ref> +// fir.store %22 to %24 : !fir.ref> +// } +// %16:2 = hlfir.declare %14 typeparams %12 {uniq_name = "tmp"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %false = arith.constant false +// %17 = fir.undefined tuple, i1> +// %18 = fir.insert_value %17, %false, [1 : index] : (tuple, i1>, i1) -> tuple, i1> +// %19 = fir.insert_value %18, %16#0, [0 : index] : (tuple, i1>, !fir.boxchar<1>) -> tuple, i1> +// hlfir.assign %16#0 to %1#0 : !fir.boxchar<1>, !fir.boxchar<1> +// return +// } + +func.func @_QPmin3(%arg0: !fir.boxchar<1> {fir.bindc_name = "c1"}, %arg1: !fir.boxchar<1> {fir.bindc_name = "c2"}, %arg2: !fir.boxchar<1> {fir.bindc_name = "c3"}, %arg3: !fir.boxchar<1> {fir.bindc_name = "c4"}) { + %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %1:2 = hlfir.declare %0#0 typeparams %0#1 {uniq_name = "_QFmin3Ec1"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) + %2:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %3:2 = hlfir.declare %2#0 typeparams %2#1 {uniq_name = "_QFmin3Ec2"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) + %4:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %5:2 = hlfir.declare %4#0 typeparams %4#1 {uniq_name = "_QFmin3Ec3"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) + %6:2 = fir.unboxchar %arg3 : (!fir.boxchar<1>) -> (!fir.ref>, index) + %7:2 = hlfir.declare %6#0 typeparams %6#1 {uniq_name = "_QFmin3Ec4"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) + %8 = hlfir.char_extremum min, %3#0, %5#0, %7#0 : (!fir.boxchar<1>, !fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> + hlfir.assign %8 to %1#0 : !hlfir.expr>, !fir.boxchar<1> + hlfir.destroy %8 : !hlfir.expr> + return +} + +// func.func @_QPmin3(%arg0: !fir.boxchar<1> {fir.bindc_name = "c1"}, %arg1: !fir.boxchar<1> {fir.bindc_name = "c2"}, %arg2: !fir.boxchar<1> {fir.bindc_name = "c3"}, %arg3: !fir.boxchar<1> {fir.bindc_name = "c4"}) { +// %0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %1:2 = hlfir.declare %0#0 typeparams %0#1 {uniq_name = "_QFmin3Ec1"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %2:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %3:2 = hlfir.declare %2#0 typeparams %2#1 {uniq_name = "_QFmin3Ec2"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %4:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %5:2 = hlfir.declare %4#0 typeparams %4#1 {uniq_name = "_QFmin3Ec3"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %6:2 = fir.unboxchar %arg3 : (!fir.boxchar<1>) -> (!fir.ref>, index) +// %7:2 = hlfir.declare %6#0 typeparams %6#1 {uniq_name = "_QFmin3Ec4"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %8 = arith.cmpi uge, %2#1, %4#1 : index +// %9 = arith.select %8, %2#1, %4#1 : index +// %10 = arith.cmpi ult, %2#1, %4#1 : index +// %11 = arith.select %10, %3#1, %5#1 : !fir.ref> +// %12 = arith.cmpi uge, %9, %6#1 : index +// %13 = arith.select %12, %9, %6#1 : index +// %14 = arith.cmpi ult, %2#1, %6#1 : index +// %15 = arith.select %14, %11, %7#1 : !fir.ref> +// %16 = fir.alloca !fir.char<1,?>(%13 : index) {bindc_name = ".chrtmp"} +// %c0 = arith.constant 0 : index +// %c1 = arith.constant 1 : index +// %17 = arith.subi %2#1, %c1 : index +// fir.do_loop %arg4 = %c0 to %17 step %c1 { +// %22 = fir.convert %15 : (!fir.ref>) -> !fir.ref>> +// %23 = fir.coordinate_of %22, %arg4 : (!fir.ref>>, index) -> !fir.ref> +// %24 = fir.load %23 : !fir.ref> +// %25 = fir.convert %16 : (!fir.ref>) -> !fir.ref>> +// %26 = fir.coordinate_of %25, %arg4 : (!fir.ref>>, index) -> !fir.ref> +// fir.store %24 to %26 : !fir.ref> +// } +// %18:2 = hlfir.declare %16 typeparams %13 {uniq_name = "tmp"} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +// %false = arith.constant false +// %19 = fir.undefined tuple, i1> +// %20 = fir.insert_value %19, %false, [1 : index] : (tuple, i1>, i1) -> tuple, i1> +// %21 = fir.insert_value %20, %18#0, [0 : index] : (tuple, i1>, !fir.boxchar<1>) -> tuple, i1> +// hlfir.assign %18#0 to %1#0 : !fir.boxchar<1>, !fir.boxchar<1> +// return +// } + + + + + + diff --git a/flang/test/HLFIR/char_extremum.fir b/flang/test/HLFIR/char_extremum.fir new file mode 100644 --- /dev/null +++ b/flang/test/HLFIR/char_extremum.fir @@ -0,0 +1,130 @@ +// Test hlfir.char_extremum operation parse, verify (no errors), and unparse. + +// RUN: fir-opt %s | fir-opt | FileCheck %s + + +// variable check +func.func @char_extremum_min_var(%arg0: !fir.ref>, %arg1: !fir.ref>) { + %0 = hlfir.char_extremum min, %arg0, %arg1 : (!fir.ref>, !fir.ref>) -> !hlfir.expr> + return +} + +// CHECK-LABEL: func.func @char_extremum_min_var( +// CHECK-SAME: %[[VAL_0:[a-zA-Z0-9_]*]]: !fir.ref>, +// CHECK-SAME: %[[VAL_1:[a-zA-Z0-9_]*]]: !fir.ref>) { +// CHECK: %{{.*}} = hlfir.char_extremum min, %[[VAL_0]], %[[VAL_1]] : (!fir.ref>, !fir.ref>) -> !hlfir.expr> + +func.func @char_extremum_max_var(%arg0: !fir.ref>, %arg1: !fir.ref>) { +%0 = hlfir.char_extremum min, %arg0, %arg1 : (!fir.ref>, !fir.ref>) -> !hlfir.expr> +return +} + +// CHECK-LABEL: func.func @char_extremum_max_var( +// CHECK-SAME: %[[VAL_0:[a-zA-Z0-9_]*]]: !fir.ref>, +// CHECK-SAME: %[[VAL_1:[a-zA-Z0-9_]*]]: !fir.ref>) { +// CHECK: %{{.*}} = hlfir.char_extremum min, %[[VAL_0]], %[[VAL_1]] : (!fir.ref>, !fir.ref>) -> !hlfir.expr> + +func.func @char_extremum_min_var_variadic(%arg0: !fir.ref>, %arg1: !fir.ref>, %arg2: !fir.ref>) { + %0 = hlfir.char_extremum min, %arg0, %arg1, %arg2 : (!fir.ref>, !fir.ref>, !fir.ref>) -> !hlfir.expr> + return +} + +// CHECK-LABEL: func.func @char_extremum_min_var_variadic( +// CHECK-SAME: %[[VAL_0:[a-zA-Z0-9_]*]]: !fir.ref>, +// CHECK-SAME: %[[VAL_1:[a-zA-Z0-9_]*]]: !fir.ref>, +// CHECK-SAME: %[[VAL_2:.*]]: !fir.ref>) { +// CHECK: %{{.*}} = hlfir.char_extremum min, %[[VAL_0]], %[[VAL_1]], %[[VAL_2]] : (!fir.ref>, !fir.ref>, !fir.ref>) -> !hlfir.expr> + +func.func @char_extremum_max_var_variadic(%arg0: !fir.ref>, %arg1: !fir.ref>, %arg2: !fir.ref>) { + %0 = hlfir.char_extremum max, %arg0, %arg1, %arg2 : (!fir.ref>, !fir.ref>, !fir.ref>) -> !hlfir.expr> + return +} + +// CHECK-LABEL: func.func @char_extremum_max_var_variadic( +// CHECK-SAME: %[[VAL_0:[a-zA-Z0-9_]*]]: !fir.ref>, +// CHECK-SAME: %[[VAL_1:[a-zA-Z0-9_]*]]: !fir.ref>, +// CHECK-SAME: %[[VAL_2:.*]]: !fir.ref>) { +// CHECK: %{{.*}} = hlfir.char_extremum max, %[[VAL_0]], %[[VAL_1]], %[[VAL_2]] : (!fir.ref>, !fir.ref>, !fir.ref>) -> !hlfir.expr> + + +// boxchar check +func.func @char_extremum_min_boxchar(%arg0: !fir.boxchar<1>, %arg1: !fir.boxchar<1>) { + %0 = hlfir.char_extremum min, %arg0, %arg1 : (!fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> + return +} +// CHECK-LABEL: func.func @char_extremum_min_boxchar( +// CHECK-SAME: %[[VAL_0:[a-zA-Z0-9_]*]]: !fir.boxchar<1>, +// CHECK-SAME: %[[VAL_1:[a-zA-Z0-9_]*]]: !fir.boxchar<1>) { +// CHECK: %{{.*}} = hlfir.char_extremum min, %[[VAL_0]], %[[VAL_1]] : (!fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> + +func.func @char_extremum_max_boxchar(%arg0: !fir.boxchar<1>, %arg1: !fir.boxchar<1>) { + %0 = hlfir.char_extremum max, %arg0, %arg1 : (!fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> + return +} +// CHECK-LABEL: func.func @char_extremum_max_boxchar( +// CHECK-SAME: %[[VAL_0:[a-zA-Z0-9_]*]]: !fir.boxchar<1>, +// CHECK-SAME: %[[VAL_1:[a-zA-Z0-9_]*]]: !fir.boxchar<1>) { +// CHECK: %{{.*}} = hlfir.char_extremum max, %[[VAL_0]], %[[VAL_1]] : (!fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> + +func.func @char_extremum_min_boxchar_variadic(%arg0: !fir.boxchar<1>, %arg1: !fir.boxchar<1>, %arg2: !fir.boxchar<1>, %arg3: !fir.boxchar<1>) { + %0 = hlfir.char_extremum min, %arg0, %arg1, %arg2, %arg3 : (!fir.boxchar<1>, !fir.boxchar<1>, !fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> + return +} +// CHECK-LABEL: func.func @char_extremum_min_boxchar_variadic( +// CHECK-SAME: %[[VAL_0:[a-zA-Z0-9_]*]]: !fir.boxchar<1>, +// CHECK-SAME: %[[VAL_1:[a-zA-Z0-9_]*]]: !fir.boxchar<1>, +// CHECK-SAME: %[[VAL_2:[a-zA-Z0-9_]*]]: !fir.boxchar<1>, +// CHECK-SAME: %[[VAL_3:[a-zA-Z0-9_]*]]: !fir.boxchar<1>) { +// CHECK: %{{.*}} = hlfir.char_extremum min, %[[VAL_0]], %[[VAL_1]], %[[VAL_2]], %[[VAL_3]] : (!fir.boxchar<1>, !fir.boxchar<1>, !fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> + +func.func @char_extremum_max_boxchar_variadic(%arg0: !fir.boxchar<1>, %arg1: !fir.boxchar<1>, %arg2: !fir.boxchar<1>, %arg3: !fir.boxchar<1>) { + %0 = hlfir.char_extremum max, %arg0, %arg1, %arg2, %arg3 : (!fir.boxchar<1>, !fir.boxchar<1>, !fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> + return +} +// CHECK-LABEL: func.func @char_extremum_max_boxchar_variadic( +// CHECK-SAME: %[[VAL_0:[a-zA-Z0-9_]*]]: !fir.boxchar<1>, +// CHECK-SAME: %[[VAL_1:[a-zA-Z0-9_]*]]: !fir.boxchar<1>, +// CHECK-SAME: %[[VAL_2:[a-zA-Z0-9_]*]]: !fir.boxchar<1>, +// CHECK-SAME: %[[VAL_3:[a-zA-Z0-9_]*]]: !fir.boxchar<1>) { +// CHECK: %{{.*}} = hlfir.char_extremum max, %[[VAL_0]], %[[VAL_1]], %[[VAL_2]], %[[VAL_3]] : (!fir.boxchar<1>, !fir.boxchar<1>, !fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> + + +//expr check +func.func @char_extremum_min_expr(%arg0: !hlfir.expr>, %arg1: !hlfir.expr>) { + %0 = hlfir.char_extremum min, %arg0, %arg1 : (!hlfir.expr>, !hlfir.expr>) -> (!hlfir.expr>) + return +} +// CHECK-LABEL: func.func @char_extremum_min_expr( +// CHECK-SAME: %[[VAL_0:[a-zA-Z0-9_]*]]: !hlfir.expr>, +// CHECK-SAME: %[[VAL_1:[a-zA-Z0-9_]*]]: !hlfir.expr>) { +// CHECK: %{{.*}} = hlfir.char_extremum min, %[[VAL_0]], %[[VAL_1]] : (!hlfir.expr>, !hlfir.expr>) -> !hlfir.expr> + +func.func @char_extremum_max_expr(%arg0: !hlfir.expr>, %arg1: !hlfir.expr>) { + %0 = hlfir.char_extremum max, %arg0, %arg1 : (!hlfir.expr>, !hlfir.expr>) -> (!hlfir.expr>) + return +} +// CHECK-LABEL: func.func @char_extremum_max_expr( +// CHECK-SAME: %[[VAL_0:[a-zA-Z0-9_]*]]: !hlfir.expr>, +// CHECK-SAME: %[[VAL_1:[a-zA-Z0-9_]*]]: !hlfir.expr>) { +// CHECK: %{{.*}} = hlfir.char_extremum max, %[[VAL_0]], %[[VAL_1]] : (!hlfir.expr>, !hlfir.expr>) -> !hlfir.expr> + +func.func @char_extremum_min_expr_variadic(%arg0: !hlfir.expr>, %arg1: !hlfir.expr>, %arg2: !hlfir.expr>) { + %0 = hlfir.char_extremum min, %arg0, %arg1, %arg2 : (!hlfir.expr>, !hlfir.expr>, !hlfir.expr>) -> (!hlfir.expr>) + return +} +// CHECK-LABEL: func.func @char_extremum_min_expr_variadic( +// CHECK-SAME: %[[VAL_0:[a-zA-Z0-9_]*]]: !hlfir.expr>, +// CHECK-SAME: %[[VAL_1:[a-zA-Z0-9_]*]]: !hlfir.expr>, +// CHECK-SAME: %[[VAL_2:[a-zA-Z0-9_]*]]: !hlfir.expr>) { +// CHECK: %{{.*}} = hlfir.char_extremum min, %[[VAL_0]], %[[VAL_1]], %[[VAL_2]] : (!hlfir.expr>, !hlfir.expr>, !hlfir.expr>) -> !hlfir.expr> + +func.func @char_extremum_max_expr_variadic(%arg0: !hlfir.expr>, %arg1: !hlfir.expr>, %arg2: !hlfir.expr>) { + %0 = hlfir.char_extremum max, %arg0, %arg1, %arg2 : (!hlfir.expr>, !hlfir.expr>, !hlfir.expr>) -> (!hlfir.expr>) + return +} +// CHECK-LABEL: func.func @char_extremum_max_expr_variadic( +// CHECK-SAME: %[[VAL_0:[a-zA-Z0-9_]*]]: !hlfir.expr>, +// CHECK-SAME: %[[VAL_1:[a-zA-Z0-9_]*]]: !hlfir.expr>, +// CHECK-SAME: %[[VAL_2:[a-zA-Z0-9_]*]]: !hlfir.expr>) { +// CHECK: %{{.*}} = hlfir.char_extremum max, %[[VAL_0]], %[[VAL_1]], %[[VAL_2]] : (!hlfir.expr>, !hlfir.expr>, !hlfir.expr>) -> !hlfir.expr> + diff --git a/flang/test/Lower/HLFIR/char_extremum.f03 b/flang/test/Lower/HLFIR/char_extremum.f03 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/HLFIR/char_extremum.f03 @@ -0,0 +1,134 @@ +! Test lowering of the max and min intrinsics on character types to HLFIR +! RUN: bbc -emit-fir -hlfir -o - %s 2>&1 | FileCheck %s + +subroutine max1(c1, c2, c3) + character(*) :: c1, c2, c3 + c1 = max(c2,c3) +end subroutine + +! CHECK-LABEL: func.func @_QPmax1 +! CHECK: %[[VAL_0:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %{{.*}} : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_1:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_0]]#0 typeparams %[[VAL_0]]#1 {{.*}} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +! CHECK: %[[VAL_2:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %{{.*}} : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_3:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_2]]#0 typeparams %[[VAL_2]]#1 {{.*}} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +! CHECK: %[[VAL_4:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %{{.*}} : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_5:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_4]]#0 typeparams %[[VAL_4]]#1 {{.*}} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +! CHECK: %[[VAL_6:[a-zA-Z0-9_]*]] = hlfir.char_extremum max, %[[VAL_3]]#0, %[[VAL_5]]#0 : (!fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> +! CHECK: hlfir.assign %[[VAL_6]] to %[[VAL_1]]#0 : !hlfir.expr>, !fir.boxchar<1> +! CHECK: hlfir.destroy %[[VAL_6]] : !hlfir.expr> + +subroutine min1(c1, c2, c3) + character(*) :: c1, c2, c3 + c1 = min(c2,c3) +end subroutine +! CHECK-LABEL: func.func @_QPmin1 +! CHECK: %[[VAL_0:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %{{.*}} : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_1:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_0]]#0 typeparams %[[VAL_0]]#1 {{.*}} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +! CHECK: %[[VAL_2:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %{{.*}} : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_3:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_2]]#0 typeparams %[[VAL_2]]#1 {{.*}} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +! CHECK: %[[VAL_4:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %{{.*}} : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_5:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_4]]#0 typeparams %[[VAL_4]]#1 {{.*}} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +! CHECK: %[[VAL_6:[a-zA-Z0-9_]*]] = hlfir.char_extremum min, %[[VAL_3]]#0, %[[VAL_5]]#0 : (!fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> +! CHECK: hlfir.assign %[[VAL_6]] to %[[VAL_1]]#0 : !hlfir.expr>, !fir.boxchar<1> +! CHECK: hlfir.destroy %[[VAL_6]] : !hlfir.expr> +! CHECK: return + +subroutine max2(c1, c2, c3) + character(*) :: c1(100) + character :: c2(100)*10, c3(100)*20 + c1(1) = max(c2(1),c3(1)) +end subroutine +! CHECK-LABEL: func.func @_QPmax2 +! CHECK: %[[VAL_0:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %{{.*}} : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_1:[a-zA-Z0-9_]*]] = fir.convert %[[VAL_0]]#0 : (!fir.ref>) -> !fir.ref>> +! CHECK: %[[VAL_C100:[a-zA-Z0-9_]*]] = arith.constant 100 : index +! CHECK: %[[VAL_2:[a-zA-Z0-9_]*]] = fir.shape %[[VAL_C100]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_3:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_1]](%[[VAL_2]]) typeparams %[[VAL_0]]#1 {{.*}} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.box>>, !fir.ref>>) +! CHECK: %[[VAL_4:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %{{.*}} : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_C10:[a-zA-Z0-9_]*]] = arith.constant 10 : index +! CHECK: %[[VAL_5:[a-zA-Z0-9_]*]] = fir.convert %[[VAL_4]]#0 : (!fir.ref>) -> !fir.ref>> +! CHECK: %[[VAL_C100_0:[a-zA-Z0-9_]*]] = arith.constant 100 : index +! CHECK: %[[VAL_6:[a-zA-Z0-9_]*]] = fir.shape %[[VAL_C100_0]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_7:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_5]](%[[VAL_6]]) typeparams %[[VAL_C10]] {{.*}} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) +! CHECK: %[[VAL_8:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %{{.*}} : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_C20:[a-zA-Z0-9_]*]] = arith.constant 20 : index +! CHECK: %[[VAL_9:[a-zA-Z0-9_]*]] = fir.convert %[[VAL_8]]#0 : (!fir.ref>) -> !fir.ref>> +! CHECK: %[[VAL_C100_1:[a-zA-Z0-9_]*]] = arith.constant 100 : index +! CHECK: %[[VAL_10:[a-zA-Z0-9_]*]] = fir.shape %[[VAL_C100_1]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_11:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_9]](%[[VAL_10]]) typeparams %[[VAL_C20]] {{.*}} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) +! CHECK: %[[VAL_C1:[a-zA-Z0-9_]*]] = arith.constant 1 : index +! CHECK: %[[VAL_12:[a-zA-Z0-9_]*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_C1]]) typeparams %[[VAL_C10]] : (!fir.ref>>, index, index) -> !fir.ref> +! CHECK: %[[VAL_C1_2:[a-zA-Z0-9_]*]] = arith.constant 1 : index +! CHECK: %[[VAL_13:[a-zA-Z0-9_]*]] = hlfir.designate %[[VAL_11]]#0 (%[[VAL_C1_2]]) typeparams %[[VAL_C20]] : (!fir.ref>>, index, index) -> !fir.ref> +! CHECK: %[[VAL_14:[a-zA-Z0-9_]*]] = hlfir.char_extremum max, %[[VAL_12]], %[[VAL_13]] : (!fir.ref>, !fir.ref>) -> !hlfir.expr> +! CHECK: %c1_3 = arith.constant 1 : index +! CHECK: %[[VAL_15:[a-zA-Z0-9_]*]] = hlfir.designate %[[VAL_3]]#0 (%c1_3) typeparams %[[VAL_0]]#1 : (!fir.box>>, index, index) -> !fir.boxchar<1> +! CHECK: hlfir.assign %[[VAL_14]] to %[[VAL_15]] : !hlfir.expr>, !fir.boxchar<1> +! CHECK: hlfir.destroy %[[VAL_14]] : !hlfir.expr> + +subroutine min2(c1, c2, c3) + character(*) :: c1(100) + character :: c2(100)*10, c3(100)*20 + c1(1) = min(c2(1),c3(1)) +end subroutine +! CHECK-LABEL: func.func @_QPmin2 +! CHECK: %[[VAL_0:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_1:[a-zA-Z0-9_]*]] = fir.convert %[[VAL_0]]#0 : (!fir.ref>) -> !fir.ref>> +! CHECK: %[[VAL_C100:[a-zA-Z0-9_]*]] = arith.constant 100 : index +! CHECK: %[[VAL_2:[a-zA-Z0-9_]*]] = fir.shape %[[VAL_C100]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_3:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_1]](%[[VAL_2]]) typeparams %[[VAL_0]]#1 {{.*}} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.box>>, !fir.ref>>) +! CHECK: %[[VAL_4:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_C10:[a-zA-Z0-9_]*]] = arith.constant 10 : index +! CHECK: %[[VAL_5:[a-zA-Z0-9_]*]] = fir.convert %[[VAL_4]]#0 : (!fir.ref>) -> !fir.ref>> +! CHECK: %[[VAL_C100_0:[a-zA-Z0-9_]*]] = arith.constant 100 : index +! CHECK: %[[VAL_6:[a-zA-Z0-9_]*]] = fir.shape %[[VAL_C100_0]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_7:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_5]](%[[VAL_6]]) typeparams %[[VAL_C10]] {{.*}} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) +! CHECK: %[[VAL_8:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_C20:[a-zA-Z0-9_]*]] = arith.constant 20 : index +! CHECK: %[[VAL_C9:[a-zA-Z0-9_]*]] = fir.convert %[[VAL_8]]#0 : (!fir.ref>) -> !fir.ref>> +! CHECK: %[[VAL_C100_1:[a-zA-Z0-9_]*]] = arith.constant 100 : index +! CHECK: %[[VAL_10:[a-zA-Z0-9_]*]] = fir.shape %[[VAL_C100_1]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_11:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_C9]](%[[VAL_10]]) typeparams %[[VAL_C20]] {{.*}} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) +! CHECK: %[[VAL_C1:[a-zA-Z0-9_]*]] = arith.constant 1 : index +! CHECK: %[[VAL_12:[a-zA-Z0-9_]*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_C1]]) typeparams %[[VAL_C10]] : (!fir.ref>>, index, index) -> !fir.ref> +! CHECK: %[[VAL_C1_2:[a-zA-Z0-9_]*]] = arith.constant 1 : index +! CHECK: %[[VAL_13:[a-zA-Z0-9_]*]] = hlfir.designate %[[VAL_11]]#0 (%[[VAL_C1_2]]) typeparams %[[VAL_C20]] : (!fir.ref>>, index, index) -> !fir.ref> +! CHECK: %[[VAL_14:[a-zA-Z0-9_]*]] = hlfir.char_extremum min, %[[VAL_12]], %[[VAL_13]] : (!fir.ref>, !fir.ref>) -> !hlfir.expr> +! CHECK: %[[VAL_C1_3:[a-zA-Z0-9_]*]] = arith.constant 1 : index +! CHECK: %[[VAL_15:[a-zA-Z0-9_]*]] = hlfir.designate %[[VAL_3]]#0 (%[[VAL_C1_3]]) typeparams %[[VAL_0]]#1 : (!fir.box>>, index, index) -> !fir.boxchar<1> +! CHECK: hlfir.assign %[[VAL_14]] to %[[VAL_15]] : !hlfir.expr>, !fir.boxchar<1> +! CHECK: hlfir.destroy %[[VAL_14]] : !hlfir.expr> + +subroutine max3(c1, c2, c3, c4) + character(*) :: c1, c2, c3, c4 + c1 = max(c2, c3, c4) +end subroutine +! CHECK-LABEL: func.func @_QPmax3 +! CHECK: %[[VAL_0:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_1:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_0]]#0 typeparams %[[VAL_0]]#1 {{.*}} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +! CHECK: %[[VAL_2:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_3:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_2]]#0 typeparams %[[VAL_2]]#1 {{.*}} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +! CHECK: %[[VAL_4:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_5:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_4]]#0 typeparams %[[VAL_4]]#1 {{.*}} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +! CHECK: %[[VAL_6:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %arg3 : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_7:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_6]]#0 typeparams %[[VAL_6]]#1 {{.*}} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +! CHECK: %[[VAL_8:[a-zA-Z0-9_]*]] = hlfir.char_extremum max, %[[VAL_3]]#0, %[[VAL_5]]#0, %[[VAL_7]]#0 : (!fir.boxchar<1>, !fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> +! CHECK: hlfir.assign %[[VAL_8]] to %[[VAL_1]]#0 : !hlfir.expr>, !fir.boxchar<1> +! CHECK: hlfir.destroy %[[VAL_8]] : !hlfir.expr> + +subroutine min3(c1, c2, c3, c4) + character(*) :: c1, c2, c3, c4 + c1 = min(c2, c3, c4) +end subroutine +! CHECK-LABEL: func.func @_QPmin3 +! CHECK: %[[VAL_0:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_1:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_0]]#0 typeparams %[[VAL_0]]#1 {{.*}} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +! CHECK: %[[VAL_2:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_3:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_2]]#0 typeparams %[[VAL_2]]#1 {{.*}} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +! CHECK: %[[VAL_4:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %arg2 : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_5:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_4]]#0 typeparams %[[VAL_4]]#1 {{.*}} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +! CHECK: %[[VAL_6:[a-zA-Z0-9_]*]]:2 = fir.unboxchar %arg3 : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[VAL_7:[a-zA-Z0-9_]*]]:2 = hlfir.declare %[[VAL_6]]#0 typeparams %[[VAL_6]]#1 {{.*}} : (!fir.ref>, index) -> (!fir.boxchar<1>, !fir.ref>) +! CHECK: %[[VAL_8:[a-zA-Z0-9_]*]] = hlfir.char_extremum min, %[[VAL_3]]#0, %[[VAL_5]]#0, %[[VAL_7]]#0 : (!fir.boxchar<1>, !fir.boxchar<1>, !fir.boxchar<1>) -> !hlfir.expr> +! CHECK: hlfir.assign %[[VAL_8]] to %[[VAL_1]]#0 : !hlfir.expr>, !fir.boxchar<1> +! CHECK: hlfir.destroy %[[VAL_8]] : !hlfir.expr>