public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/61893] New: Constant folding inhibits trapping with -ftrapv
@ 2014-07-24 9:32 rguenth at gcc dot gnu.org
2014-07-25 10:36 ` [Bug middle-end/61893] " rguenth at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-07-24 9:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61893
Bug ID: 61893
Summary: Constant folding inhibits trapping with -ftrapv
Product: gcc
Version: 4.9.1
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: rguenth at gcc dot gnu.org
int
iaddv (void)
{
return __INT_MAX__ + 1;
}
> ./cc1 -quiet t2.c -ftrapv
t2.c: In function 'iaddv':
t2.c:4:24: warning: integer overflow in expression [-Woverflow]
return __INT_MAX__ + 1;
^
iaddv:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $-2147483648, %eax
popq %rbp
.cfi_def_cfa 7, 8
ret
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/61893] Constant folding inhibits trapping with -ftrapv
2014-07-24 9:32 [Bug middle-end/61893] New: Constant folding inhibits trapping with -ftrapv rguenth at gcc dot gnu.org
@ 2014-07-25 10:36 ` rguenth at gcc dot gnu.org
2014-07-25 11:47 ` rguenth at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-07-25 10:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61893
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed by sth like
Index: fold-const.c
===================================================================
--- fold-const.c (revision 212388)
+++ fold-const.c (working copy)
@@ -1121,7 +1121,12 @@
STRIP_NOPS (arg2);
if (TREE_CODE (arg1) == INTEGER_CST)
- return int_const_binop (code, arg1, arg2);
+ {
+ tree res = int_const_binop (code, arg1, arg2);
+ if (res && TYPE_OVERFLOW_TRAPS (TREE_TYPE (arg1)) && TREE_OVERFLOW
(res))
+ return NULL_TREE;
+ return res;
+ }
if (TREE_CODE (arg1) == REAL_CST)
{
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/61893] Constant folding inhibits trapping with -ftrapv
2014-07-24 9:32 [Bug middle-end/61893] New: Constant folding inhibits trapping with -ftrapv rguenth at gcc dot gnu.org
2014-07-25 10:36 ` [Bug middle-end/61893] " rguenth at gcc dot gnu.org
@ 2014-07-25 11:47 ` rguenth at gcc dot gnu.org
2014-08-27 9:59 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-07-25 11:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61893
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixing bit-ccp with
Index: tree-ssa-ccp.c
===================================================================
--- tree-ssa-ccp.c (revision 213040)
+++ tree-ssa-ccp.c (working copy)
@@ -1456,8 +1456,19 @@ bit_value_unop (enum tree_code code, tre
widest_int value, mask;
prop_value_t val;
- if (rval.lattice_val == UNDEFINED)
- return rval;
+ if (rval.lattice_val == UNDEFINED
+ /* If the value is fully known constants assume that
+ earlier simplification failed for a reason, for example
+ due to -ftrapv. */
+ || (rval.lattice_val == CONSTANT
+ && TREE_CODE (rval.value) == INTEGER_CST
+ && rval.mask == -1))
+ {
+ val.lattice_val = VARYING;
+ val.value = NULL_TREE;
+ val.mask = -1;
+ return val;
+ }
gcc_assert ((rval.lattice_val == CONSTANT
&& TREE_CODE (rval.value) == INTEGER_CST)
@@ -1492,7 +1503,16 @@ bit_value_binop (enum tree_code code, tr
prop_value_t val;
if (r1val.lattice_val == UNDEFINED
- || r2val.lattice_val == UNDEFINED)
+ || r2val.lattice_val == UNDEFINED
+ /* If both values are fully known constants assume that
+ earlier simplification failed for a reason, for example
+ due to -ftrapv. */
+ || (r1val.lattice_val == CONSTANT
+ && TREE_CODE (r1val.value) == INTEGER_CST
+ && r1val.mask == 0
+ && r2val.lattice_val == CONSTANT
+ && TREE_CODE (r2val.value) == INTEGER_CST
+ && r2val.mask == 0))
{
val.lattice_val = VARYING;
val.value = NULL_TREE;
reveals that expansion produces
(insn 5 4 6 (set (reg:SI 4 si)
(const_int 1 [0x1])) t.c:7 -1
(nil))
(insn 6 5 7 (set (reg:SI 5 di)
(const_int 2147483647 [0x7fffffff])) t.c:7 -1
(nil))
(call_insn/u 7 6 8 (set (reg:SI 0 ax)
(call (mem:QI (symbol_ref:DI ("__addvsi3") [flags 0x41]) [0 S1 A8])
(const_int 0 [0]))) t.c:7 -1
(expr_list:REG_EH_REGION (const_int -2147483648 [0xffffffff80000000])
(nil))
(expr_list (use (reg:SI 4 si))
(expr_list (use (reg:SI 5 di))
(nil))))
(insn 8 7 9 (set (reg:SI 86 [ D.1753 ])
(reg:SI 0 ax)) t.c:7 -1
(expr_list:REG_EQUAL (plus:SI (const_int 2147483647 [0x7fffffff])
(const_int 1 [0x1]))
(nil)))
note the REG_EQUAL note which CSE happily simplifies and substitutes...
Index: optabs.c
===================================================================
--- optabs.c (revision 213040)
+++ optabs.c (working copy)
@@ -3985,7 +3985,8 @@ emit_libcall_block_1 (rtx insns, rtx tar
}
last = emit_move_insn (target, result);
- set_dst_reg_note (last, REG_EQUAL, copy_rtx (equiv), target);
+ if (!equiv_may_trap)
+ set_dst_reg_note (last, REG_EQUAL, copy_rtx (equiv), target);
if (final_dest != target)
emit_move_insn (final_dest, target);
with that we finally trap with -O2...
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/61893] Constant folding inhibits trapping with -ftrapv
2014-07-24 9:32 [Bug middle-end/61893] New: Constant folding inhibits trapping with -ftrapv rguenth at gcc dot gnu.org
2014-07-25 10:36 ` [Bug middle-end/61893] " rguenth at gcc dot gnu.org
2014-07-25 11:47 ` rguenth at gcc dot gnu.org
@ 2014-08-27 9:59 ` rguenth at gcc dot gnu.org
2015-10-22 8:19 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-08-27 9:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61893
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2014-08-27
Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org
Ever confirmed|0 |1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/61893] Constant folding inhibits trapping with -ftrapv
2014-07-24 9:32 [Bug middle-end/61893] New: Constant folding inhibits trapping with -ftrapv rguenth at gcc dot gnu.org
` (2 preceding siblings ...)
2014-08-27 9:59 ` rguenth at gcc dot gnu.org
@ 2015-10-22 8:19 ` rguenth at gcc dot gnu.org
2015-10-22 11:44 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-10-22 8:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61893
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |eggert at gnu dot org
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
*** Bug 68046 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/61893] Constant folding inhibits trapping with -ftrapv
2014-07-24 9:32 [Bug middle-end/61893] New: Constant folding inhibits trapping with -ftrapv rguenth at gcc dot gnu.org
` (3 preceding siblings ...)
2015-10-22 8:19 ` rguenth at gcc dot gnu.org
@ 2015-10-22 11:44 ` rguenth at gcc dot gnu.org
2015-10-22 11:45 ` rguenth at gcc dot gnu.org
2021-09-13 20:41 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-10-22 11:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61893
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Author: rguenth
Date: Thu Oct 22 11:44:11 2015
New Revision: 229170
URL: https://gcc.gnu.org/viewcvs?rev=229170&root=gcc&view=rev
Log:
2015-10-22 Richard Biener <rguenther@suse.de>
PR middle-end/68046
PR middle-end/61893
* optabs.c (emit_libcall_block_1): Allow a NULL_RTX equiv.
(expand_binop): For -ftrapv optabs do not record an REG_EQUAL note.
(expand_unop): Likewise.
* gcc.dg/torture/ftrapv-2.c: New testcase.
Added:
trunk/gcc/testsuite/gcc.dg/torture/ftrapv-2.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/optabs.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/61893] Constant folding inhibits trapping with -ftrapv
2014-07-24 9:32 [Bug middle-end/61893] New: Constant folding inhibits trapping with -ftrapv rguenth at gcc dot gnu.org
` (4 preceding siblings ...)
2015-10-22 11:44 ` rguenth at gcc dot gnu.org
@ 2015-10-22 11:45 ` rguenth at gcc dot gnu.org
2021-09-13 20:41 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-10-22 11:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61893
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note only the non-constant-folding part is fixed (the REG_EQUAL notes which
enable combine to remove the trapping).
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/61893] Constant folding inhibits trapping with -ftrapv
2014-07-24 9:32 [Bug middle-end/61893] New: Constant folding inhibits trapping with -ftrapv rguenth at gcc dot gnu.org
` (5 preceding siblings ...)
2015-10-22 11:45 ` rguenth at gcc dot gnu.org
@ 2021-09-13 20:41 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-13 20:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61893
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |john at mcfarlane dot name
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 102303 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-09-13 20:41 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-24 9:32 [Bug middle-end/61893] New: Constant folding inhibits trapping with -ftrapv rguenth at gcc dot gnu.org
2014-07-25 10:36 ` [Bug middle-end/61893] " rguenth at gcc dot gnu.org
2014-07-25 11:47 ` rguenth at gcc dot gnu.org
2014-08-27 9:59 ` rguenth at gcc dot gnu.org
2015-10-22 8:19 ` rguenth at gcc dot gnu.org
2015-10-22 11:44 ` rguenth at gcc dot gnu.org
2015-10-22 11:45 ` rguenth at gcc dot gnu.org
2021-09-13 20:41 ` pinskia 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).