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]

Re: [PATCH] Fix PR64126


On Mon, 1 Dec 2014, Richard Biener wrote:

The following fixes PR64126.

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

Richard.

2014-12-01  Richard Biener  <rguenther@suse.de>

	PR middle-end/64126
	* match.pd: Allow conversions in ~A + 1 -> -A, add -A - 1 -> ~A
	and -1 - A -> ~A.
	* fold-const.c (fold_binary_loc): Remove transforms here.

Index: gcc/match.pd
===================================================================
--- gcc/match.pd	(revision 218144)
+++ gcc/match.pd	(working copy)
@@ -484,8 +522,22 @@ (define_operator_list inverted_tcc_compa

  /* ~A + 1 -> -A */
  (simplify
-   (plus (bit_not @0) integer_each_onep)
-   (negate @0))
+   (plus (convert? (bit_not @0)) integer_each_onep)
+   (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
+    (negate (convert @0))))
+
+  /* -A - 1 -> ~A */
+  (simplify
+   (minus (convert? (negate @0)) integer_each_onep)
+   (if (!TYPE_OVERFLOW_TRAPS (type)

I don't understand why TYPE_OVERFLOW_TRAPS is tested for this one but not the others.

+	&& tree_nop_conversion_p (type, TREE_TYPE (@0)))
+    (bit_not (convert @0))))
+
+  /* -1 - A -> ~A */
+  (simplify
+   (minus integer_all_onesp @0)
+   (if (TREE_CODE (type) != COMPLEX_TYPE)
+    (bit_not @0)))

It should also be true for COMPLEX_TYPE where integer_all_onesp tests for -1-i.

(I know you are just copying from fold-const)

--
Marc Glisse


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