https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126879

            Bug ID: 126879
           Summary: match pattern for `(a ^ b) cmp c || a != b`/`(a ^ b)
                    cmp c && a == b` has non-needed tree_expr_nonzero_p on
                    it
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: easyhack, missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Created attachment 65337
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65337&action=edit
testcase

For the testcase we should produce the same results at -O1. But current does
not because the patterns for `(a ^ b) cmp c || a != b`/`(a ^ b) cmp c && a ==
b` current has a tree_expr_nonzero_p  on it:
```
/* ((a ^ b) & c) cmp d || a != b --> (0 cmp d || a != b). */
/* ((a ^ b) & c) cmp d && a == b --> (0 cmp d && a == b). */
(for bitop (bit_ior bit_and)
     neeq  (ne      eq)
 (for cmp  (simple_comparison)
  (simplify
    (bitop:c
      (cmp:c
        (bit_and:c
          (bit_xor @0 @1)
          tree_expr_nonzero_p@2)
        @3)
      (neeq@4 @0 @1))
    (bitop
      (cmp
        { build_zero_cst (TREE_TYPE (@0)); }
        @3)
      @4))

```

the nonzero is not needed here as `a^b` will be zero in the case of knowing
`a==b`.

Reply via email to