public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/29964] New: volatile problem in optimized functions
@ 2006-11-23 21:31 sb at anoto dot com
2006-11-23 21:34 ` [Bug c/29964] " sb at anoto dot com
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: sb at anoto dot com @ 2006-11-23 21:31 UTC (permalink / raw)
To: gcc-bugs
Using -Os and volatile results in functions, sometimes the optimizer 'forgets'
the volatile property of the function and makes it pure. This has a major
impact in some cases. Test case 1 gives buggy code where test case 2 & 3 works.
The command line to compile this was arm-elf-gcc -c test.c -Os
/* Test case 1 */
struct test_a { volatile int a; };
int func_a(void) __attribute__ ((noinline));
int func_a(void)
{
return ((struct test_a *)0)->a;
}
void a(void)
{
while(func_a() == 0);
}
/* Test case 2 */
struct test_b { volatile int a;};
int func_b(void) __attribute__ ((noinline));
int func_b(void)
{
volatile struct test_b *t= 0;
return t->a;
}
void b(void)
{
while(func_b() == 0);
}
/* Test case 3 */
struct test_c { volatile int a; };
int func_c(void) __attribute__ ((noinline));
int func_c(void)
{
return ((volatile struct test_c *)0)->a;
}
void c(void)
{
while(func_c() == 0);
}
The result from this is:
00000000 <func_a>:
0: e3a03000 mov r3, #0 ; 0x0
4: e5930000 ldr r0, [r3]
8: e12fff1e bx lr
0000000c <a>:
c: e52de004 str lr, [sp, #-4]!
10: ebfffffe bl 0 <func_a>
14: e3500000 cmp r0, #0 ; 0x0
18: 0a000003 beq 14 <a+0x8> <--- looping back to the cmp!?!
1c: e49df004 ldr pc, [sp], #4
00000020 <func_b>:
20: e3a03000 mov r3, #0 ; 0x0
24: e5930000 ldr r0, [r3]
28: e12fff1e bx lr
0000002c <b>:
2c: e52de004 str lr, [sp, #-4]!
30: ebfffffe bl 20 <func_b>
34: e3500000 cmp r0, #0 ; 0x0
38: 0a00000a beq 30 <b+0x4> <--- looping back to the functon
call
3c: e49df004 ldr pc, [sp], #4
00000040 <func_c>:
40: e3a03000 mov r3, #0 ; 0x0
44: e5930000 ldr r0, [r3]
48: e12fff1e bx lr
0000004c <c>:
4c: e52de004 str lr, [sp, #-4]!
50: ebfffffe bl 40 <func_c>
54: e3500000 cmp r0, #0 ; 0x0
58: 0a000012 beq 50 <c+0x4> <--- looping back to the functon
call
5c: e49df004 ldr pc, [sp], #4
--
Summary: volatile problem in optimized functions
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sb at anoto dot com
GCC build triplet: x86-pc-cygwin
GCC host triplet: x86-pc-cygwin
GCC target triplet: arm-elf-gcc
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29964
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/29964] volatile problem in optimized functions
2006-11-23 21:31 [Bug c/29964] New: volatile problem in optimized functions sb at anoto dot com
@ 2006-11-23 21:34 ` sb at anoto dot com
2006-11-23 21:41 ` [Bug tree-optimization/29964] [4.1/4.2/4.3 Regression] function with volatile operators still found to be pure pinskia at gcc dot gnu dot org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: sb at anoto dot com @ 2006-11-23 21:34 UTC (permalink / raw)
To: gcc-bugs
--
sb at anoto dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |sb at anoto dot com
Severity|normal |major
Keywords| |wrong-code
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29964
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/29964] [4.1/4.2/4.3 Regression] function with volatile operators still found to be pure
2006-11-23 21:31 [Bug c/29964] New: volatile problem in optimized functions sb at anoto dot com
2006-11-23 21:34 ` [Bug c/29964] " sb at anoto dot com
@ 2006-11-23 21:41 ` pinskia at gcc dot gnu dot org
2006-11-23 22:08 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-23 21:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2006-11-23 21:40 -------
Confirmed. IPA pure-const pass is founds func_a as pure which is incorrect:
Function found to be pure: func_a
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu dot
| |org
Severity|major |normal
Status|UNCONFIRMED |NEW
Component|c |tree-optimization
Ever Confirmed|0 |1
GCC build triplet|x86-pc-cygwin |
GCC host triplet|x86-pc-cygwin |
GCC target triplet|arm-elf-gcc |
Last reconfirmed|0000-00-00 00:00:00 |2006-11-23 21:40:57
date| |
Summary|volatile problem in |[4.1/4.2/4.3 Regression]
|optimized functions |function with volatile
| |operators still found to be
| |pure
Target Milestone|--- |4.1.2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29964
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/29964] [4.1/4.2/4.3 Regression] function with volatile operators still found to be pure
2006-11-23 21:31 [Bug c/29964] New: volatile problem in optimized functions sb at anoto dot com
2006-11-23 21:34 ` [Bug c/29964] " sb at anoto dot com
2006-11-23 21:41 ` [Bug tree-optimization/29964] [4.1/4.2/4.3 Regression] function with volatile operators still found to be pure pinskia at gcc dot gnu dot org
@ 2006-11-23 22:08 ` pinskia at gcc dot gnu dot org
2006-11-23 22:49 ` pinskia at gcc dot gnu dot org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-23 22:08 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2006-11-23 22:08 -------
And I have a fix which I am testing right now. It moves some code around so we
get the correct result.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |pinskia at gcc dot gnu dot
|dot org |org
Status|NEW |ASSIGNED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29964
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/29964] [4.1/4.2/4.3 Regression] function with volatile operators still found to be pure
2006-11-23 21:31 [Bug c/29964] New: volatile problem in optimized functions sb at anoto dot com
` (2 preceding siblings ...)
2006-11-23 22:08 ` pinskia at gcc dot gnu dot org
@ 2006-11-23 22:49 ` pinskia at gcc dot gnu dot org
2006-11-24 18:32 ` pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-23 22:49 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2006-11-23 22:49 -------
By the way this is the patch which I am testing:
Index: ipa-pure-const.c
===================================================================
--- ipa-pure-const.c (revision 119134)
+++ ipa-pure-const.c (working copy)
@@ -166,6 +166,14 @@ check_tree (funct_state local, tree t, b
if ((TREE_CODE (t) == EXC_PTR_EXPR) || (TREE_CODE (t) == FILTER_EXPR))
return;
+ /* Any tree which is volatile disqualifies this function from being
+ const or pure. */
+ if (TREE_THIS_VOLATILE (t))
+ {
+ local->pure_const_state = IPA_NEITHER;
+ return;
+ }
+
while (TREE_CODE (t) == REALPART_EXPR
|| TREE_CODE (t) == IMAGPART_EXPR
|| handled_component_p (t))
@@ -183,12 +191,13 @@ check_tree (funct_state local, tree t, b
/* Any indirect reference that occurs on the lhs
disqualifies the function from being pure or const. Any
- indirect reference to a volatile disqualifies the
- function from being pure or const. Any indirect
- reference that occurs on the rhs disqualifies the
+ indirect reference that occurs on the rhs disqualifies the
function from being const. */
- if (checking_write || TREE_THIS_VOLATILE (t))
- local->pure_const_state = IPA_NEITHER;
+ if (checking_write)
+ {
+ local->pure_const_state = IPA_NEITHER;
+ return;
+ }
else if (local->pure_const_state == IPA_CONST)
local->pure_const_state = IPA_PURE;
}
@@ -541,7 +550,7 @@ analyze_function (struct cgraph_node *fn
walk_tree (bsi_stmt_ptr (bsi), scan_function,
fn, visited_nodes);
if (l->pure_const_state == IPA_NEITHER)
- return;
+ goto end;
}
}
@@ -568,6 +577,14 @@ analyze_function (struct cgraph_node *fn
pop_cfun ();
}
}
+
+end:
+ if (dump_file)
+ {
+ fprintf (dump_file, "after local analysis of %s with initial value =
%d\n ",
+ cgraph_node_name (fn),
+ l->pure_const_state);
+ }
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29964
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/29964] [4.1/4.2/4.3 Regression] function with volatile operators still found to be pure
2006-11-23 21:31 [Bug c/29964] New: volatile problem in optimized functions sb at anoto dot com
` (3 preceding siblings ...)
2006-11-23 22:49 ` pinskia at gcc dot gnu dot org
@ 2006-11-24 18:32 ` pinskia at gcc dot gnu dot org
2006-11-24 18:34 ` [Bug tree-optimization/29964] [4.1/4.2 " pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-24 18:32 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from pinskia at gcc dot gnu dot org 2006-11-24 18:32 -------
Subject: Bug 29964
Author: pinskia
Date: Fri Nov 24 18:32:14 2006
New Revision: 119162
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119162
Log:
2006-11-24 Andrew Pinski <andrew_pinski@playstation.sony.com>
PR tree-opt/29964
* ipa-pure-const.c (check_tree): If the original tree
is volatile return early and say the function is not pure
nor const. Remove the volatile check for writes.
(analyze_function): Print out the result of the local
analysis pass.
2006-11-24 Andrew Pinski <andrew_pinski@playstation.sony.com>
PR tree-opt/29964
* gcc.dg/pure-1.c: New test.
Added:
trunk/gcc/testsuite/gcc.dg/pure-1.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/ipa-pure-const.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29964
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/29964] [4.1/4.2 Regression] function with volatile operators still found to be pure
2006-11-23 21:31 [Bug c/29964] New: volatile problem in optimized functions sb at anoto dot com
` (4 preceding siblings ...)
2006-11-24 18:32 ` pinskia at gcc dot gnu dot org
@ 2006-11-24 18:34 ` pinskia at gcc dot gnu dot org
2006-11-25 16:45 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-24 18:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from pinskia at gcc dot gnu dot org 2006-11-24 18:34 -------
Fixed on the mainline will test and commit to the 4.1 and 4.2 branches later
this holiday weekend.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |4.1.1 4.2.0
Known to work| |4.0.4 4.3.0
Summary|[4.1/4.2/4.3 Regression] |[4.1/4.2 Regression]
|function with volatile |function with volatile
|operators still found to be |operators still found to be
|pure |pure
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29964
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/29964] [4.1/4.2 Regression] function with volatile operators still found to be pure
2006-11-23 21:31 [Bug c/29964] New: volatile problem in optimized functions sb at anoto dot com
` (5 preceding siblings ...)
2006-11-24 18:34 ` [Bug tree-optimization/29964] [4.1/4.2 " pinskia at gcc dot gnu dot org
@ 2006-11-25 16:45 ` pinskia at gcc dot gnu dot org
2006-11-25 21:12 ` [Bug tree-optimization/29964] [4.1 " pinskia at gcc dot gnu dot org
2006-11-25 21:12 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-25 16:45 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from pinskia at gcc dot gnu dot org 2006-11-25 16:45 -------
Subject: Bug 29964
Author: pinskia
Date: Sat Nov 25 16:45:09 2006
New Revision: 119202
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119202
Log:
2006-11-25 Andrew Pinski <andrew_pinski@playstation.sony.com>
PR tree-opt/29964
* ipa-pure-const.c (check_tree): If the original tree
is volatile return early and say the function is not pure
nor const. Remove the volatile check for writes.
(analyze_function): Print out the result of the local
analysis pass.
2006-11-25 Andrew Pinski <andrew_pinski@playstation.sony.com>
PR tree-opt/29964
* gcc.dg/pure-1.c: New test.
Added:
branches/gcc-4_2-branch/gcc/testsuite/gcc.dg/pure-1.c
- copied unchanged from r119162, trunk/gcc/testsuite/gcc.dg/pure-1.c
Modified:
branches/gcc-4_2-branch/gcc/ChangeLog
branches/gcc-4_2-branch/gcc/ipa-pure-const.c
branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29964
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/29964] [4.1 Regression] function with volatile operators still found to be pure
2006-11-23 21:31 [Bug c/29964] New: volatile problem in optimized functions sb at anoto dot com
` (6 preceding siblings ...)
2006-11-25 16:45 ` pinskia at gcc dot gnu dot org
@ 2006-11-25 21:12 ` pinskia at gcc dot gnu dot org
2006-11-25 21:12 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-25 21:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from pinskia at gcc dot gnu dot org 2006-11-25 21:12 -------
Fixed.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29964
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/29964] [4.1 Regression] function with volatile operators still found to be pure
2006-11-23 21:31 [Bug c/29964] New: volatile problem in optimized functions sb at anoto dot com
` (7 preceding siblings ...)
2006-11-25 21:12 ` [Bug tree-optimization/29964] [4.1 " pinskia at gcc dot gnu dot org
@ 2006-11-25 21:12 ` pinskia at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-25 21:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from pinskia at gcc dot gnu dot org 2006-11-25 21:12 -------
Subject: Bug 29964
Author: pinskia
Date: Sat Nov 25 21:12:08 2006
New Revision: 119208
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119208
Log:
2006-11-25 Andrew Pinski <andrew_pinski@playstation.sony.com>
PR tree-opt/29964
* ipa-pure-const.c (check_tree): If the original tree
is volatile return early and say the function is not pure
nor const. Remove the volatile check for writes.
(analyze_function): Print out the result of the local
analysis pass.
2006-11-25 Andrew Pinski <andrew_pinski@playstation.sony.com>
PR tree-opt/29964
* gcc.dg/pure-1.c: New test.
Added:
branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/pure-1.c
- copied unchanged from r119162, trunk/gcc/testsuite/gcc.dg/pure-1.c
Modified:
branches/gcc-4_1-branch/gcc/ChangeLog
branches/gcc-4_1-branch/gcc/ipa-pure-const.c
branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29964
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2006-11-25 21:12 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-23 21:31 [Bug c/29964] New: volatile problem in optimized functions sb at anoto dot com
2006-11-23 21:34 ` [Bug c/29964] " sb at anoto dot com
2006-11-23 21:41 ` [Bug tree-optimization/29964] [4.1/4.2/4.3 Regression] function with volatile operators still found to be pure pinskia at gcc dot gnu dot org
2006-11-23 22:08 ` pinskia at gcc dot gnu dot org
2006-11-23 22:49 ` pinskia at gcc dot gnu dot org
2006-11-24 18:32 ` pinskia at gcc dot gnu dot org
2006-11-24 18:34 ` [Bug tree-optimization/29964] [4.1/4.2 " pinskia at gcc dot gnu dot org
2006-11-25 16:45 ` pinskia at gcc dot gnu dot org
2006-11-25 21:12 ` [Bug tree-optimization/29964] [4.1 " pinskia at gcc dot gnu dot org
2006-11-25 21:12 ` pinskia at gcc dot gnu dot 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).