[flang-commits] [flang] [flang] Implement non-standard LNBLNK intrinsic (PR #117589)
via flang-commits
flang-commits at lists.llvm.org
Mon Nov 25 10:11:48 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Tom Eccles (tblah)
<details>
<summary>Changes</summary>
This is defined here
https://gcc.gnu.org/onlinedocs/gfortran/LNBLNK.html. It is just an alias to LEN_TRIM.
This was requested by a user:
https://discourse.llvm.org/t/unresolved-externals-with-appendend-underscore/83305
---
Full diff: https://github.com/llvm/llvm-project/pull/117589.diff
4 Files Affected:
- (modified) flang/docs/Intrinsics.md (+3)
- (modified) flang/lib/Evaluate/intrinsics.cpp (+1)
- (modified) flang/lib/Optimizer/Builder/IntrinsicCall.cpp (+1)
- (modified) flang/test/Lower/Intrinsics/len_trim.f90 (+19)
``````````diff
diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index 0196be10d86556..94bca7a3972b6e 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -1052,6 +1052,9 @@ end program rename_proc
This intrinsic is an alias for `CPU_TIME`: supporting both a subroutine and a
function form.
+### Non-standard Intrinsics: LNBLNK
+This intrinsic is an alias for `LEN_TRIM`, without the optional KIND argument.
+
#### Usage and Info
- **Standard:** GNU extension
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 1e27c0ae4216c5..ff6ccf154f17a5 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -616,6 +616,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
DefaultLogical},
{"llt", {{"string_a", SameCharNoLen}, {"string_b", SameCharNoLen}},
DefaultLogical},
+ {"lnblnk", {{"string", AnyChar}}, DefaultInt},
{"loc", {{"x", Addressable, Rank::anyOrAssumedRank}}, SubscriptInt,
Rank::scalar},
{"log", {{"x", SameFloating}}, SameFloating},
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index a2b327f45c6939..ef9ac1cbb151b2 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -434,6 +434,7 @@ static constexpr IntrinsicHandler handlers[]{
{"lgt", &I::genCharacterCompare<mlir::arith::CmpIPredicate::sgt>},
{"lle", &I::genCharacterCompare<mlir::arith::CmpIPredicate::sle>},
{"llt", &I::genCharacterCompare<mlir::arith::CmpIPredicate::slt>},
+ {"lnblnk", &I::genLenTrim},
{"loc", &I::genLoc, {{{"x", asBox}}}, /*isElemental=*/false},
{"malloc", &I::genMalloc},
{"maskl", &I::genMask<mlir::arith::ShLIOp>},
diff --git a/flang/test/Lower/Intrinsics/len_trim.f90 b/flang/test/Lower/Intrinsics/len_trim.f90
index 8777e5857609f2..e3483331ab5ab3 100644
--- a/flang/test/Lower/Intrinsics/len_trim.f90
+++ b/flang/test/Lower/Intrinsics/len_trim.f90
@@ -18,3 +18,22 @@ integer function len_trim_test(c)
! CHECK: %[[len:.*]] = arith.addi %[[iterateResult]]#1, %[[c1]]
! CHECK: select %[[iterateResult]]#0, %[[c0]], %[[len]]
end function
+
+! CHECK-LABEL: lnblnk_test
+integer function lnblnk_test(c)
+character(*) :: c
+ltrim = lnblnk(c)
+! CHECK-DAG: %[[c0:.*]] = arith.constant 0 : index
+! CHECK-DAG: %[[c1:.*]] = arith.constant 1 : index
+! CHECK-DAG: %[[cm1:.*]] = arith.constant -1 : index
+! CHECK-DAG: %[[lastChar:.*]] = arith.subi {{.*}}, %[[c1]]
+! CHECK: %[[iterateResult:.*]]:2 = fir.iterate_while (%[[index:.*]] = %[[lastChar]] to %[[c0]] step %[[cm1]]) and ({{.*}}) iter_args({{.*}}) {
+ ! CHECK: %[[addr:.*]] = fir.coordinate_of {{.*}}, %[[index]]
+ ! CHECK: %[[codeAddr:.*]] = fir.convert %[[addr]]
+ ! CHECK: %[[code:.*]] = fir.load %[[codeAddr]]
+ ! CHECK: %[[bool:.*]] = arith.cmpi eq
+ ! CHECK: fir.result %[[bool]], %[[index]]
+! CHECK: }
+! CHECK: %[[len:.*]] = arith.addi %[[iterateResult]]#1, %[[c1]]
+! CHECK: select %[[iterateResult]]#0, %[[c0]], %[[len]]
+end function
``````````
</details>
https://github.com/llvm/llvm-project/pull/117589
More information about the flang-commits
mailing list