public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110165] New: [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8
@ 2023-06-07 23:27 pinskia at gcc dot gnu.org
  2023-06-07 23:28 ` [Bug tree-optimization/110165] " pinskia at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-07 23:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110165
           Summary: [13/14 Regression] wrong code with signed 1 bit
                    integers sometimes since r13-4459-g6508d5e5a1a8
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Full testcase:
````
struct s
{
  int t : 1;
};

[[gnu::noipa]]
int f(struct s t, int a, int b)
{
        int bd = t.t;
        if (bd) a|=b;
        return a;
}

int main(void)
{
        struct s t;
        for(int i = 0;i <= 1; i++)
        {
                int a = 0x10;
                int b = 0x0f;
                int c = a | b;
                int r = f((struct s){i}, a, b);
                int exp = i == 1 ? a | b : a;
                if (exp != r)
                 __builtin_abort();
        }
}
```

Found while improving these match patterns.

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

* [Bug tree-optimization/110165] [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8
  2023-06-07 23:27 [Bug tree-optimization/110165] New: [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8 pinskia at gcc dot gnu.org
@ 2023-06-07 23:28 ` pinskia at gcc dot gnu.org
  2023-06-08  1:24 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-07 23:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-06-07
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
   Target Milestone|---                         |13.2

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

* [Bug tree-optimization/110165] [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8
  2023-06-07 23:27 [Bug tree-optimization/110165] New: [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8 pinskia at gcc dot gnu.org
  2023-06-07 23:28 ` [Bug tree-optimization/110165] " pinskia at gcc dot gnu.org
@ 2023-06-08  1:24 ` pinskia at gcc dot gnu.org
  2023-06-08  1:52 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-08  1:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This will fix the issue:
/* (zero_one == 0) ? y : z <op> y -> ((typeof(y))zero_one * z) <op> y */
(for op (bit_xor bit_ior plus)
 (simplify
  (cond (eq@3 zero_one_valued_p@0
            integer_zerop)
        @1
        (op:c @2 @1))
  (if (INTEGRAL_TYPE_P (type)
       && TYPE_PRECISION (type) > 1
       && (INTEGRAL_TYPE_P (TREE_TYPE (@0))))
       (op (mult (convert:type @3) @2) @1))))

/* (zero_one != 0) ? z <op> y : y -> ((typeof(y))zero_one * z) <op> y */
(for op (bit_xor bit_ior plus)
 (simplify
  (cond (ne@3 zero_one_valued_p@0
            integer_zerop)
       (op:c @2 @1)
        @1)
  (if (INTEGRAL_TYPE_P (type)
       && TYPE_PRECISION (type) > 1
       && (INTEGRAL_TYPE_P (TREE_TYPE (@0))))
       (op (mult (convert:type @3) @2) @1))))

Though it could be improved better. maybe convert followed by & 1 and still @0
rather than @3. still deciding.

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

* [Bug tree-optimization/110165] [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8
  2023-06-07 23:27 [Bug tree-optimization/110165] New: [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8 pinskia at gcc dot gnu.org
  2023-06-07 23:28 ` [Bug tree-optimization/110165] " pinskia at gcc dot gnu.org
  2023-06-08  1:24 ` pinskia at gcc dot gnu.org
@ 2023-06-08  1:52 ` pinskia at gcc dot gnu.org
  2023-06-08 10:17 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-08  1:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This produces better gimple:
```
/* (zero_one == 0) ? y : z <op> y -> ((typeof(y))zero_one * z) <op> y */
(for op (bit_xor bit_ior plus)
 (simplify
  (cond (eq zero_one_valued_p@0
            integer_zerop)
        @1
        (op:c @2 @1))
  (if (INTEGRAL_TYPE_P (type)
       && TYPE_PRECISION (type) > 1
       && (INTEGRAL_TYPE_P (TREE_TYPE (@0))))
       (op (mult (bit_and (convert:type @0) { build_one_cst(type); }) @2)
@1))))

/* (zero_one != 0) ? z <op> y : y -> ((typeof(y))zero_one * z) <op> y */
(for op (bit_xor bit_ior plus)
 (simplify
  (cond (ne zero_one_valued_p@0
            integer_zerop)
       (op:c @2 @1)
        @1)
  (if (INTEGRAL_TYPE_P (type)
       && TYPE_PRECISION (type) > 1
       && (INTEGRAL_TYPE_P (TREE_TYPE (@0))))
       (op (mult (bit_and (convert:type @0) { build_one_cst(type); }) @2)
@1))))
```
But it still has extra gimple produced for unsigned 1 bit field:
```
Folded into the sequence:
_7 = (int) _1;
_8 = (int) _1;
_9 = b_5(D) * _8;
_10 = a_4(D) | _9;
statement un-sinked:
a_6 = a_4(D) | b_5(D);
Removing basic block 3
;; basic block 3, loop depth 0
;;  pred:       2
;;  succ:       4


Removing dead stmt:a_6 = a_4(D) | b_5(D);
Removing dead stmt:_7 = (int) _1;
```
Maybe that is ok.

For signed 1-bit this is produced:
```
Folded into the sequence:
_7 = (int) _1;
_8 = _7 & 1;
_9 = b_5(D) * _8;
_10 = a_4(D) | _9;
statement un-sinked:
a_6 = a_4(D) | b_5(D);
Removing basic block 3
;; basic block 3, loop depth 0
;;  pred:       2
;;  succ:       4


Removing dead stmt:a_6 = a_4(D) | b_5(D);
```

I think this is the best I am going to get it.

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

* [Bug tree-optimization/110165] [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8
  2023-06-07 23:27 [Bug tree-optimization/110165] New: [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8 pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-06-08  1:52 ` pinskia at gcc dot gnu.org
@ 2023-06-08 10:17 ` jakub at gcc dot gnu.org
  2023-06-08 13:39 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-06-08 10:17 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
If zero_one_valued_p is true for [-1, 0] valued cases, then it should be fixed.

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

* [Bug tree-optimization/110165] [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8
  2023-06-07 23:27 [Bug tree-optimization/110165] New: [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8 pinskia at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-06-08 10:17 ` jakub at gcc dot gnu.org
@ 2023-06-08 13:39 ` pinskia at gcc dot gnu.org
  2023-06-08 20:49 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-08 13:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #3)
> If zero_one_valued_p is true for [-1, 0] valued cases, then it should be
> fixed.

I think that is the right appoarch in the end, I will go and implement that.

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

* [Bug tree-optimization/110165] [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8
  2023-06-07 23:27 [Bug tree-optimization/110165] New: [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8 pinskia at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-06-08 13:39 ` pinskia at gcc dot gnu.org
@ 2023-06-08 20:49 ` pinskia at gcc dot gnu.org
  2023-06-09  6:53 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-08 20:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 55287
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55287&action=edit
Patch for trunk

Have the testcases but didn't add them to the patch.
Will also Create the GCC 13 patch later today.

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

* [Bug tree-optimization/110165] [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8
  2023-06-07 23:27 [Bug tree-optimization/110165] New: [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8 pinskia at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-06-08 20:49 ` pinskia at gcc dot gnu.org
@ 2023-06-09  6:53 ` rguenth at gcc dot gnu.org
  2023-06-09 14:15 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-06-09  6:53 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug tree-optimization/110165] [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8
  2023-06-07 23:27 [Bug tree-optimization/110165] New: [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8 pinskia at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-06-09  6:53 ` rguenth at gcc dot gnu.org
@ 2023-06-09 14:15 ` cvs-commit at gcc dot gnu.org
  2023-06-09 14:18 ` [Bug tree-optimization/110165] [13 " pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-09 14:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:72e652f3425079259faa4edefe1dc571f72f91e0

commit r14-1653-g72e652f3425079259faa4edefe1dc571f72f91e0
Author: Andrew Pinski <apinski@marvell.com>
Date:   Thu Jun 8 14:25:51 2023 -0700

    MATCH: Fix zero_one_valued_p not to match signed 1 bit integers

    So for the attached testcase, we assumed that zero_one_valued_p would
    be the value [0,1] but currently zero_one_valued_p matches also
    signed 1 bit integers.
    This changes that not to match that and fixes the 2 new testcases at
    all optimization levels.

    OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

    Note the GCC 13 patch will be slightly different due to the changes
    made to zero_one_valued_p.

            PR tree-optimization/110165
            PR tree-optimization/110166

    gcc/ChangeLog:

            * match.pd (zero_one_valued_p): Don't accept
            signed 1-bit integers.

    gcc/testsuite/ChangeLog:

            * gcc.c-torture/execute/pr110165-1.c: New test.
            * gcc.c-torture/execute/pr110166-1.c: New test.

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

* [Bug tree-optimization/110165] [13 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8
  2023-06-07 23:27 [Bug tree-optimization/110165] New: [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8 pinskia at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2023-06-09 14:15 ` cvs-commit at gcc dot gnu.org
@ 2023-06-09 14:18 ` pinskia at gcc dot gnu.org
  2023-06-09 22:13 ` cvs-commit at gcc dot gnu.org
  2023-06-09 22:15 ` pinskia at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-09 14:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |14.0
            Summary|[13/14 Regression] wrong    |[13 Regression] wrong code
                   |code with signed 1 bit      |with signed 1 bit integers
                   |integers sometimes since    |sometimes since
                   |r13-4459-g6508d5e5a1a8      |r13-4459-g6508d5e5a1a8

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed on the trunk will do a backport with the needed changes.

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

* [Bug tree-optimization/110165] [13 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8
  2023-06-07 23:27 [Bug tree-optimization/110165] New: [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8 pinskia at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2023-06-09 14:18 ` [Bug tree-optimization/110165] [13 " pinskia at gcc dot gnu.org
@ 2023-06-09 22:13 ` cvs-commit at gcc dot gnu.org
  2023-06-09 22:15 ` pinskia at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-09 22:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Andrew Pinski
<pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:682bbd364708fe371b8f34546d970051cdbbfd4c

commit r13-7434-g682bbd364708fe371b8f34546d970051cdbbfd4c
Author: Andrew Pinski <apinski@marvell.com>
Date:   Thu Jun 8 14:25:51 2023 -0700

    MATCH: Fix zero_one_valued_p not to match signed 1 bit integers

    So for the attached testcase, we assumed that zero_one_valued_p would
    be the value [0,1] but currently zero_one_valued_p matches also
    signed 1 bit integers.
    This changes that not to match that and fixes the 2 new testcases at
    all optimization levels.

    OK for GCC 13? Bootstrapped and tested on x86_64-linux-gnu with no
regressions.

            PR tree-optimization/110165
            PR tree-optimization/110166

    gcc/ChangeLog:

            * match.pd (zero_one_valued_p): Don't accept
            signed 1-bit integers.

    gcc/testsuite/ChangeLog:

            * gcc.c-torture/execute/pr110165-1.c: New test.
            * gcc.c-torture/execute/pr110166-1.c: New test.

    (cherry picked from commit 72e652f3425079259faa4edefe1dc571f72f91e0)

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

* [Bug tree-optimization/110165] [13 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8
  2023-06-07 23:27 [Bug tree-optimization/110165] New: [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8 pinskia at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2023-06-09 22:13 ` cvs-commit at gcc dot gnu.org
@ 2023-06-09 22:15 ` pinskia at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-09 22:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2023-06-09 22:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-07 23:27 [Bug tree-optimization/110165] New: [13/14 Regression] wrong code with signed 1 bit integers sometimes since r13-4459-g6508d5e5a1a8 pinskia at gcc dot gnu.org
2023-06-07 23:28 ` [Bug tree-optimization/110165] " pinskia at gcc dot gnu.org
2023-06-08  1:24 ` pinskia at gcc dot gnu.org
2023-06-08  1:52 ` pinskia at gcc dot gnu.org
2023-06-08 10:17 ` jakub at gcc dot gnu.org
2023-06-08 13:39 ` pinskia at gcc dot gnu.org
2023-06-08 20:49 ` pinskia at gcc dot gnu.org
2023-06-09  6:53 ` rguenth at gcc dot gnu.org
2023-06-09 14:15 ` cvs-commit at gcc dot gnu.org
2023-06-09 14:18 ` [Bug tree-optimization/110165] [13 " pinskia at gcc dot gnu.org
2023-06-09 22:13 ` cvs-commit at gcc dot gnu.org
2023-06-09 22:15 ` 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).