Skip to content

Conversation

@clementval
Copy link
Contributor

No description provided.

@clementval clementval requested a review from wangzpgi January 9, 2026 20:53
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:semantics labels Jan 9, 2026
@llvmbot
Copy link
Member

llvmbot commented Jan 9, 2026

@llvm/pr-subscribers-flang-fir-hlfir

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/175243.diff

2 Files Affected:

  • (modified) flang/include/flang/Evaluate/tools.h (+1-2)
  • (modified) flang/test/Lower/CUDA/cuda-data-transfer.cuf (+16)
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index ea26a0ee9da7a..6a424f2cbb04e 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -1352,8 +1352,7 @@ inline bool IsCUDADataTransfer(const A &lhs, const B &rhs) {
   // Special cases performed on the host:
   // - Only managed or unifed symbols are involved on RHS and LHS.
   // - LHS is managed or unified and the RHS is host only.
-  if ((lhsNbManagedSymbols >= 1 && rhsNbManagedSymbols == 1 &&
-          rhsNbSymbols == 1) ||
+  if ((lhsNbManagedSymbols >= 1 && rhsNbManagedSymbols == rhsNbSymbols) ||
       (lhsNbManagedSymbols >= 1 && rhsNbSymbols == 0)) {
     return false;
   }
diff --git a/flang/test/Lower/CUDA/cuda-data-transfer.cuf b/flang/test/Lower/CUDA/cuda-data-transfer.cuf
index 058e2506c1d53..0c14f960bbb29 100644
--- a/flang/test/Lower/CUDA/cuda-data-transfer.cuf
+++ b/flang/test/Lower/CUDA/cuda-data-transfer.cuf
@@ -588,3 +588,19 @@ end subroutine
 ! CHECK: %{{.*}} = cuf.alloc !fir.type<_QMmod1Tt3{spheres:!fir.box<!fir.heap<!fir.array<?x!fir.type<_QMmod1Ts{c:!fir.array<3xf32>}>>>>}> {bindc_name = "t", data_attr = #cuf.cuda<managed>, uniq_name = "_QFsub30Et"} -> !fir.ref<!fir.type<_QMmod1Tt3{spheres:!fir.box<!fir.heap<!fir.array<?x!fir.type<_QMmod1Ts{c:!fir.array<3xf32>}>>>>}>>
 ! CHECK: hlfir.assign 
 ! CHECK-NOT: cuf.data_transfer
+
+! Test that assigment with onlt managed variables on both rhs and lhs is done
+! on the host.
+
+subroutine sub31()
+  type :: t30
+    real, managed, allocatable :: q(:)
+  end type
+  type(t30), managed, allocatable :: x(:)
+  x(4)%q = x(3)%q
+end subroutine
+
+! CHECK-LABEL: func.func @_QPsub31()
+! CHECK: cuf.alloc !fir.box<!fir.heap<!fir.array<?x!fir.type<_QFsub31Tt30{q:!fir.box<!fir.heap<!fir.array<?xf32>>>}>>>> 
+! CHECK: hlfir.assign 
+! CHECK-NOT: cuf.data_transfer

@llvmbot
Copy link
Member

llvmbot commented Jan 9, 2026

@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/175243.diff

2 Files Affected:

  • (modified) flang/include/flang/Evaluate/tools.h (+1-2)
  • (modified) flang/test/Lower/CUDA/cuda-data-transfer.cuf (+16)
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index ea26a0ee9da7a..6a424f2cbb04e 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -1352,8 +1352,7 @@ inline bool IsCUDADataTransfer(const A &lhs, const B &rhs) {
   // Special cases performed on the host:
   // - Only managed or unifed symbols are involved on RHS and LHS.
   // - LHS is managed or unified and the RHS is host only.
-  if ((lhsNbManagedSymbols >= 1 && rhsNbManagedSymbols == 1 &&
-          rhsNbSymbols == 1) ||
+  if ((lhsNbManagedSymbols >= 1 && rhsNbManagedSymbols == rhsNbSymbols) ||
       (lhsNbManagedSymbols >= 1 && rhsNbSymbols == 0)) {
     return false;
   }
diff --git a/flang/test/Lower/CUDA/cuda-data-transfer.cuf b/flang/test/Lower/CUDA/cuda-data-transfer.cuf
index 058e2506c1d53..0c14f960bbb29 100644
--- a/flang/test/Lower/CUDA/cuda-data-transfer.cuf
+++ b/flang/test/Lower/CUDA/cuda-data-transfer.cuf
@@ -588,3 +588,19 @@ end subroutine
 ! CHECK: %{{.*}} = cuf.alloc !fir.type<_QMmod1Tt3{spheres:!fir.box<!fir.heap<!fir.array<?x!fir.type<_QMmod1Ts{c:!fir.array<3xf32>}>>>>}> {bindc_name = "t", data_attr = #cuf.cuda<managed>, uniq_name = "_QFsub30Et"} -> !fir.ref<!fir.type<_QMmod1Tt3{spheres:!fir.box<!fir.heap<!fir.array<?x!fir.type<_QMmod1Ts{c:!fir.array<3xf32>}>>>>}>>
 ! CHECK: hlfir.assign 
 ! CHECK-NOT: cuf.data_transfer
+
+! Test that assigment with onlt managed variables on both rhs and lhs is done
+! on the host.
+
+subroutine sub31()
+  type :: t30
+    real, managed, allocatable :: q(:)
+  end type
+  type(t30), managed, allocatable :: x(:)
+  x(4)%q = x(3)%q
+end subroutine
+
+! CHECK-LABEL: func.func @_QPsub31()
+! CHECK: cuf.alloc !fir.box<!fir.heap<!fir.array<?x!fir.type<_QFsub31Tt30{q:!fir.box<!fir.heap<!fir.array<?xf32>>>}>>>> 
+! CHECK: hlfir.assign 
+! CHECK-NOT: cuf.data_transfer

@clementval clementval enabled auto-merge (squash) January 9, 2026 22:56
@clementval clementval merged commit 5e78d5e into llvm:main Jan 9, 2026
10 checks passed
@clementval clementval deleted the cuf_tx_managed_host branch January 10, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:fir-hlfir flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants