[flang-commits] [PATCH] D156754: [flang] Fix crash in folding of DPROD() with non-scalar arguments
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Tue Aug 1 09:39:13 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4f1eec1fc643: [flang] Fix crash in folding of DPROD() with non-scalar arguments (authored by klausler).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156754/new/
https://reviews.llvm.org/D156754
Files:
flang/lib/Evaluate/fold-real.cpp
flang/test/Evaluate/fold-dprod.f90
Index: flang/test/Evaluate/fold-dprod.f90
===================================================================
--- /dev/null
+++ flang/test/Evaluate/fold-dprod.f90
@@ -0,0 +1,8 @@
+! RUN: %python %S/test_folding.py %s %flang_fc1
+! Tests folding of DPROD()
+module m
+ logical, parameter :: test_kind = kind(dprod(2., 3.)) == kind(0.d0)
+ logical, parameter :: test_ss = dprod(2., 3.) == 6.d0
+ logical, parameter :: test_sv = all(dprod(2., [3.,4.]) == [6.d0,8.d0])
+ logical, parameter :: test_vv = all(dprod([2.,3.], [4.,5.]) == [8.d0,15.0d0])
+end
Index: flang/lib/Evaluate/fold-real.cpp
===================================================================
--- flang/lib/Evaluate/fold-real.cpp
+++ flang/lib/Evaluate/fold-real.cpp
@@ -149,10 +149,15 @@
} else if (name == "dot_product") {
return FoldDotProduct<T>(context, std::move(funcRef));
} else if (name == "dprod") {
- if (auto scalars{GetScalarConstantArguments<T, T>(context, args)}) {
- return Fold(context,
- Expr<T>{Multiply<T>{
- Expr<T>{std::get<0>(*scalars)}, Expr<T>{std::get<1>(*scalars)}}});
+ // Rewrite DPROD(x,y) -> DBLE(x)*DBLE(y)
+ if (args.at(0) && args.at(1)) {
+ const auto *xExpr{args[0]->UnwrapExpr()};
+ const auto *yExpr{args[1]->UnwrapExpr()};
+ if (xExpr && yExpr) {
+ return Fold(context,
+ ToReal<T::kind>(context, common::Clone(*xExpr)) *
+ ToReal<T::kind>(context, common::Clone(*yExpr)));
+ }
}
} else if (name == "epsilon") {
return Expr<T>{Scalar<T>::EPSILON()};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156754.546097.patch
Type: text/x-patch
Size: 1570 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230801/ca313747/attachment-0001.bin>
More information about the flang-commits
mailing list