[PATCH] PR c/12312: Fix (not (eq X Y)) into (ne X Y) thinko.

Roger Sayle roger@eyesopen.com
Thu Sep 18 13:27:00 GMT 2003


Once again my sincere apologies.  In my endurance attempts to fix
PR bootstrap/12269, I tried to reproduce the problem on non IA-64
platforms by extending the RTL simplification of (not (eq X Y))
into (ne (X Y)) to modes other than BImode.  My only excuse is that
I was obviously sleep deprived at the time.  In RTL, the "not"
operator is the bit-wise not operation (i.e. C's "~"), and isn't
the truth-value or logical not operation (i.e. C's "!").

Clearly this transformation only works when STORE_FLAG_VALUE is -1, so
that const_true_rtx is constm1_rtx, or when the mode is only a single
bit wide, i.e. BImode.

In the PR's example, we end up with the expresssion x + (-(y == 0) - 1),
which we try to simplify via the transformation that -z - 1 is ~z, and
end up with x + (y != 0).  This is only safe under the conditions
described above.

This patch adds back the necessary check for BImode, but now also
supports negative STORE_FLAG_VALUE targets.  Sorry once again for
the inconvenience.


The following patch has been tested with a complete bootstrap, all
languages except treelang, on i686-pc-linux-gnu with no new failures.
It also fixes the current bootstrap failure of hppa2.0w-hp-hpux11.00.
All the compilers (except Java, Ada and treelang) bootstrap, and the
build then fails in libstdc++ at exactly the same place that it fails
for alphaev67-dec-osf5.1.  Using --enable-languages="c,objc,f77", the
bootstrap now runs to completion.

Ok for mainline?


2003-09-18  Roger Sayle  <roger@eyesopen.com>

	PR c/12312
	* simplify-rtx.c (simplify_unary_operation): Only transform
	(not (eq X Y)) into (ne X Y) when mode is BImode or STORE_FLAG_VALUE
	is -1.  RTL "not" is a bit-wise not, "~", not a logical not "!".


Index: simplify-rtx.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/simplify-rtx.c,v
retrieving revision 1.159
diff -c -3 -p -r1.159 simplify-rtx.c
*** simplify-rtx.c	16 Sep 2003 17:16:24 -0000	1.159
--- simplify-rtx.c	18 Sep 2003 02:04:17 -0000
*************** simplify_unary_operation (enum rtx_code
*** 808,813 ****
--- 808,814 ----

  	  /* (not (eq X Y)) == (ne X Y), etc.  */
  	  if (GET_RTX_CLASS (GET_CODE (op)) == '<'
+ 	      && (mode == BImode || STORE_FLAG_VALUE == -1)
  	      && ((reversed = reversed_comparison_code (op, NULL_RTX))
  		  != UNKNOWN))
  	    return simplify_gen_relational (reversed, mode, VOIDmode,

Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833



More information about the Gcc-patches mailing list