This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Deadly optimization bug (all gcc versions!)


Am Son, 22 Aug 1999 schrieb veksler@il.ibm.com:
>Am Mit, 18 Aug 1999 schrieb Franz Sirl:
>> Well, this is the analysis, however I have no idea how to fix it
>correctly :-(.
>> A local fix in if_then_else_cond() would be to compare the results of
>> nonzero_bits(x), reg_nonzero_bits[REGNO(x)] and
>> reg_last_set_nonzero_bits[REGNO(x)] and use the biggest one? But this may
>> just hide other potential problems with get_last_value()?
>
>Is there anyone trying to fix this? If not, I suppose this bug & analysis
>should enter
>some TODO list on gcc & egcs. It should be fixed for:
>   gcc-2.7.2.4 (what is the latest patch version ?)
>   gcc-2.95.2
>   egcs - current.
>
>I could look into it myself, but that would take me a lot of time to learn
>RTL, and
>understand all sort of internal gcc issues (which I would like to avoid).
>Besides, it's
>hard to believe that a bug of this magnitude does not interest people that
>do understand
> what's going on inside gcc.

Well a simple fix is not the problem :-). The appended patch solves your
testcase, I just don't know if it goes far enough. Someone with more knowledge
about combine should look carefully at the optimization in
get_last_value() causing this. Does this optimization possibly cause other
problems? Is this optimization worth the trouble anyway?

Franz.


Index: combine.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/combine.c,v
retrieving revision 1.68
diff -u -p -r1.68 combine.c
--- combine.c	1999/08/20 23:05:06	1.68
+++ combine.c	1999/08/22 10:41:29
@@ -7529,7 +7529,10 @@ nonzero_bits (x, mode)
 
       tem = get_last_value (x);
 
-      if (tem)
+      /* disable this code since get_last_value might return the last
+         value set before the substitution chain, which might have 
+         differing nonzero_bits. */
+      if (0 && tem)
 	{
 #ifdef SHORT_IMMEDIATES_SIGN_EXTEND
 	  /* If X is narrower than MODE and TEM is a non-negative
--- /dev/null	Tue May  5 15:32:27 1998
+++ 19990822.c	Sun Aug 22 05:46:13 1999
@@ -0,0 +1,19 @@
+/* testcase provided by veksler@il.ibm.com */
+
+/* If one=1, then the output should be: bit&1 */
+unsigned test(unsigned one , unsigned  bit)
+{
+   unsigned val=  bit & 1;
+   unsigned zero= one >> 1;
+
+   val++;
+   return zero + ( val>> 1 );
+}
+
+int main()
+{
+   if (test(1,0) != 0) abort();
+   if (test(1,1) != 1) abort();
+   if (test(1,65535) != 1) abort();
+   exit(0);
+}
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]