+/* Optimize (X & (-A)) / A where A is a power of 2, to X >> log2(A) */
+(for div (trunc_div ceil_div floor_div round_div exact_div)
+ (simplify
+  (div (convert? (bit_and @0 INTEGER_CST@1)) INTEGER_CST@2)
+  (if (!TYPE_UNSIGNED (type) && integer_pow2p (@2)
+       && tree_int_cst_sgn (@2) > 0
+       && wi::add (@2, @1) == 0
+       && tree_nop_conversion_p (type, TREE_TYPE (@0)))
+   (rshift (convert @0) { build_int_cst (integer_type_node,
+                                        wi::exact_log2 (@2)); }))))

Sorry, I must be very unclear when I write :-(
I indeed like tree_int_cst_sgn (@2) > 0 better than looking at the sign bit, but I don't know why you re-introduced !TYPE_UNSIGNED (type) at the same time. The whole reason I prefer tree_int_cst_sgn is that it also applies when type is unsigned and @2 is 2^31.

--
Marc Glisse

Reply via email to