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: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)


On Tue, 7 Jul 2015, Richard Biener wrote:

On Tue, Jul 7, 2015 at 8:06 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
On Tue, 7 Jul 2015, Hurugalawadi, Naveen wrote:

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


+/* 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)

You don't need to repeat INTEGER_CST, the second time @1 is enough.

+  (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; }))))))

What happens if you write t*3/3?

Huh, and you posted this patch twice?  See my reply to the other copy
for the correctness issues and better handling of exact_div

They are not the same, one is for left shifts and the other one for right shifts. And that makes a big difference: in t*c/c, the division is always exact, so all divisions are equivalent. This is not the case for t/c*c.

--
Marc Glisse


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