[PATCH] D106294: [flang] Implement the runtime portion of the UNPACK intrinsic

Pete Steinfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 19 11:43:02 PDT 2021


PeteSteinfeld created this revision.
PeteSteinfeld requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

I'd previously merged this into the fir-dev branch.  This change is to
do the same thing to the main branch of llvm-project.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106294

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


Index: flang/unittests/RuntimeGTest/Transformational.cpp
===================================================================
--- flang/unittests/RuntimeGTest/Transformational.cpp
+++ flang/unittests/RuntimeGTest/Transformational.cpp
@@ -212,4 +212,20 @@
     EXPECT_EQ(*result.ZeroBasedIndexedElement<std::int32_t>(j), expect[j]);
   }
   result.Destroy();
+
+  // Test for scalar value of the "field" argument
+  auto scalarField{MakeArray<TypeCategory::Integer, 4>(
+      std::vector<int>{}, std::vector<std::int32_t>{343})};
+  RTNAME(Unpack)(result, *vector, *mask, *scalarField, __FILE__, __LINE__);
+  EXPECT_EQ(result.rank(), 2);
+  EXPECT_EQ(result.GetDimension(0).LowerBound(), 1);
+  EXPECT_EQ(result.GetDimension(0).Extent(), 2);
+  EXPECT_EQ(result.GetDimension(1).LowerBound(), 1);
+  EXPECT_EQ(result.GetDimension(1).Extent(), 3);
+  static std::int32_t scalarExpect[6]{343, 1, 2, 343, 343, 3};
+  for (int j{0}; j < 6; ++j) {
+    EXPECT_EQ(
+        *result.ZeroBasedIndexedElement<std::int32_t>(j), scalarExpect[j]);
+  }
+  result.Destroy();
 }
Index: flang/runtime/transformational.cpp
===================================================================
--- flang/runtime/transformational.cpp
+++ flang/runtime/transformational.cpp
@@ -521,7 +521,9 @@
     }
     result.IncrementSubscripts(resultAt);
     mask.IncrementSubscripts(maskAt);
-    field.IncrementSubscripts(fieldAt);
+    if (field.rank() != 0) { // scalar "field" argument
+      field.IncrementSubscripts(fieldAt);
+    }
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106294.359859.patch
Type: text/x-patch
Size: 1519 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210719/20c85daf/attachment.bin>


More information about the llvm-commits mailing list