[flang-commits] [flang] 3ad7108 - [flang][cuda] Avoid temporary when RHS is a logical constant (#99078)
via flang-commits
flang-commits at lists.llvm.org
Wed Jul 17 08:39:22 PDT 2024
Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-07-17T08:39:18-07:00
New Revision: 3ad7108c3cf843cac6301db3f73ccea9661bc4d3
URL: https://github.com/llvm/llvm-project/commit/3ad7108c3cf843cac6301db3f73ccea9661bc4d3
DIFF: https://github.com/llvm/llvm-project/commit/3ad7108c3cf843cac6301db3f73ccea9661bc4d3.diff
LOG: [flang][cuda] Avoid temporary when RHS is a logical constant (#99078)
Enhance the detection of constant on the RHS for logical cases so we
don't create a temporary.
Added:
Modified:
flang/lib/Lower/Bridge.cpp
flang/test/Lower/CUDA/cuda-data-transfer.cuf
Removed:
################################################################################
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 77e038dac13ff..a4043744c6386 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -4230,9 +4230,13 @@ class FirConverter : public Fortran::lower::AbstractConverter {
auto transferKindAttr = cuf::DataTransferKindAttr::get(
builder.getContext(), cuf::DataTransferKind::HostDevice);
if (!rhs.isVariable()) {
+ mlir::Value base = rhs;
+ if (auto convertOp =
+ mlir::dyn_cast<fir::ConvertOp>(rhs.getDefiningOp()))
+ base = convertOp.getValue();
// Special case if the rhs is a constant.
- if (matchPattern(rhs.getDefiningOp(), mlir::m_Constant())) {
- builder.create<cuf::DataTransferOp>(loc, rhs, lhsVal,
+ if (matchPattern(base.getDefiningOp(), mlir::m_Constant())) {
+ builder.create<cuf::DataTransferOp>(loc, base, lhsVal,
transferKindAttr);
} else {
auto associate = hlfir::genAssociateExpr(
diff --git a/flang/test/Lower/CUDA/cuda-data-transfer.cuf b/flang/test/Lower/CUDA/cuda-data-transfer.cuf
index 1383b73ea44d6..d657f819dfbf1 100644
--- a/flang/test/Lower/CUDA/cuda-data-transfer.cuf
+++ b/flang/test/Lower/CUDA/cuda-data-transfer.cuf
@@ -265,3 +265,12 @@ end subroutine
! CHECK: %[[TEMP:.*]] = fir.allocmem !fir.array<?xi32>, %14#1 {bindc_name = ".tmp", uniq_name = ""}
! CHECK: cuf.data_transfer
! CHECK: fir.freemem %[[TEMP]] : !fir.heap<!fir.array<?xi32>>
+
+subroutine sub14()
+ logical(4), device :: log(10)
+ log = .true.
+end subroutine
+
+! CHECK-LABEL: func.func @_QPsub14()
+! CHECK: %[[TRUE:.*]] = arith.constant true
+! CHECK: cuf.data_transfer %[[TRUE]] to %{{.*}}#0 {transfer_kind = #cuf.cuda_transfer<host_device>} : i1, !fir.ref<!fir.array<10x!fir.logical<4>>>
More information about the flang-commits
mailing list