[flang-commits] [PATCH] D85864: [flang] Correct manipulation of mixed complex expressions

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Aug 12 16:36:33 PDT 2020


klausler created this revision.
klausler added reviewers: sscalpone, PeteSteinfeld.
klausler added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
klausler requested review of this revision.

Ensure that mixed complex expressions (one operand complex,
the other not) are properly manipulated; add test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85864

Files:
  flang/lib/Evaluate/tools.cpp
  flang/test/Evaluate/folding11.f90


Index: flang/test/Evaluate/folding11.f90
===================================================================
--- /dev/null
+++ flang/test/Evaluate/folding11.f90
@@ -0,0 +1,31 @@
+! RUN: %S/test_folding.sh %s %t %f18
+module m
+  complex, parameter :: z1 = 1. + (2., 3.)
+  logical, parameter :: test_z1 = z1 == (3., 3.)
+  complex, parameter :: z2 = 1 + (2., 3.)
+  logical, parameter :: test_z2 = z2 == (3., 3.)
+  complex, parameter :: z3 = 2. * (3., 4.)
+  logical, parameter :: test_z3 = z3 == (6., 8.)
+  complex, parameter :: z4 = 2 * (3., 4.)
+  logical, parameter :: test_z4 = z4 == (6., 8.)
+  complex, parameter :: z5 = 5. - (3., 4.)
+  logical, parameter :: test_z5 = z5 == (2., -4.)
+  complex, parameter :: z6 = 5 - (3., 4.)
+  logical, parameter :: test_z6 = z6 == (2., -4.)
+  complex, parameter :: z11 = (2., 3.) + 1.
+  logical, parameter :: test_z11 = z11 == (3., 3.)
+  complex, parameter :: z12 = (2., 3.) + 1
+  logical, parameter :: test_z12 = z12 == (3., 3.)
+  complex, parameter :: z13 = (3., 4.) * 2.
+  logical, parameter :: test_z13 = z13 == (6., 8.)
+  complex, parameter :: z14 = (3., 4.) * 2
+  logical, parameter :: test_z14 = z14 == (6., 8.)
+  complex, parameter :: z15 = (3., 4.) - 1.
+  logical, parameter :: test_z15 = z15 == (2., 4.)
+  complex, parameter :: z16 = (3., 4.) - 1
+  logical, parameter :: test_z16 = z16 == (2., 4.)
+  complex, parameter :: z17 = (3., 4.) / 2.
+  logical, parameter :: test_z17 = z17 == (1.5, 2.)
+  complex, parameter :: z18 = (3., 4.) / 2
+  logical, parameter :: test_z18 = z18 == (1.5, 2.)
+end module
Index: flang/lib/Evaluate/tools.cpp
===================================================================
--- flang/lib/Evaluate/tools.cpp
+++ flang/lib/Evaluate/tools.cpp
@@ -242,9 +242,9 @@
     // (a,b) * x -> (a*x, b*x)
     // (a,b) / x -> (a/x, b/x)
     auto copy{iry};
-    auto rr{NumericOperation<Multiply>(messages, AsGenericExpr(std::move(zr)),
+    auto rr{NumericOperation<OPR>(messages, AsGenericExpr(std::move(zr)),
         AsGenericExpr(std::move(iry)), defaultRealKind)};
-    auto ri{NumericOperation<Multiply>(messages, AsGenericExpr(std::move(zi)),
+    auto ri{NumericOperation<OPR>(messages, AsGenericExpr(std::move(zi)),
         AsGenericExpr(std::move(copy)), defaultRealKind)};
     if (auto parts{common::AllPresent(std::move(rr), std::move(ri))}) {
       return Package(ConstructComplex(messages, std::get<0>(std::move(*parts)),
@@ -287,7 +287,7 @@
       std::is_same_v<OPR<LargestReal>, Multiply<LargestReal>>) {
     // x + (a,b) -> (a,b) + x -> (a+x, b)
     // x * (a,b) -> (a,b) * x -> (a*x, b*x)
-    return MixedComplexLeft<Add, LCAT>(
+    return MixedComplexLeft<OPR, LCAT>(
         messages, std::move(zy), std::move(irx), defaultRealKind);
   } else if constexpr (std::is_same_v<OPR<LargestReal>,
                            Subtract<LargestReal>>) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85864.285211.patch
Type: text/x-patch
Size: 2868 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20200812/2e7bedd4/attachment-0001.bin>


More information about the flang-commits mailing list