[PATCH] D113659: [flang] Fix vector cshift runtime with non zero lower bounds

Jean Perier via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 12 00:44:53 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG6544d9a4a098: [flang] Fix vector cshift runtime with non zero lower bounds (authored by jeanPerier).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113659

Files:
  flang/runtime/transformational.cpp
  flang/unittests/Runtime/Transformational.cpp


Index: flang/unittests/Runtime/Transformational.cpp
===================================================================
--- flang/unittests/Runtime/Transformational.cpp
+++ flang/unittests/Runtime/Transformational.cpp
@@ -93,6 +93,26 @@
   }
   vectorResult.Destroy();
 
+  // VECTOR  1 3 5 2 4 6 WITH non zero lower bound in a negative cshift.
+  auto vectorWithLowerBounds{MakeArray<TypeCategory::Integer, 4>(
+      std::vector<int>{6}, std::vector<std::int32_t>{1, 2, 3, 4, 5, 6})};
+  vector->GetDimension(0).SetLowerBound(2);
+  StaticDescriptor<1, true> vectorDesc2;
+
+  RTNAME(CshiftVector)
+  (vectorResult, *vectorWithLowerBounds, -2, __FILE__, __LINE__);
+  EXPECT_EQ(vectorResult.type(), array->type());
+  EXPECT_EQ(vectorResult.rank(), 1);
+  EXPECT_EQ(vectorResult.GetDimension(0).LowerBound(), 1);
+  EXPECT_EQ(vectorResult.GetDimension(0).Extent(), 6);
+  EXPECT_EQ(vectorResult.type(), (TypeCode{TypeCategory::Integer, 4}));
+  static std::int32_t cshiftExpect5[6]{5, 6, 1, 2, 3, 4};
+  for (int j{0}; j < 6; ++j) {
+    EXPECT_EQ(*vectorResult.ZeroBasedIndexedElement<std::int32_t>(j),
+        cshiftExpect5[j]);
+  }
+  vectorResult.Destroy();
+
   auto boundary{MakeArray<TypeCategory::Integer, 4>(
       std::vector<int>{3}, std::vector<std::int32_t>{-1, -2, -3})};
   boundary->GetDimension(0).SetLowerBound(9); // shouldn't matter
@@ -130,6 +150,22 @@
         eoshiftVectorExpect[j]);
   }
   vectorResult.Destroy();
+
+  // VECTOR EOSHIFT on input with non zero lower bounds
+  RTNAME(EoshiftVector)
+  (vectorResult, *vectorWithLowerBounds, -2, &vectorBoundary, __FILE__,
+      __LINE__);
+  EXPECT_EQ(vectorResult.type(), array->type());
+  EXPECT_EQ(vectorResult.rank(), 1);
+  EXPECT_EQ(vectorResult.GetDimension(0).LowerBound(), 1);
+  EXPECT_EQ(vectorResult.GetDimension(0).Extent(), 6);
+  EXPECT_EQ(vectorResult.type(), (TypeCode{TypeCategory::Integer, 4}));
+  static std::int32_t eoshiftVectorExpect2[6]{343, 343, 1, 2, 3, 4};
+  for (int j{0}; j < 6; ++j) {
+    EXPECT_EQ(*vectorResult.ZeroBasedIndexedElement<std::int32_t>(j),
+        eoshiftVectorExpect2[j]);
+  }
+  vectorResult.Destroy();
 }
 
 TEST(Transformational, Pack) {
Index: flang/runtime/transformational.cpp
===================================================================
--- flang/runtime/transformational.cpp
+++ flang/runtime/transformational.cpp
@@ -184,7 +184,7 @@
   for (SubscriptValue j{0}; j < extent; ++j) {
     SubscriptValue resultAt{1 + j};
     SubscriptValue sourceAt{lb + (j + shift) % extent};
-    if (sourceAt < 0) {
+    if (sourceAt < lb) {
       sourceAt += extent;
     }
     CopyElement(result, &resultAt, source, &sourceAt, terminator);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113659.386752.patch
Type: text/x-patch
Size: 2677 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211112/0b558e9a/attachment.bin>


More information about the llvm-commits mailing list