[flang-commits] [flang] 942bc18 - [flang] Rebox the polymorphic argument in merge intrinsic
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Wed Mar 15 08:32:37 PDT 2023
Author: Valentin Clement
Date: 2023-03-15T16:32:29+01:00
New Revision: 942bc18d203a96234bc92a0ce41e8f38970a6462
URL: https://github.com/llvm/llvm-project/commit/942bc18d203a96234bc92a0ce41e8f38970a6462
DIFF: https://github.com/llvm/llvm-project/commit/942bc18d203a96234bc92a0ce41e8f38970a6462.diff
LOG: [flang] Rebox the polymorphic argument in merge intrinsic
When fsource or tsource is not polymorphic, the result is not
polymorphic. Rebox the polymoprhic arguement so the dynamic
type of the result is correct.
Reviewed By: PeteSteinfeld
Differential Revision: https://reviews.llvm.org/D146133
Added:
Modified:
flang/lib/Optimizer/Builder/IntrinsicCall.cpp
flang/test/Lower/polymorphic-temp.f90
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 9f8b009c12e8e..bfc36b8a8f90f 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -4035,10 +4035,18 @@ IntrinsicLibrary::genMerge(mlir::Type,
mlir::Value fsourceCast = fsource;
if (fir::isPolymorphicType(tsource.getType()) &&
!fir::isPolymorphicType(fsource.getType())) {
- tsourceCast = builder.createConvert(loc, fsource.getType(), tsource);
+ tsourceCast = builder.create<fir::ReboxOp>(loc, fsource.getType(), tsource,
+ /*shape*/ mlir::Value{},
+ /*slice=*/mlir::Value{});
+
+ // builder.createConvert(loc, fsource.getType(), tsource);
} else if (!fir::isPolymorphicType(tsource.getType()) &&
fir::isPolymorphicType(fsource.getType())) {
- fsourceCast = builder.createConvert(loc, tsource.getType(), fsource);
+ fsourceCast = builder.create<fir::ReboxOp>(loc, tsource.getType(), fsource,
+ /*shape*/ mlir::Value{},
+ /*slice=*/mlir::Value{});
+
+ // fsourceCast = builder.createConvert(loc, tsource.getType(), fsource);
} else {
// FSOURCE and TSOURCE are not polymorphic.
// FSOURCE has the same type as TSOURCE, but they may not have the same MLIR
diff --git a/flang/test/Lower/polymorphic-temp.f90 b/flang/test/Lower/polymorphic-temp.f90
index 16b629a5d6d29..7858064108b58 100644
--- a/flang/test/Lower/polymorphic-temp.f90
+++ b/flang/test/Lower/polymorphic-temp.f90
@@ -222,7 +222,7 @@ subroutine test_merge_intrinsic2(a, b, i)
! CHECK: %[[LOAD_I:.*]] = fir.load %[[I]] : !fir.ref<i32>
! CHECK: %[[C1:.*]] = arith.constant 1 : i32
! CHECK: %[[CMPI:.*]] = arith.cmpi eq, %[[LOAD_I]], %[[C1]] : i32
-! CHECK: %[[A_CONV:.*]] = fir.convert %[[LOAD_A]] : (!fir.class<!fir.heap<!fir.type<_QMpoly_tmpTp1{a:i32}>>>) -> !fir.box<!fir.heap<!fir.type<_QMpoly_tmpTp1{a:i32}>>>
-! CHECK: %{{.*}} = arith.select %[[CMPI]], %[[A_CONV]], %[[LOAD_B]] : !fir.box<!fir.heap<!fir.type<_QMpoly_tmpTp1{a:i32}>>>
+! CHECK: %[[A_REBOX:.*]] = fir.rebox %[[LOAD_A]] : (!fir.class<!fir.heap<!fir.type<_QMpoly_tmpTp1{a:i32}>>>) -> !fir.box<!fir.heap<!fir.type<_QMpoly_tmpTp1{a:i32}>>>
+! CHECK: %{{.*}} = arith.select %[[CMPI]], %[[A_REBOX]], %[[LOAD_B]] : !fir.box<!fir.heap<!fir.type<_QMpoly_tmpTp1{a:i32}>>>
end module
More information about the flang-commits
mailing list