From 4571f8aa05a1eb88532edfcf7e144633535d5e85 Mon Sep 17 00:00:00 2001 From: Andrzej Warzynski Date: Thu, 17 Mar 2022 17:22:46 +0000 Subject: [PATCH] [flang][lowering] Add support for lowering of the `ior` intrinsic This patch adds support for lowering of the `ior` intrinsic from Fortran to the FIR dialect of MLIR. This is part of the upstreaming effort from the `fir-dev` branch in [1]. [1] https://github.com/flang-compiler/f18-llvm-project Differential Revision: https://reviews.llvm.org/D121928 Co-authored-by: Jean Perier Co-authored-by: V Donaldson Co-authored-by: Eric Schweitz --- flang/lib/Lower/IntrinsicCall.cpp | 9 +++++++++ flang/test/Lower/Intrinsics/ior.f90 | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 flang/test/Lower/Intrinsics/ior.f90 diff --git a/flang/lib/Lower/IntrinsicCall.cpp b/flang/lib/Lower/IntrinsicCall.cpp index 8fba5c180175..5c82f594e02c 100644 --- a/flang/lib/Lower/IntrinsicCall.cpp +++ b/flang/lib/Lower/IntrinsicCall.cpp @@ -485,6 +485,7 @@ struct IntrinsicLibrary { fir::ExtendedValue genIchar(mlir::Type, llvm::ArrayRef); mlir::Value genIeor(mlir::Type, llvm::ArrayRef); fir::ExtendedValue genIndex(mlir::Type, llvm::ArrayRef); + mlir::Value genIor(mlir::Type, llvm::ArrayRef); mlir::Value genIshft(mlir::Type, llvm::ArrayRef); mlir::Value genIshftc(mlir::Type, llvm::ArrayRef); fir::ExtendedValue genLbound(mlir::Type, llvm::ArrayRef); @@ -735,6 +736,7 @@ static constexpr IntrinsicHandler handlers[]{ {"substring", asAddr}, {"back", asValue, handleDynamicOptional}, {"kind", asValue}}}}, + {"ior", &I::genIor}, {"ishft", &I::genIshft}, {"ishftc", &I::genIshftc}, {"lbound", @@ -2512,6 +2514,13 @@ IntrinsicLibrary::genIndex(mlir::Type resultType, return readAndAddCleanUp(mutBox, resultType, "INDEX"); } +// IOR +mlir::Value IntrinsicLibrary::genIor(mlir::Type resultType, + llvm::ArrayRef args) { + assert(args.size() == 2); + return builder.create(loc, args[0], args[1]); +} + // ISHFT mlir::Value IntrinsicLibrary::genIshft(mlir::Type resultType, llvm::ArrayRef args) { diff --git a/flang/test/Lower/Intrinsics/ior.f90 b/flang/test/Lower/Intrinsics/ior.f90 new file mode 100644 index 000000000000..35f1997ba15a --- /dev/null +++ b/flang/test/Lower/Intrinsics/ior.f90 @@ -0,0 +1,10 @@ +! RUN: bbc -emit-fir %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s + +! CHECK-LABEL: ior_test +subroutine ior_test(a, b) + integer :: a, b + print *, ior(a, b) + ! CHECK: %{{[0-9]+}} = arith.ori %{{[0-9]+}}, %{{[0-9]+}} : i{{(8|16|32|64|128)}} +end subroutine ior_test +