public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hjl.tools at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/55142] [4.8 Regression] internal compiler error: in plus_constant, at explow.c:88
Date: Wed, 31 Oct 2012 12:20:00 -0000	[thread overview]
Message-ID: <bug-55142-4-edWSPAaew1@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-55142-4@http.gcc.gnu.org/bugzilla/>


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55142

--- Comment #8 from H.J. Lu <hjl.tools at gmail dot com> 2012-10-31 12:19:56 UTC ---
Does this make any senses?

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 5ea5110..50879d6 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -7038,6 +7038,24 @@ fold_to_nonsharp_ineq_using_bound (location_t loc, tree
ineq, tree bound)
   return fold_build2_loc (loc, GE_EXPR, type, a, y);
 }

+static unsigned int
+unsigned_expr_operands (tree op)
+{
+  switch (TREE_CODE (op))
+    {
+    case MULT_EXPR:
+      if (!unsigned_expr_operands (TREE_OPERAND (op, 0)))
+    return 0;
+      return unsigned_expr_operands (TREE_OPERAND (op, 1));
+
+    case NOP_EXPR:
+      return unsigned_expr_operands (TREE_OPERAND (op, 0));
+
+    default:
+      return TYPE_UNSIGNED (TREE_TYPE (op));
+    }
+}
+
 /* Fold a sum or difference of at least one multiplication.
    Returns the folded tree or NULL if no simplification could be made.  */

