[PATCH] D84936: [flang] Fix CMPLX folding with complex arguments
Jean Perier via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 31 01:27:25 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa50cec71ecea: [flang] Fix CMPLX folding with complex arguments (authored by jeanPerier).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D84936/new/
https://reviews.llvm.org/D84936
Files:
flang/lib/Evaluate/fold-complex.cpp
flang/test/Evaluate/folding01.f90
Index: flang/test/Evaluate/folding01.f90
===================================================================
--- flang/test/Evaluate/folding01.f90
+++ flang/test/Evaluate/folding01.f90
@@ -63,6 +63,14 @@
logical, parameter :: test_ne_i1 =.NOT.(2.NE.2)
logical, parameter :: test_ne_i2 = -2.NE.2
+! Check conversions
+ logical, parameter :: test_cmplx1 = cmplx((1._4, -1._4)).EQ.((1._4, -1._4))
+ logical, parameter :: test_cmplx2 = cmplx((1._4, -1._4), 8).EQ.((1._8, -1._8))
+ logical, parameter :: test_cmplx3 = cmplx(1._4, -1._4).EQ.((1._4, -1._4))
+ logical, parameter :: test_cmplx4 = cmplx(1._4, -1._4, 8).EQ.((1._8, -1._8))
+ logical, parameter :: test_cmplx5 = cmplx(1._4).EQ.((1._4, 0._4))
+ logical, parameter :: test_cmplx6 = cmplx(1._4, kind=8).EQ.((1._8, 0._8))
+
! Check integer intrinsic operation folding
logical, parameter :: test_unaryminus_i = (-(-1)).EQ.1
logical, parameter :: test_unaryplus_i = (+1).EQ.1
Index: flang/lib/Evaluate/fold-complex.cpp
===================================================================
--- flang/lib/Evaluate/fold-complex.cpp
+++ flang/lib/Evaluate/fold-complex.cpp
@@ -36,7 +36,7 @@
context, std::move(funcRef), &Scalar<T>::CONJG);
} else if (name == "cmplx") {
using Part = typename T::Part;
- if (args.size() == 1) {
+ if (args.size() == 2) { // CMPLX(X, [KIND])
if (auto *x{UnwrapExpr<Expr<SomeComplex>>(args[0])}) {
return Fold(context, ConvertToType<T>(std::move(*x)));
}
@@ -46,7 +46,8 @@
Expr<T>{ComplexConstructor<KIND>{ToReal<KIND>(context, std::move(re)),
ToReal<KIND>(context, std::move(im))}});
}
- CHECK(args.size() == 2 || args.size() == 3);
+ // CMPLX(X, [Y, KIND])
+ CHECK(args.size() == 3);
Expr<SomeType> re{std::move(*args[0].value().UnwrapExpr())};
Expr<SomeType> im{args[1] ? std::move(*args[1].value().UnwrapExpr())
: AsGenericExpr(Constant<Part>{Scalar<Part>{}})};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84936.282152.patch
Type: text/x-patch
Size: 1988 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200731/c009e4fd/attachment.bin>
More information about the llvm-commits
mailing list