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]
Other format: [Raw text]

[PATCH] Fix combine's simplify_comparison (PR rtl-optimization/51023, take 3)


On Wed, Nov 09, 2011 at 05:47:02PM +0100, Bernd Schmidt wrote:
> Yes, I think I prefer this.

So here is hopefully last iteration of that.

Negative constants that trunc_int_for_mode to the same value
are IMHO just fine too, similarly for ZERO_EXTEND 0xffff for HImode
should be fine too.  On the other side, if mode is DImode and
outer mode of ZERO_EXTEND is TImode, if const_op had the highest bit
set, it would mean it is considered to be 65 1s followed by 63 other
bits.  It is hard to construct testcases for these (except for
the failure), because apparently the FE is already narrowing the comparisons
if the constant is in range.

Ok for trunk if this bootstraps/regtests?

Can you please look at the simplify_set hunk?  Thanks.

2011-11-09  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/51023
	* combine.c (simplify_comparison) <case SIGN_EXTEND>: Don't use
	val_signbit_known_clear_p for signed comparison narrowing
	optimization.  Don't check for non-VOIDmode, use
	HWI_COMPUTABLE_MODE_P macro.
	<case ZERO_EXTEND>: Don't check for non-VOIDmode.
	Optimize even when const_op is equal to GET_MODE_MASK (mode),
	don't optimize if const_op is negative.

	* gcc.c-torture/execute/pr51023.c: New test.

--- gcc/combine.c.jj	2011-11-08 23:35:12.000000000 +0100
+++ gcc/combine.c	2011-11-09 18:03:54.185527804 +0100
@@ -11397,9 +11397,10 @@ simplify_comparison (enum rtx_code code,
 	     later on, and then we wouldn't know whether to sign- or
 	     zero-extend.  */
 	  mode = GET_MODE (XEXP (op0, 0));
-	  if (mode != VOIDmode && GET_MODE_CLASS (mode) == MODE_INT
+	  if (GET_MODE_CLASS (mode) == MODE_INT
 	      && ! unsigned_comparison_p
-	      && val_signbit_known_clear_p (mode, const_op)
+	      && HWI_COMPUTABLE_MODE_P (mode)
+	      && trunc_int_for_mode (const_op, mode) == const_op
 	      && have_insn_for (COMPARE, mode))
 	    {
 	      op0 = XEXP (op0, 0);
@@ -11477,10 +11478,11 @@ simplify_comparison (enum rtx_code code,
 
 	case ZERO_EXTEND:
 	  mode = GET_MODE (XEXP (op0, 0));
-	  if (mode != VOIDmode && GET_MODE_CLASS (mode) == MODE_INT
+	  if (GET_MODE_CLASS (mode) == MODE_INT
 	      && (unsigned_comparison_p || equality_comparison_p)
 	      && HWI_COMPUTABLE_MODE_P (mode)
-	      && ((unsigned HOST_WIDE_INT) const_op < GET_MODE_MASK (mode))
+	      && (unsigned HOST_WIDE_INT) const_op <= GET_MODE_MASK (mode)
+	      && const_op >= 0
 	      && have_insn_for (COMPARE, mode))
 	    {
 	      op0 = XEXP (op0, 0);
--- gcc/testsuite/gcc.c-torture/execute/pr51023.c.jj	2011-11-09 10:17:31.133406427 +0100
+++ gcc/testsuite/gcc.c-torture/execute/pr51023.c	2011-11-09 10:17:13.000000000 +0100
@@ -0,0 +1,18 @@
+/* PR rtl-optimization/51023 */
+
+extern void abort (void);
+
+short int
+foo (long int x)
+{
+  return x;
+}
+
+int
+main ()
+{
+  long int a = 0x4272AL;
+  if (foo (a) == a)
+    abort ();
+  return 0;
+}


	Jakub


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