@@ -7048,6 +7066,17 @@ fold_plusminus_mult_expr (location_t loc, enum tree_code
code, tree type,
   tree arg00, arg01, arg10, arg11;
   tree alt0 = NULL_TREE, alt1 = NULL_TREE, same;

+  /* Make sure the type is not saturating and has the signedness of
+     the stripped operands, as fold_plusminus_mult_expr will re-associate.
+     ??? The latter condition should use TYPE_OVERFLOW_* flags instead.  */
+  if (!((TREE_CODE (arg0) == MULT_EXPR
+       || TREE_CODE (arg1) == MULT_EXPR)
+      && !TYPE_SATURATING (type)
+      && TYPE_UNSIGNED (type) == unsigned_expr_operands (arg0)
+      && TYPE_UNSIGNED (type) == unsigned_expr_operands (arg1)
+      && (!FLOAT_TYPE_P (type) || flag_associative_math)))
+    return NULL_TREE;
+
   /* (A * C) +- (B * C) -> (A+-B) * C.
      (A * C) +- A -> A * (C+-1).
      We are most concerned about the case where C is a constant,
@@ -10042,17 +10071,7 @@ fold_binary_loc (location_t loc,
         }
     }

-      /* Handle (A1 * C1) + (A2 * C2) with A1, A2 or C1, C2 being the same or
-     one.  Make sure the type is not saturating and has the signedness of
-     the stripped operands, as fold_plusminus_mult_expr will re-associate.
-     ??? The latter condition should use TYPE_OVERFLOW_* flags instead.  */
-      if ((TREE_CODE (arg0) == MULT_EXPR
-       || TREE_CODE (arg1) == MULT_EXPR)
-      && !TYPE_SATURATING (type)
-      && TYPE_UNSIGNED (type) == TYPE_UNSIGNED (TREE_TYPE (arg0))
-      && TYPE_UNSIGNED (type) == TYPE_UNSIGNED (TREE_TYPE (arg1))
-      && (!FLOAT_TYPE_P (type) || flag_associative_math))
-        {
+    {
       tree tem = fold_plusminus_mult_expr (loc, code, type, arg0, arg1);
       if (tem)
         return tem;
@@ -10668,17 +10687,7 @@ fold_binary_loc (location_t loc,
       && (tem = distribute_real_division (loc, code, type, arg0, arg1)))
     return tem;

-      /* Handle (A1 * C1) - (A2 * C2) with A1, A2 or C1, C2 being the same or
-     one.  Make sure the type is not saturating and has the signedness of
-     the stripped operands, as fold_plusminus_mult_expr will re-associate.
-     ??? The latter condition should use TYPE_OVERFLOW_* flags instead.  */
-      if ((TREE_CODE (arg0) == MULT_EXPR
-       || TREE_CODE (arg1) == MULT_EXPR)
-      && !TYPE_SATURATING (type)
-      && TYPE_UNSIGNED (type) == TYPE_UNSIGNED (TREE_TYPE (arg0))
-      && TYPE_UNSIGNED (type) == TYPE_UNSIGNED (TREE_TYPE (arg1))
-      && (!FLOAT_TYPE_P (type) || flag_associative_math))
-        {
+    {
       tree tem = fold_plusminus_mult_expr (loc, code, type, arg0, arg1);
       if (tem)
         return tem;


  parent reply	other threads:[~2012-10-31 12:20 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-31  2:05 [Bug middle-end/55142] New: " hjl.tools at gmail dot com
2012-10-31  2:21 ` [Bug middle-end/55142] " hjl.tools at gmail dot com
2012-10-31  8:26 ` hjl.tools at gmail dot com
2012-10-31  9:14 ` hjl.tools at gmail dot com
2012-10-31 10:19 ` hjl.tools at gmail dot com
2012-10-31 10:59 ` ebotcazou at gcc dot gnu.org
2012-10-31 11:09 ` hjl.tools at gmail dot com
2012-10-31 11:26 ` hjl.tools at gmail dot com
2012-10-31 12:20 ` hjl.tools at gmail dot com [this message]
2012-10-31 12:50 ` ebotcazou at gcc dot gnu.org
2012-10-31 13:12 ` hjl.tools at gmail dot com
2012-11-01  8:44 ` ebotcazou at gcc dot gnu.org
2012-11-01 12:51 ` [Bug target/55142] " ebotcazou at gcc dot gnu.org
2012-11-01 14:20 ` ebotcazou at gcc dot gnu.org
2012-11-01 22:24 ` [Bug middle-end/55142] " hjl.tools at gmail dot com
2012-11-01 22:30 ` hjl.tools at gmail dot com
2012-11-01 23:00 ` ebotcazou at gcc dot gnu.org
2012-11-01 23:08 ` hjl.tools at gmail dot com
2012-11-02 23:09 ` hjl.tools at gmail dot com
2012-11-03  2:51 ` hjl.tools at gmail dot com
2012-11-07 18:35 ` ebotcazou at gcc dot gnu.org
2012-11-07 22:12 ` hjl.tools at gmail dot com
2012-11-07 22:43 ` ebotcazou at gcc dot gnu.org
2012-11-07 23:04 ` hjl.tools at gmail dot com
2012-11-08 16:11 ` ebotcazou at gcc dot gnu.org
2012-11-08 16:24 ` ubizjak at gmail dot com
2012-11-08 16:34 ` ubizjak at gmail dot com
2012-11-08 17:18 ` ebotcazou at gcc dot gnu.org
2012-11-08 23:03 ` hjl.tools at gmail dot com
2012-11-08 23:22 ` ebotcazou at gcc dot gnu.org
2012-11-09  0:35 ` hjl.tools at gmail dot com
2012-11-09  2:36 ` hjl.tools at gmail dot com
2012-11-12  4:08 ` hjl.tools at gmail dot com
2012-11-13 14:17 ` ebotcazou at gcc dot gnu.org
2012-11-13 14:32 ` [Bug target/55142] " hjl.tools at gmail dot com
2012-11-13 18:21 ` hjl.tools at gmail dot com
2012-11-13 18:36 ` [Bug middle-end/55142] " hjl at gcc dot gnu.org
2012-11-13 19:37 ` ebotcazou at gcc dot gnu.org
2012-11-19 19:18 ` hjl at gcc dot gnu.org
2014-05-30  2:22 ` pinskia at gcc dot gnu.org
2014-05-30 22:47 ` pinskia at gcc dot gnu.org
2014-11-23  4:13 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-55142-4-edWSPAaew1@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).