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 PR27302


This fixes operand_equal_p to consider the swapped comparison code
for comparing the operands, splitted from the previous patch as
requested by Roger, the rest will go into canonicalization and has
to wait for 4.3.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Ok for mainline?

Thanks,
Richard.

2006-05-09  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/27302
	* fold-const.c (operand_equal_p): For two comparisons,
	try comparison of one comparison code swapped if that yields
	the same code.

	* gcc.dg/torture/pr27302.c: New testcase.

Index: fold-const.c
===================================================================
*** fold-const.c	(revision 113628)
--- fold-const.c	(working copy)
*************** operand_equal_p (tree arg0, tree arg1, u
*** 2489,2494 ****
--- 2659,2680 ----
    STRIP_NOPS (arg0);
    STRIP_NOPS (arg1);
  
+   /* In case both args are comparisons but with different comparison
+      code, try to swap the comparison operands of one arg to produce
+      a match and compare that variant.  */
+   if (TREE_CODE (arg0) != TREE_CODE (arg1)
+       && COMPARISON_CLASS_P (arg0)
+       && COMPARISON_CLASS_P (arg1))
+     {
+       enum tree_code swap_code = swap_tree_comparison (TREE_CODE (arg1));
+ 
+       if (TREE_CODE (arg0) == swap_code)
+ 	return operand_equal_p (arg0,
+ 				build2 (swap_code, TREE_TYPE (arg1),
+ 					TREE_OPERAND (arg1, 1),
+ 					TREE_OPERAND (arg1, 0)), flags);
+     }
+ 
    if (TREE_CODE (arg0) != TREE_CODE (arg1)
        /* This is needed for conversions and for COMPONENT_REF.
  	 Might as well play it safe and always test this.  */
Index: testsuite/gcc.dg/torture/pr27302.c
===================================================================
*** testsuite/gcc.dg/torture/pr27302.c	(revision 0)
--- testsuite/gcc.dg/torture/pr27302.c	(revision 0)
***************
*** 0 ****
--- 1,15 ----
+ /* { dg-do run } */
+ 
+ extern void link_error (void);
+ 
+ void test0 (int a, int b)
+ {
+   if ((a < b) != (b > a))
+     link_error ();
+ }
+ 
+ int main()
+ {
+   test0 (1, 2);
+   return 0;
+ }


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