public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/80588] GCC can't simplify static inline function with xor/xnor
       [not found] <bug-80588-4@http.gcc.gnu.org/bugzilla/>
@ 2020-12-17 23:22 ` sucicf1 at outlook dot com
  2021-07-25  4:58 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: sucicf1 at outlook dot com @ 2020-12-17 23:22 UTC (permalink / raw)
  To: gcc-bugs

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

Ivan Sučić <sucicf1 at outlook dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sucicf1 at outlook dot com

--- Comment #2 from Ivan Sučić <sucicf1 at outlook dot com> ---
By me everything works but test2b. When I in match.pd remove /* Try to fold
(type) X op CST -> (type) (X op ((type-x) CST))
   when profitable.
   For bitwise binary operations apply operand conversions to the
   binary operation result instead of to the operands.  This allows
   to combine successive conversions and bitwise binary operations.
   We combine the above two cases by using a conditional convert.  */
(for bitop (bit_and bit_ior bit_xor)
 (simplify
  (bitop (convert @0) (convert? @1))
  (if (((TREE_CODE (@1) == INTEGER_CST
         && INTEGRAL_TYPE_P (TREE_TYPE (@0))
         && int_fits_type_p (@1, TREE_TYPE (@0)))
        || types_match (@0, @1))
       /* ???  This transform conflicts with fold-const.c doing
          Convert (T)(x & c) into (T)x & (T)c, if c is an integer
          constants (if x has signed type, the sign bit cannot be set
          in c).  This folds extension into the BIT_AND_EXPR.
          Restrict it to GIMPLE to avoid endless recursions.  */
       && (bitop != BIT_AND_EXPR || GIMPLE)
       && (/* That's a good idea if the conversion widens the operand, thus
              after hoisting the conversion the operation will be narrower.  */
           TYPE_PRECISION (TREE_TYPE (@0)) < TYPE_PRECISION (type)
           /* It's also a good idea if the conversion is to a non-integer
              mode.  */
           || GET_MODE_CLASS (TYPE_MODE (type)) != MODE_INT
           /* Or if the precision of TO is not the same as the precision
              of its mode.  */
           || !type_has_mode_precision_p (type)))
   (convert (bitop @0 (convert @1))))))


then test2b optimizes correct. The question is why? In match.pd what does
convert?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug tree-optimization/80588] GCC can't simplify static inline function with xor/xnor
       [not found] <bug-80588-4@http.gcc.gnu.org/bugzilla/>
  2020-12-17 23:22 ` [Bug tree-optimization/80588] GCC can't simplify static inline function with xor/xnor sucicf1 at outlook dot com
@ 2021-07-25  4:58 ` pinskia at gcc dot gnu.org
  2021-07-25  4:58 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-25  4:58 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu.org

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think the biggest issue is:
_8 == _9
For truth_values is not just converted to 
_8 ^ _9

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug tree-optimization/80588] GCC can't simplify static inline function with xor/xnor
       [not found] <bug-80588-4@http.gcc.gnu.org/bugzilla/>
  2020-12-17 23:22 ` [Bug tree-optimization/80588] GCC can't simplify static inline function with xor/xnor sucicf1 at outlook dot com
  2021-07-25  4:58 ` pinskia at gcc dot gnu.org
@ 2021-07-25  4:58 ` pinskia at gcc dot gnu.org
  2021-07-25  5:07 ` pinskia at gcc dot gnu.org
  2022-11-19 23:42 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-25  4:58 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug tree-optimization/80588] GCC can't simplify static inline function with xor/xnor
       [not found] <bug-80588-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2021-07-25  4:58 ` pinskia at gcc dot gnu.org
@ 2021-07-25  5:07 ` pinskia at gcc dot gnu.org
  2022-11-19 23:42 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-25  5:07 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-07-25
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
On the trunk the only one missing is test2b:
  _8 = a_4(D) != 0;
  _9 = b_3(D) != 0;
  _10 = _8 ^ _9;
  _1 = ~_10;
  _7 = _8 == _9;
  _2 = _1 == _7;
  _5 = (int) _2;

If _7 is converted to _8 ^ _9
we would see _7 and _10 are the same
  _10 = _8 ^ _9;
  _1 = ~_10;
  _7 = _10;
  _2 = _1 ^ _7;

And then you have:
(~_10 ^ _10)
Which is always 1
And done.

So:

(simplify
 (eq truth_value@0 truth_value@1)
 (bit_xor @0 @1))
(simplify
 (ne truth_value@0 truth_value@1)
 (bit_xor (bit_xor @0 @1)) { build_one_cst (type); })

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug tree-optimization/80588] GCC can't simplify static inline function with xor/xnor
       [not found] <bug-80588-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2021-07-25  5:07 ` pinskia at gcc dot gnu.org
@ 2022-11-19 23:42 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-19 23:42 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=106379
   Target Milestone|---                         |13.0
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #4)
> (simplify
>  (eq truth_value@0 truth_value@1)
>  (bit_xor @0 @1))
> (simplify
>  (ne truth_value@0 truth_value@1)
>  (bit_xor (bit_xor @0 @1)) { build_one_cst (type); })

Also I had this wrong.
~(a ^ b) is the same as a == b.

This was fixed by r13-1779-g375668e0508fbe173a (aka PR 106379).

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-19 23:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-80588-4@http.gcc.gnu.org/bugzilla/>
2020-12-17 23:22 ` [Bug tree-optimization/80588] GCC can't simplify static inline function with xor/xnor sucicf1 at outlook dot com
2021-07-25  4:58 ` pinskia at gcc dot gnu.org
2021-07-25  4:58 ` pinskia at gcc dot gnu.org
2021-07-25  5:07 ` pinskia at gcc dot gnu.org
2022-11-19 23:42 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).