From f74811fea0c596c8ba7dbc74dddffe5c7c6e7b14 Mon Sep 17 00:00:00 2001 From: pinskia Date: Fri, 16 Feb 2007 01:27:42 +0000 Subject: [PATCH] 2007-02-15 Andrew Pinski PR middle-end/30433 * fold-const.c (fold_comparison): Add back the folding of constant complex comparisions. 2007-02-15 Andrew Pinski PR middle-end/30433 * gcc.c-torture/compile/pr30433.c: New testcase to check that complex constants comparisions are foldded. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@122029 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 23 +++++++++++++++++++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.c-torture/compile/pr30433.c | 2 ++ 4 files changed, 37 insertions(+) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr30433.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 152407b26c5..aac9a3e3610 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,11 @@ 2007-02-15 Andrew Pinski + PR middle-end/30433 + * fold-const.c (fold_comparison): Add back the + folding of constant complex comparisions. + +2007-02-15 Andrew Pinski + PR middle-end/30729 * stmt.c (warn_if_unused_value): VA_ARG_EXPR has side effects unknown to this function, return early. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 0aca93c386a..3c8636e8fc3 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8852,6 +8852,29 @@ fold_comparison (enum tree_code code, tree type, tree op0, tree op1) } } + /* If this is a comparison of complex values and both sides + are COMPLEX_CST, do the comparision by parts to fold the + comparision. */ + if ((code == EQ_EXPR || code == NE_EXPR) + && TREE_CODE (TREE_TYPE (arg0)) == COMPLEX_TYPE + && TREE_CODE (arg0) == COMPLEX_CST + && TREE_CODE (arg1) == COMPLEX_CST) + { + tree real0, imag0, real1, imag1; + enum tree_code outercode; + + real0 = TREE_REALPART (arg0); + imag0 = TREE_IMAGPART (arg0); + real1 = TREE_REALPART (arg1); + imag1 = TREE_IMAGPART (arg1); + outercode = code == EQ_EXPR ? TRUTH_ANDIF_EXPR : TRUTH_ORIF_EXPR; + + return fold_build2 (outercode, type, + fold_build2 (code, type, real0, real1), + fold_build2 (code, type, imag0, imag1)); + } + + /* Fold a comparison of the address of COMPONENT_REFs with the same type and component to a comparison of the address of the base object. In short, &x->a OP &y->a to x OP y and diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c0fc66a9f32..e05d167bfe9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2007-02-15 Andrew Pinski + PR middle-end/30433 + * gcc.c-torture/compile/pr30433.c: New testcase to check + that complex constants comparisions are foldded. + +2007-02-15 Andrew Pinski + PR C++/30158 * g++.dg/ext/stmtexpr10.C: New testcase. diff --git a/gcc/testsuite/gcc.c-torture/compile/pr30433.c b/gcc/testsuite/gcc.c-torture/compile/pr30433.c new file mode 100644 index 00000000000..1f0edd0794d --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr30433.c @@ -0,0 +1,2 @@ +int f = (_Complex float)(0.5) == 0.5; + -- 2.11.4.GIT