public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/68067] Wrong constant folding
[not found] <bug-68067-4@http.gcc.gnu.org/bugzilla/>
@ 2015-10-23 16:30 ` jsm28 at gcc dot gnu.org
2015-10-23 16:37 ` [Bug tree-optimization/68067] [4.9/5/6 Regression] " jsm28 at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 7+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2015-10-23 16:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68067
Joseph S. Myers <jsm28 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |NEW
Last reconfirmed| |2015-10-23
Resolution|INVALID |---
Ever confirmed|0 |1
--- Comment #3 from Joseph S. Myers <jsm28 at gcc dot gnu.org> ---
I don't think this is undefined. b is INT_MIN, a valid value of type int. b -
c is also INT_MIN, again no overflow. And a - (b - c) is -1 - INT_MIN, a valid
subtraction whose value is within range.
a + (c - b) would indeed be undefined, but that's not what the source code has.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/68067] [4.9/5/6 Regression] Wrong constant folding
[not found] <bug-68067-4@http.gcc.gnu.org/bugzilla/>
2015-10-23 16:30 ` [Bug c/68067] Wrong constant folding jsm28 at gcc dot gnu.org
@ 2015-10-23 16:37 ` jsm28 at gcc dot gnu.org
2015-10-24 20:34 ` mikpelinux at gmail dot com
` (4 subsequent siblings)
6 siblings, 0 replies; 7+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2015-10-23 16:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68067
Joseph S. Myers <jsm28 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |4.9.4
Summary|Wrong constant folding |[4.9/5/6 Regression] Wrong
| |constant folding
--- Comment #4 from Joseph S. Myers <jsm28 at gcc dot gnu.org> ---
Regression relative to 4.2.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/68067] [4.9/5/6 Regression] Wrong constant folding
[not found] <bug-68067-4@http.gcc.gnu.org/bugzilla/>
2015-10-23 16:30 ` [Bug c/68067] Wrong constant folding jsm28 at gcc dot gnu.org
2015-10-23 16:37 ` [Bug tree-optimization/68067] [4.9/5/6 Regression] " jsm28 at gcc dot gnu.org
@ 2015-10-24 20:34 ` mikpelinux at gmail dot com
2015-10-26 11:45 ` [Bug middle-end/68067] " rguenth at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 7+ messages in thread
From: mikpelinux at gmail dot com @ 2015-10-24 20:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68067
Mikael Pettersson <mikpelinux at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mikpelinux at gmail dot com
--- Comment #5 from Mikael Pettersson <mikpelinux at gmail dot com> ---
Started with r124217:
--- pr68067.s-r124216 2015-10-24 22:29:26.827234815 +0200
+++ pr68067.s-r124217 2015-10-24 22:24:24.287329237 +0200
@@ -5,8 +5,9 @@
.type main, @function
main:
.LFB2:
- xorl %eax, %eax
- ret
+ subq $8, %rsp
+.LCFI0:
+ call abort
.LFE2:
.size main, .-main
.section .eh_frame,"a",@progbits
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/68067] [4.9/5/6 Regression] Wrong constant folding
[not found] <bug-68067-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2015-10-24 20:34 ` mikpelinux at gmail dot com
@ 2015-10-26 11:45 ` rguenth at gcc dot gnu.org
2015-10-26 12:19 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-10-26 11:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68067
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Component|tree-optimization |middle-end
Known to work| |4.2.4
Version|trans-mem |6.0
Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org
Known to fail| |4.3.0, 5.2.0
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Ok, I'll investigate further (the rev. in question just exposes the issue).
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/68067] [4.9/5/6 Regression] Wrong constant folding
[not found] <bug-68067-4@http.gcc.gnu.org/bugzilla/>
` (3 preceding siblings ...)
2015-10-26 11:45 ` [Bug middle-end/68067] " rguenth at gcc dot gnu.org
@ 2015-10-26 12:19 ` rguenth at gcc dot gnu.org
2015-10-28 10:01 ` [Bug middle-end/68067] [4.9/5 " rguenth at gcc dot gnu.org
2015-10-28 10:02 ` rguenth at gcc dot gnu.org
6 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-10-26 12:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68067
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
Ok, so we transform a - (b - c) to (c - b) + a, that's invalid of course. This
also started with GCC 4.3.0.
negate_expr_p has
case MINUS_EXPR:
/* We can't turn -(A-B) into B-A when we honor signed zeros. */
return !HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
&& !HONOR_SIGNED_ZEROS (element_mode (type))
&& reorder_operands_p (TREE_OPERAND (t, 0),
TREE_OPERAND (t, 1));
and fold_binary:
/* A - B -> A + (-B) if B is easily negatable. */
if (negate_expr_p (arg1)
&& !TYPE_OVERFLOW_SANITIZED (type)
&& ((FLOAT_TYPE_P (type)
/* Avoid this transformation if B is a positive REAL_CST. */
&& (TREE_CODE (arg1) != REAL_CST
|| REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg1))))
|| INTEGRAL_TYPE_P (type)))
return fold_build2_loc (loc, PLUS_EXPR, type,
fold_convert_loc (loc, type, arg0),
fold_convert_loc (loc, type,
negate_expr (arg1)));
we can see "!TYPE_OVERFLOW_SANITIZED" here, a clear sign that sth is wrong.
I think the PLUS_EXPR case of negate_expr_p has the same issue
A + B negated as -B - A or -A - B as as if A == INT_MIN and B == 0 we
again get -0 - INT_MIN instead of INT_MIN + 0.
Testcase:
int main(void)
{
int a = -1;
static int b = -2147483647 - 1;
static int c = 0;
int t = a - (b + c*-2);
if (t != 2147483647) { __builtin_abort(); }
return 0;
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/68067] [4.9/5 Regression] Wrong constant folding
[not found] <bug-68067-4@http.gcc.gnu.org/bugzilla/>
` (4 preceding siblings ...)
2015-10-26 12:19 ` rguenth at gcc dot gnu.org
@ 2015-10-28 10:01 ` rguenth at gcc dot gnu.org
2015-10-28 10:02 ` rguenth at gcc dot gnu.org
6 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-10-28 10:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68067
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |6.0
Summary|[4.9/5/6 Regression] Wrong |[4.9/5 Regression] Wrong
|constant folding |constant folding
--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed on trunk sofar.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/68067] [4.9/5 Regression] Wrong constant folding
[not found] <bug-68067-4@http.gcc.gnu.org/bugzilla/>
` (5 preceding siblings ...)
2015-10-28 10:01 ` [Bug middle-end/68067] [4.9/5 " rguenth at gcc dot gnu.org
@ 2015-10-28 10:02 ` rguenth at gcc dot gnu.org
6 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-10-28 10:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68067
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
Author: rguenth
Date: Wed Oct 28 10:01:23 2015
New Revision: 229479
URL: https://gcc.gnu.org/viewcvs?rev=229479&root=gcc&view=rev
Log:
2015-10-28 Richard Biener <rguenther@suse.de>
PR middle-end/68067
* fold-const.c (negate_expr_p): We cannot negate plus or minus
if overflow is not wrapping. Likewise multiplication unless
one operand is constant and not power of two.
(fold_negate_expr): Adjust accordingly.
* gcc.dg/torture/pr68067-1.c: New testcase.
* gcc.dg/torture/pr68067-2.c: Likewise.
Added:
trunk/gcc/testsuite/gcc.dg/torture/pr68067-1.c
trunk/gcc/testsuite/gcc.dg/torture/pr68067-2.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/fold-const.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-10-28 10:02 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-68067-4@http.gcc.gnu.org/bugzilla/>
2015-10-23 16:30 ` [Bug c/68067] Wrong constant folding jsm28 at gcc dot gnu.org
2015-10-23 16:37 ` [Bug tree-optimization/68067] [4.9/5/6 Regression] " jsm28 at gcc dot gnu.org
2015-10-24 20:34 ` mikpelinux at gmail dot com
2015-10-26 11:45 ` [Bug middle-end/68067] " rguenth at gcc dot gnu.org
2015-10-26 12:19 ` rguenth at gcc dot gnu.org
2015-10-28 10:01 ` [Bug middle-end/68067] [4.9/5 " rguenth at gcc dot gnu.org
2015-10-28 10:02 ` rguenth at gcc dot gnu.org
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).