This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: CVS Update: www.netwinder.org: pub
- To: Philip Blundell <pb at nexus dot co dot uk>
- Subject: Re: CVS Update: www.netwinder.org: pub
- From: Jeffrey A Law <law at cygnus dot com>
- Date: Thu, 02 Sep 1999 03:28:45 -0600
- cc: Andreas Schwab <schwab at suse dot de>, gcc-patches at gcc dot gnu dot org
- Reply-To: law at cygnus dot com
In message <E11MSbT-0000gd-00@fountain.nexus.co.uk>you write:
> With gcc 2.95 this doesn't work because both the condition and the body
> of the "if" statement are optimized away.
>
> Do you have any suggestions for where to start looking for the bug?
Well, this is how I would debug this problem:
Compile the testcase with the "-dap" flags (in addition to any other flags
you need to expose the bug).
Then start working through the dump files in order (the GCC manual documents
the order of the dump files). You are looking for the first pass in which
the loads & conditional branch disappear.
This bug has existed in gcc-2.8.x, egcs-1.0.x, egcs-1.1.x gcc-2.95.x :( I'll
put it in the potential queue for gcc-2.95.2.
It turns out in this case the memory loads, comparison, etc did not appear
in the first rtl dump. This indicates a problem sometime before rtl
generation.
It turns out to be a simple bug. The compiler has code to try and optimize
range tests.
Basically we had
(ANDIF (EQ X 0) (EQ X 1))
The compiler realized that there is no value of X in which that expression
can ever be true.
But it forgot to take into account volatile :-)
This bug has existed in every gcc/egcs release after gcc-2.7.x. Wow.
I've put the fix in the gcc-2.95.2 potential patches list.
* fold-const.c (fold_range_test): Do not try to fold the range
test if the rhs or lhs has side effects.
Index: fold-const.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/fold-const.c,v
retrieving revision 1.69
diff -c -3 -p -r1.69 fold-const.c
*** fold-const.c 1999/08/27 07:37:16 1.69
--- fold-const.c 1999/09/02 09:34:05
*************** fold_range_test (exp)
*** 3560,3565 ****
--- 3560,3569 ----
tree rhs = make_range (TREE_OPERAND (exp, 1), &in1_p, &low1, &high1);
tree tem;
+ /* Fail if anything is volatile. */
+ if (TREE_SIDE_EFFECTS (lhs) || TREE_SIDE_EFFECTS (rhs))
+ return 0;
+
/* If this is an OR operation, invert both sides; we will invert
again at the end. */
if (or_op)