public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/101938] New: [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569
@ 2021-08-16 16:07 marxin at gcc dot gnu.org
2021-08-16 16:07 ` [Bug tree-optimization/101938] " marxin at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-16 16:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101938
Bug ID: 101938
Summary: [12 Regression] Wrong code with -fwrapv since
r12-2591-g2e96b5f14e402569
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: marxin at gcc dot gnu.org
CC: aldyh at gcc dot gnu.org, amacleod at redhat dot com
Target Milestone: ---
It's a test-case reduced from postgresql package:
$ cat postgresql.c
#include <stdio.h>
typedef long long int int64;
#define INT64CONST(x) (x##LL)
#define PG_INT64_MIN (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
static int64
__attribute__((noipa))
int8gcd_internal(int64 arg1, int64 arg2)
{
int64 swap;
int64 a1,
a2;
/*
* Put the greater absolute value in arg1.
*
* This would happen automatically in the loop below, but avoids an
* expensive modulo operation, and simplifies the special-case handling
* for INT64_MIN below.
*
* We do this in negative space in order to handle INT64_MIN.
*/
a1 = (arg1 < 0) ? arg1 : -arg1;
a2 = (arg2 < 0) ? arg2 : -arg2;
if (a1 > a2)
{
swap = arg1;
arg1 = arg2;
arg2 = swap;
}
/* Special care needs to be taken with INT64_MIN. See comments above.
*/
if (arg1 == PG_INT64_MIN)
{
if (arg2 == 0 || arg2 == PG_INT64_MIN)
{
__builtin_printf ("ret=out of range\n");
}
/*
* Some machines throw a floating-point exception for INT64_MIN
% -1,
* which is a bit silly since the correct answer is perfectly
* well-defined, namely zero. Guard against this and just
return the
* result, gcd(INT64_MIN, -1) = 1.
*/
if (arg2 == -1) {
__builtin_printf ("ret=%d\n", 1);
return 1;
}
}
/* Use the Euclidean algorithm to find the GCD */
while (arg2 != 0)
{
swap = arg2;
arg2 = arg1 % arg2;
arg1 = swap;
}
/*
* Make sure the result is positive. (We know we don't have INT64_MIN
* anymore).
*/
if (arg1 < 0)
arg1 = -arg1;
__builtin_printf ("ret=%lld\n", arg1);
return arg1;
}
int main()
{
int8gcd_internal (-1, -9223372036854775808ULL);
return 0;
}
$ gcc postgresql.c -fwrapv && ./a.out
ret=1
$ gcc postgresql.c -O2 -fwrapv && ./a.out
Floating point exception (core dumped)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/101938] [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569
2021-08-16 16:07 [Bug tree-optimization/101938] New: [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569 marxin at gcc dot gnu.org
@ 2021-08-16 16:07 ` marxin at gcc dot gnu.org
2021-08-16 16:19 ` marxin at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-16 16:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101938
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.0
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-08-16
Ever confirmed|0 |1
--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
As noted, started with r12-2591-g2e96b5f14e402569.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/101938] [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569
2021-08-16 16:07 [Bug tree-optimization/101938] New: [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569 marxin at gcc dot gnu.org
2021-08-16 16:07 ` [Bug tree-optimization/101938] " marxin at gcc dot gnu.org
@ 2021-08-16 16:19 ` marxin at gcc dot gnu.org
2021-08-17 7:43 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-16 16:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101938
--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
Simplified test-case:
$ cat postgresql.c
typedef long long int int64;
#define INT64CONST(x) (x##LL)
/* -9223372036854775808ULL */
#define INT64_MIN (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
static void __attribute__((noipa)) foo(int64 arg1, int64 arg2) {
int64 a1 = -arg1;
int64 a2 = (arg2 < 0) ? arg2 : -arg2;
if (a1 > a2) {
int64 swap = arg1;
arg1 = arg2;
arg2 = swap;
}
if (arg1 == INT64_MIN && arg2 == -1) return;
__builtin_abort();
}
int main() {
foo(-1, INT64_MIN);
return 0;
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/101938] [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569
2021-08-16 16:07 [Bug tree-optimization/101938] New: [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569 marxin at gcc dot gnu.org
2021-08-16 16:07 ` [Bug tree-optimization/101938] " marxin at gcc dot gnu.org
2021-08-16 16:19 ` marxin at gcc dot gnu.org
@ 2021-08-17 7:43 ` rguenth at gcc dot gnu.org
2021-08-17 8:58 ` aldyh at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-08-17 7:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101938
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/101938] [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569
2021-08-16 16:07 [Bug tree-optimization/101938] New: [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569 marxin at gcc dot gnu.org
` (2 preceding siblings ...)
2021-08-17 7:43 ` rguenth at gcc dot gnu.org
@ 2021-08-17 8:58 ` aldyh at gcc dot gnu.org
2021-08-17 8:59 ` aldyh at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: aldyh at gcc dot gnu.org @ 2021-08-17 8:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101938
Aldy Hernandez <aldyh at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |aldyh at gcc dot gnu.org
--- Comment #3 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
Created attachment 51312
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51312&action=edit
proposed patch
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/101938] [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569
2021-08-16 16:07 [Bug tree-optimization/101938] New: [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569 marxin at gcc dot gnu.org
` (3 preceding siblings ...)
2021-08-17 8:58 ` aldyh at gcc dot gnu.org
@ 2021-08-17 8:59 ` aldyh at gcc dot gnu.org
2021-08-17 9:39 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: aldyh at gcc dot gnu.org @ 2021-08-17 8:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101938
--- Comment #4 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
This is actually an oversight in the range-ops code. In flag_wrapv
-TYPE_MIN_VALUE = TYPE_MIN_VALUE which is special cased in the ABS folding
routine, but not in operator_abs::op1_range().
Thank you for reporting and distilling this Martin.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/101938] [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569
2021-08-16 16:07 [Bug tree-optimization/101938] New: [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569 marxin at gcc dot gnu.org
` (4 preceding siblings ...)
2021-08-17 8:59 ` aldyh at gcc dot gnu.org
@ 2021-08-17 9:39 ` cvs-commit at gcc dot gnu.org
2021-08-17 9:40 ` aldyh at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-17 9:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101938
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Aldy Hernandez <aldyh@gcc.gnu.org>:
https://gcc.gnu.org/g:891bdbf2b0432b4aa3d3e76923617fcb4fd33cf6
commit r12-2944-g891bdbf2b0432b4aa3d3e76923617fcb4fd33cf6
Author: Andrew MacLeod <amacleod@redhat.com>
Date: Tue Aug 17 10:50:56 2021 +0200
Special case -TYPE_MIN_VALUE for flag_wrapv in operator_abs::op1_range.
With flag_wrapv, -TYPE_MIN_VALUE = TYPE_MIN_VALUE which is
unrepresentable. We currently special case this in the ABS folding
routine, but are missing similar treatment in operator_abs::op1_range.
Tested on x86-64 Linux.
PR tree-optimization/101938
gcc/ChangeLog:
* range-op.cc (operator_abs::op1_range): Special case
-TYPE_MIN_VALUE for flag_wrapv.
gcc/testsuite/ChangeLog:
* gcc.dg/pr101938.c: New test.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/101938] [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569
2021-08-16 16:07 [Bug tree-optimization/101938] New: [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569 marxin at gcc dot gnu.org
` (5 preceding siblings ...)
2021-08-17 9:39 ` cvs-commit at gcc dot gnu.org
@ 2021-08-17 9:40 ` aldyh at gcc dot gnu.org
2021-08-17 9:42 ` marxin at gcc dot gnu.org
2021-08-17 9:43 ` aldyh at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: aldyh at gcc dot gnu.org @ 2021-08-17 9:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101938
Aldy Hernandez <aldyh at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
--- Comment #6 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
fixed in trunk
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/101938] [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569
2021-08-16 16:07 [Bug tree-optimization/101938] New: [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569 marxin at gcc dot gnu.org
` (6 preceding siblings ...)
2021-08-17 9:40 ` aldyh at gcc dot gnu.org
@ 2021-08-17 9:42 ` marxin at gcc dot gnu.org
2021-08-17 9:43 ` aldyh at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-17 9:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101938
--- Comment #7 from Martin Liška <marxin at gcc dot gnu.org> ---
> Thank you for reporting and distilling this Martin.
You're welcome, it was pretty fun isolating that!
Thanks for the hot fix.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/101938] [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569
2021-08-16 16:07 [Bug tree-optimization/101938] New: [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569 marxin at gcc dot gnu.org
` (7 preceding siblings ...)
2021-08-17 9:42 ` marxin at gcc dot gnu.org
@ 2021-08-17 9:43 ` aldyh at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: aldyh at gcc dot gnu.org @ 2021-08-17 9:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101938
--- Comment #8 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
(In reply to Martin Liška from comment #7)
> > Thank you for reporting and distilling this Martin.
>
> You're welcome, it was pretty fun isolating that!
> Thanks for the hot fix.
That was all Andrew! I just wrote comments, tests, and took the credit ;-).
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2021-08-17 9:43 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-16 16:07 [Bug tree-optimization/101938] New: [12 Regression] Wrong code with -fwrapv since r12-2591-g2e96b5f14e402569 marxin at gcc dot gnu.org
2021-08-16 16:07 ` [Bug tree-optimization/101938] " marxin at gcc dot gnu.org
2021-08-16 16:19 ` marxin at gcc dot gnu.org
2021-08-17 7:43 ` rguenth at gcc dot gnu.org
2021-08-17 8:58 ` aldyh at gcc dot gnu.org
2021-08-17 8:59 ` aldyh at gcc dot gnu.org
2021-08-17 9:39 ` cvs-commit at gcc dot gnu.org
2021-08-17 9:40 ` aldyh at gcc dot gnu.org
2021-08-17 9:42 ` marxin at gcc dot gnu.org
2021-08-17 9:43 ` aldyh 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).