From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix PR70333
Date: Tue, 22 Mar 2016 14:28:00 -0000 [thread overview]
Message-ID: <alpine.LSU.2.11.1603221416400.15580@t29.fhfr.qr> (raw)
The following fixes another wide-int merge fallout by reverting back
to what the code did before it (doing a wide multiplication).
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.
Richard.
2016-03-22 Richard Biener <rguenther@suse.de>
PR middle-end/70333
* fold-const.c (extract_muldiv_1): Properly perform multiplication
in the wide type.
* gcc.dg/torture/pr70333.c: New testcase.
Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c (revision 234394)
--- gcc/fold-const.c (working copy)
*************** extract_muldiv_1 (tree t, tree c, enum t
*** 6376,6393 ****
bool overflow_p = false;
bool overflow_mul_p;
signop sign = TYPE_SIGN (ctype);
! wide_int mul = wi::mul (op1, c, sign, &overflow_mul_p);
overflow_p = TREE_OVERFLOW (c) | TREE_OVERFLOW (op1);
if (overflow_mul_p
&& ((sign == UNSIGNED && tcode != MULT_EXPR) || sign == SIGNED))
overflow_p = true;
if (!overflow_p)
! {
! mul = wide_int::from (mul, TYPE_PRECISION (ctype),
! TYPE_SIGN (TREE_TYPE (op1)));
! return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
! wide_int_to_tree (ctype, mul));
! }
}
/* If these operations "cancel" each other, we have the main
--- 6376,6392 ----
bool overflow_p = false;
bool overflow_mul_p;
signop sign = TYPE_SIGN (ctype);
! unsigned prec = TYPE_PRECISION (ctype);
! wide_int mul = wi::mul (wide_int::from (op1, prec, sign),
! wide_int::from (c, prec, sign),
! sign, &overflow_mul_p);
overflow_p = TREE_OVERFLOW (c) | TREE_OVERFLOW (op1);
if (overflow_mul_p
&& ((sign == UNSIGNED && tcode != MULT_EXPR) || sign == SIGNED))
overflow_p = true;
if (!overflow_p)
! return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
! wide_int_to_tree (ctype, mul));
}
/* If these operations "cancel" each other, we have the main
Index: gcc/testsuite/gcc.dg/torture/pr70333.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr70333.c (revision 0)
--- gcc/testsuite/gcc.dg/torture/pr70333.c (working copy)
***************
*** 0 ****
--- 1,19 ----
+ /* { dg-do run } */
+ /* { dg-require-effective-target lp64 } */
+
+ unsigned long int
+ foo (signed char b, signed char e)
+ {
+ return ((2ULL * b) * (e * 13)) * (32 << 24);
+ }
+
+ int
+ main ()
+ {
+ if (__CHAR_BIT__ == 8
+ && sizeof (int) == 4
+ && sizeof (long long) == 8
+ && foo (-60, 1) != 0xffffff3d00000000ULL)
+ __builtin_abort ();
+ return 0;
+ }
reply other threads:[~2016-03-22 13:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=alpine.LSU.2.11.1603221416400.15580@t29.fhfr.qr \
--to=rguenther@suse.de \
--cc=gcc-patches@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).