[Openmp-commits] [PATCH] D107579: [Attributor]Fix PR51249: Stores from memory intrinsics incorrectly being replaced by undef

Joseph Huber via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Aug 5 10:25:32 PDT 2021


jhuber6 updated this revision to Diff 364538.
jhuber6 added a comment.
Herald added a project: OpenMP.
Herald added a subscriber: openmp-commits.

Adding test for bug.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107579

Files:
  llvm/lib/Transforms/IPO/AttributorAttributes.cpp
  openmp/libomptarget/test/offloading/bug51249.cpp


Index: openmp/libomptarget/test/offloading/bug51249.cpp
===================================================================
--- /dev/null
+++ openmp/libomptarget/test/offloading/bug51249.cpp
@@ -0,0 +1,28 @@
+// RUN: %libomptarget-compilexx-generic -O3 && %libomptarget-run-generic
+
+#include <complex>
+#include <cstdio>
+
+constexpr int N = 1024;
+
+std::complex<double> reduce(std::complex<double> *X, int N) {
+  std::complex<double> Sum = {0, 0};
+#pragma omp target teams distribute parallel for map(to: X[0:N]) reduction(+ : Sum)
+  for (int i = 0; i < N; ++i)
+    Sum += X[i];
+
+  return Sum;
+}
+
+int main() {
+  std::complex<double> X[N];
+
+  for (int i = 0; i < N; ++i)
+    X[i] = {1, -1};
+
+  std::complex<double> Sum = reduce(X, N);
+
+  // CHECK: PASS
+  if (std::real(Sum) + std::imag(Sum) == 0.0)
+    printf("PASS\n");
+}
Index: llvm/lib/Transforms/IPO/AttributorAttributes.cpp
===================================================================
--- llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -1344,8 +1344,8 @@
         handleAccess(A, *MI, Ptr, nullptr, AccessKind::AK_WRITE, 0, Changed,
                      nullptr, LengthVal);
       } else if (ArgNo == 1) {
-        handleAccess(A, *MI, Ptr, nullptr, AccessKind::AK_READ, 0, Changed,
-                     nullptr, LengthVal);
+        handleAccess(A, *MI, Ptr, nullptr, AccessKind::AK_READ_WRITE, 0,
+                     Changed, nullptr, LengthVal);
       } else {
         LLVM_DEBUG(dbgs() << "[AAPointerInfo] Unhandled memory intrinsic "
                           << *MI << "\n");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107579.364538.patch
Type: text/x-patch
Size: 1633 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210805/4e3cbae6/attachment.bin>


More information about the Openmp-commits mailing list