[clang] 08513cb - [OpenMP] Fix lvalue reference type generation in untied task loop
Alexey Bataev via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 29 09:16:10 PDT 2023
Author: Zhiheng Xie
Date: 2023-06-29T09:11:10-07:00
New Revision: 08513cbea4dc1fe10ee864b8fd8c1eccd7917490
URL: https://github.com/llvm/llvm-project/commit/08513cbea4dc1fe10ee864b8fd8c1eccd7917490
DIFF: https://github.com/llvm/llvm-project/commit/08513cbea4dc1fe10ee864b8fd8c1eccd7917490.diff
LOG: [OpenMP] Fix lvalue reference type generation in untied task loop
For variables with lvalue reference type in untied task loop,
it now wrongly sets its actual type as ElementType. It should
be converted to pointer type.
It fixes https://github.com/llvm/llvm-project/issues/62965
Reviewed By: ABataev
Differential Revision: https://reviews.llvm.org/D153321
Added:
clang/test/OpenMP/taskloop_untied_codegen.cpp
Modified:
clang/lib/CodeGen/CGStmtOpenMP.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index a9e9b986bc60a9..313bdaab44f0f0 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -4852,6 +4852,8 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
// a pointer to this memory.
for (auto &Pair : UntiedLocalVars) {
QualType VDType = Pair.first->getType().getNonReferenceType();
+ if (Pair.first->getType()->isLValueReferenceType())
+ VDType = CGF.getContext().getPointerType(VDType);
if (isAllocatableDecl(Pair.first)) {
llvm::Value *Ptr = CGF.Builder.CreateLoad(Pair.second.first);
Address Replacement(
diff --git a/clang/test/OpenMP/taskloop_untied_codegen.cpp b/clang/test/OpenMP/taskloop_untied_codegen.cpp
new file mode 100644
index 00000000000000..fdb1d017039b61
--- /dev/null
+++ b/clang/test/OpenMP/taskloop_untied_codegen.cpp
@@ -0,0 +1,26 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
+// RUN: %clang_cc1 -verify -triple aarch64-unknown-linux-gnu -fopenmp -x c++ -std=c++11 -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK-LABEL: define dso_local void @_Z15taskloop_untiedv
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: [[WORK:%.*]] = alloca [100 x float], align 4
+// CHECK-NEXT: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]], align 1
+// CHECK-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1:[0-9]+]])
+// CHECK-NEXT: [[TMP1:%.*]] = call ptr @__kmpc_omp_task_alloc(ptr @[[GLOB1]], i32 [[TMP0]], i32 0, i64 472, i64 1, ptr @.omp_task_entry.)
+// CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T_WITH_PRIVATES:%.*]], ptr [[TMP1]], i32 0, i32 0
+// CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T_WITH_PRIVATES]], ptr [[TMP1]], i32 0, i32 1
+// CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds [[STRUCT__KMP_PRIVATES_T:%.*]], ptr [[TMP3]], i32 0, i32 3
+// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[TMP4]], ptr align 4 [[WORK]], i64 400, i1 false)
+// CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T:%.*]], ptr [[TMP2]], i32 0, i32 2
+// CHECK-NEXT: store i32 0, ptr [[TMP5]], align 8
+// CHECK-NEXT: [[TMP6:%.*]] = call i32 @__kmpc_omp_task(ptr @[[GLOB1]], i32 [[TMP0]], ptr [[TMP1]])
+// CHECK-NEXT: ret void
+//
+void taskloop_untied() {
+ float work[100];
+#pragma omp task untied
+ for (auto cb : work)
+ cb = 1.0;
+}
More information about the cfe-commits
mailing list