[flang-commits] [PATCH] D130379: [flang] Fold calls to ISHFTC()

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jul 22 12:06:48 PDT 2022


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a reviewer: sscalpone.
Herald added a project: All.
klausler requested review of this revision.

The integer arithmetic template supports ISHFTC() but the
integer intrinsic folding code had yet to call it; finish
the job.


https://reviews.llvm.org/D130379

Files:
  flang/lib/Evaluate/fold-integer.cpp
  flang/test/Evaluate/fold-ishftc.f90


Index: flang/test/Evaluate/fold-ishftc.f90
===================================================================
--- /dev/null
+++ 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
+
Index: flang/lib/Evaluate/fold-integer.cpp
===================================================================
--- flang/lib/Evaluate/fold-integer.cpp
+++ flang/lib/Evaluate/fold-integer.cpp
@@ -742,6 +742,26 @@
           }
           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 @@
   } 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)};
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130379.446926.patch
Type: text/x-patch
Size: 2564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220722/eb315fb7/attachment-0001.bin>


More information about the flang-commits mailing list