[flang-commits] [flang] 9319665 - [flang] Add support for LSHIFT and RSHIFT intrinsics
Kelvin Li via flang-commits
flang-commits at lists.llvm.org
Tue Nov 29 11:03:50 PST 2022
Author: Kelvin Li
Date: 2022-11-29T14:03:31-05:00
New Revision: 93196654f526026f9f751784454cb72f829e39cb
URL: https://github.com/llvm/llvm-project/commit/93196654f526026f9f751784454cb72f829e39cb
DIFF: https://github.com/llvm/llvm-project/commit/93196654f526026f9f751784454cb72f829e39cb.diff
LOG: [flang] Add support for LSHIFT and RSHIFT intrinsics
The functionality of LSHIFT and RSHIFT intrinsics is the same as the
standard SHIFTL and SHIFTA intrinsics respectively. The patch is to
alias the two intrinsics to the standardized ones.
Differential Revision: https://reviews.llvm.org/D138839
Added:
flang/test/Semantics/lshift.f90
flang/test/Semantics/rshift.f90
Modified:
flang/docs/Intrinsics.md
flang/lib/Evaluate/intrinsics.cpp
Removed:
################################################################################
diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index 0ecee23c5691..3bea740ec8fd 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -749,7 +749,7 @@ This phase currently supports all the intrinsic procedures listed above but the
| Coarray intrinsic functions | IMAGE_INDEX, COSHAPE |
| Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
| Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
-| Non-standard intrinsic functions | AND, OR, XOR, LSHIFT, RSHIFT, SHIFT, ZEXT, IZEXT, COSD, SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, DCMPLX, EQV, NEQV, INT8, JINT, JNINT, KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, INT_PTR_KIND, ISNAN, MALLOC |
+| Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, DCMPLX, EQV, NEQV, INT8, JINT, JNINT, KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, INT_PTR_KIND, ISNAN, MALLOC |
| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, SYSTEM_CLOCK |
| Atomic intrinsic subroutines | ATOMIC_ADD |
| Collective intrinsic subroutines | CO_REDUCE |
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 39af09478f39..4fbb11e31b71 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -917,7 +917,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
// TODO: Coarray intrinsic functions
// IMAGE_INDEX, COSHAPE
// TODO: Non-standard intrinsic functions
-// LSHIFT, RSHIFT, SHIFT,
+// SHIFT,
// COMPL, EQV, NEQV, INT8, JINT, JNINT, KNINT,
// QCMPLX, QEXT, QFLOAT, QREAL, DNUM,
// INUM, JNUM, KNUM, QNUM, RNUM, RAN, RANF, ILEN,
@@ -934,7 +934,9 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
static const std::pair<const char *, const char *> genericAlias[]{
{"and", "iand"},
{"imag", "aimag"},
+ {"lshift", "shiftl"},
{"or", "ior"},
+ {"rshift", "shifta"},
{"xor", "ieor"},
{"__builtin_ieee_selected_real_kind", "selected_real_kind"},
};
diff --git a/flang/test/Semantics/lshift.f90 b/flang/test/Semantics/lshift.f90
new file mode 100644
index 000000000000..3b4d53a6fcd6
--- /dev/null
+++ b/flang/test/Semantics/lshift.f90
@@ -0,0 +1,50 @@
+! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
+! Check that a call to LSHIFT is transformed to SHIFTL.
+
+subroutine test_default_integer()
+ integer :: i, j, k
+ k = lshift(i, j)
+!CHECK: k=shiftl(i,j)
+ k = lshift(16, 2)
+!CHECK: k=64_4
+end
+
+subroutine test_integer1()
+ integer(1) :: i, j, k
+ k = lshift(i, j)
+!CHECK: k=shiftl(i,int(j,kind=4))
+ print *, lshift(8_1, 2)
+!CHECK: PRINT *, 32_1
+end
+
+subroutine test_integer2()
+ integer(2) :: i, j, k
+ k = lshift(i, j)
+!CHECK: k=shiftl(i,int(j,kind=4))
+ print *, lshift(8_2, 2)
+!CHECK: PRINT *, 32_2
+end
+
+subroutine test_integer4()
+ integer(4) :: i, j, k
+ k = lshift(i, j)
+!CHECK: k=shiftl(i,j)
+ print *, lshift(8_4, 2)
+!CHECK: PRINT *, 32_4
+end
+
+subroutine test_integer8()
+ integer(8) :: i, j, k
+ k = lshift(i, j)
+!CHECK: k=shiftl(i,int(j,kind=4))
+ print *, lshift(-16_8, 2)
+!CHECK: PRINT *, -64_8
+end
+
+subroutine test_integer16()
+ integer(16) :: i, j, k
+ k = lshift(i, j)
+!CHECK: k=shiftl(i,int(j,kind=4))
+ print *, lshift(8_16, 2)
+!CHECK: PRINT *, 32_16
+end
diff --git a/flang/test/Semantics/rshift.f90 b/flang/test/Semantics/rshift.f90
new file mode 100644
index 000000000000..eb653fd33ccf
--- /dev/null
+++ b/flang/test/Semantics/rshift.f90
@@ -0,0 +1,50 @@
+! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
+! Check that a call to RSHIFT is transformed to SHIFTA.
+
+subroutine test_default_integer()
+ integer :: i, j, k
+ k = rshift(i, j)
+!CHECK: k=shifta(i,j)
+ k = rshift(16, 2)
+!CHECK: k=4_4
+end
+
+subroutine test_integer1()
+ integer(1) :: i, j, k
+ k = rshift(i, j)
+!CHECK: k=shifta(i,int(j,kind=4))
+ print *, rshift(8_1, 2)
+!CHECK: PRINT *, 2_1
+end
+
+subroutine test_integer2()
+ integer(2) :: i, j, k
+ k = rshift(i, j)
+!CHECK: k=shifta(i,int(j,kind=4))
+ print *, rshift(8_2, 2)
+!CHECK: PRINT *, 2_2
+end
+
+subroutine test_integer4()
+ integer(4) :: i, j, k
+ k = rshift(i, j)
+!CHECK: k=shifta(i,j)
+ print *, rshift(8_4, 2)
+!CHECK: PRINT *, 2_4
+end
+
+subroutine test_integer8()
+ integer(8) :: i, j, k
+ k = rshift(i, j)
+!CHECK: k=shifta(i,int(j,kind=4))
+ print *, rshift(-16_8, 2)
+!CHECK: PRINT *, -4_8
+end
+
+subroutine test_integer16()
+ integer(16) :: i, j, k
+ k = rshift(i, j)
+!CHECK: k=shifta(i,int(j,kind=4))
+ print *, rshift(8_16, 2)
+!CHECK: PRINT *, 2_16
+end
More information about the flang-commits
mailing list