[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.
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 77e038d..a404374 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -4230,9 +4230,13 @@
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(