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]

[PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)


Hi,

Please find attached the patch "PR25529.patch" that converts the pattern:-
(unsigned * 2)/2 is into unsigned &0x7FFFFFFF

Please review and let me know if its okay.

Regression tested on AARH64 and x86_64.

Thanks,
Naveen

gcc/testsuite/ChangeLog:

2015-07-07  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>

	PR middle-end/25529
	* gcc.dg/pr25529.c: New test.

gcc/ChangeLog:

2015-07-07  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>

	PR middle-end/25529
	* match.pd (div (mult @0 INTEGER_CST@1) INTEGER_CST@1) : 
	New simplifier.
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -529,6 +529,16 @@ along with GCC; see the file COPYING3.  If not see
   (bitop (bit_and:c @0 @1) (bit_and @2 @1))
   (bit_and (bitop @0 @2) @1)))
 
+/* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF.  */
+(for div (trunc_div ceil_div floor_div round_div exact_div)
+ (simplify
+  (div (mult @0 INTEGER_CST@1) INTEGER_CST@1)
+  (with { tree n2 = build_int_cst (TREE_TYPE (@0),
+				   wi::exact_log2 (@1)); }
+  (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+   (bit_and @0 (rshift (lshift { build_minus_one_cst (TREE_TYPE (@0)); }
+			       { n2; }) { n2; }))))))
+
 /* (x | CST1) & CST2 -> (x & CST2) | (CST1 & CST2) */
 (simplify
   (bit_and (bit_ior @0 CONSTANT_CLASS_P@1) CONSTANT_CLASS_P@2)

--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr25529.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+f1 (unsigned t)
+{
+  return (t * 2) / 2;
+}
+
+/* { dg-final { scan-tree-dump "\& 2147483647" "optimized" } } */

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