aboutsummaryrefslogtreecommitdiff
path: root/flang
diff options
context:
space:
mode:
authorPeter Klausler <pklausler@nvidia.com>2022-07-15 17:33:44 -0700
committerPeter Klausler <pklausler@nvidia.com>2022-07-22 18:21:57 -0700
commitbaec06a9d499c76635378f570166066b522d4a62 (patch)
tree6e1ed16fb6c7477d00c625f6422c604f7e8ec6b6 /flang
parent[flang] Fix a warning (diff)
downloadllvm-project-baec06a9d499c76635378f570166066b522d4a62.tar.gz
llvm-project-baec06a9d499c76635378f570166066b522d4a62.tar.bz2
llvm-project-baec06a9d499c76635378f570166066b522d4a62.zip
[flang] Fold calls to ISHFTC()
The integer arithmetic template supports ISHFTC() but the integer intrinsic folding code had yet to call it; finish the job. Differential Revision: https://reviews.llvm.org/D130379
Diffstat (limited to 'flang')
-rw-r--r--flang/lib/Evaluate/fold-integer.cpp22
-rw-r--r--flang/test/Evaluate/fold-ishftc.f9014
2 files changed, 35 insertions, 1 deletions
diff --git a/flang/lib/Evaluate/fold-integer.cpp b/flang/lib/Evaluate/fold-integer.cpp
index eb8f0461ecb6..438424a81762 100644
--- a/flang/lib/Evaluate/fold-integer.cpp
+++ b/flang/lib/Evaluate/fold-integer.cpp
@@ -742,6 +742,26 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
}
return i.ISHFT(posVal);
}));
+ } else if (name == "ishftc") {
+ if (args.at(2)) { // SIZE= is present
+ return FoldElementalIntrinsic<T, T, Int4, Int4>(context,
+ std::move(funcRef),
+ ScalarFunc<T, T, Int4, Int4>(
+ [&](const Scalar<T> &i, const Scalar<Int4> &shift,
+ const Scalar<Int4> &size) -> Scalar<T> {
+ // Errors are caught in intrinsics.cpp
+ auto shiftVal{static_cast<int>(shift.ToInt64())};
+ auto sizeVal{static_cast<int>(size.ToInt64())};
+ return i.ISHFTC(shiftVal, sizeVal);
+ }));
+ } else { // no SIZE=
+ return FoldElementalIntrinsic<T, T, Int4>(context, std::move(funcRef),
+ ScalarFunc<T, T, Int4>(
+ [&](const Scalar<T> &i, const Scalar<Int4> &count) -> Scalar<T> {
+ auto countVal{static_cast<int>(count.ToInt64())};
+ return i.ISHFTC(countVal);
+ }));
+ }
} else if (name == "lbound") {
return LBOUND(context, std::move(funcRef));
} else if (name == "leadz" || name == "trailz" || name == "poppar" ||
@@ -1053,7 +1073,7 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
} else if (name == "ubound") {
return UBOUND(context, std::move(funcRef));
}
- // TODO: dot_product, ishftc, matmul, sign
+ // TODO: dot_product, matmul, sign
return Expr<T>{std::move(funcRef)};
}
diff --git a/flang/test/Evaluate/fold-ishftc.f90 b/flang/test/Evaluate/fold-ishftc.f90
new file mode 100644
index 000000000000..35c6bf3283b7
--- /dev/null
+++ b/flang/test/Evaluate/fold-ishftc.f90
@@ -0,0 +1,14 @@
+! RUN: %python %S/test_folding.py %s %flang_fc1
+! Tests folding of ISHFTC
+module m
+ integer, parameter :: shift8s(*) = ishftc(257, shift = [(ict, ict = -9, 9)], 8)
+ integer, parameter :: expect1(*) = 256 + [128, 1, 2, 4, 8, 16, 32, 64, 128, &
+ 1, 2, 4, 8, 16, 32, 64, 128, 1, 2]
+ logical, parameter :: test_1 = all(shift8s == expect1)
+ integer, parameter :: sizes(*) = [(ishftc(257, ict, [(isz, isz = 1, 8)]), ict = -1, 1)]
+ integer, parameter :: expect2(*) = 256 + [[1, 2, 4, 8, 16, 32, 64, 128], &
+ [(1, j = 1, 8)], &
+ [1, (2, j = 2, 8)]]
+ logical, parameter :: test_2 = all(sizes == expect2)
+end module
+