[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 18:22:11 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGbaec06a9d499: [flang] Fold calls to ISHFTC() (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130379/new/

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.447020.patch
Type: text/x-patch
Size: 2564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220723/8e9587dc/attachment-0001.bin>


More information about the flang-commits mailing list