On Wed, 11 May 2016, Jeff Law wrote:
On 05/11/2016 10:17 AM, Marc Glisse wrote:
The transformation seems right to me, but we are then missing another
transformation like ~X & Y -> X ^ Y when we know that X & ~Y is 0 (the 1
bits of X are included in those of Y). That may not be easy with the
limited bit tracking we have. A version limited to constant Y of the
form 2^n-1 (i.e. 0...01...1) where X has a range included in [0, Y] may
be simpler.
While we don't have strong bit tracking, we do track [0..1] ranges reasonably
well, so it may be worth doing.
I had started writing
+/* Simplify (~X & Y) to X ^ Y if we know that (X & ~Y) is 0. */
+#if GIMPLE
+(simplify
+ (bit_and (bit_not SSA_NAME@0) INTEGER_CST@1)
+ (if ((get_nonzero_bits (@0) & wi::bit_not (@1)) == 0)
+ (bit_xor @0 @1)))
+#endif
but then I realized that VRP does not call the simplify machinery, so this
would have to be rewritten in simplify_bit_ops_using_ranges. The good
point is that we could then compute:
may_be_nonzero_X & ~must_be_nonzero_Y
instead of assuming that Y is a constant (not that it would change
anything in practice).
--
Marc Glisse