On Fri, 14 May 2021, Jakub Jelinek via Gcc-patches wrote:

On Thu, May 06, 2021 at 09:42:41PM +0200, Marc Glisse wrote:
We can probably do it in 2 steps, first something like

(for cmp (eq ne)
 (simplify
  (cmp (bit_and:c @0 @1) @0)
  (cmp (@0 (bit_not! @1)) { build_zero_cst (TREE_TYPE (@0)); })))

to get rid of the double use, and then simplify X&C==0 to X<=~C if C is a
mask 111...000 (I thought we already had a function to detect such masks, or
the 000...111, but I can't find them anymore).

I agree that the comparison seems preferable, although if X is signed, the
way GIMPLE represents types will add an inconvenient cast. And I think VRP
already manages to use the bit test to derive a range.

I've tried the second step, but it unfortunately regresses
+FAIL: gcc.dg/ipa/propbits-2.c scan-tree-dump-not optimized "fail_test"
+FAIL: gcc.dg/tree-ssa/loop-42.c scan-tree-dump-not ivcanon "under assumptions "
so maybe it is better to keep these cases as the users wrote them.

Thank you for trying it, the patch looks good (it would probably also work on GENERIC), but indeed it is just a canonicalization, not necessarily worth breaking other stuff. This seems to point to another missed optimization. Looking at propbits-2.c, if I rewrite the condition in f1 as

  if ((unsigned)x <= 0xf)

I see later in VRP

  # RANGE [0, 4294967295] NONZERO 15
  x.2_1 = (unsigned intD.9) x_4(D);
  if (x.2_1 <= 15)

where we fail to derive a range from the nonzero bits. Maybe VRP expects IPA-CP should have done it already and doesn't bother recomputing it.

I understand this may not be a priority though, that's fine.

I didn't look at loop-42.c.

--
Marc Glisse

Reply via email to