public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/104551] New: Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids
@ 2022-02-15 18:01 vsevolod.livinskij at frtk dot ru
  2022-02-15 23:21 ` [Bug tree-optimization/104551] [12 Regression] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: vsevolod.livinskij at frtk dot ru @ 2022-02-15 18:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104551
           Summary: Wrong code with -O3 for skylake-avx512,
                    icelake-server, and sapphirerapids
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vsevolod.livinskij at frtk dot ru
  Target Milestone: ---

Reproducer (I was not able to merge it into a single file):
// func.cpp
extern unsigned var_11, var_178;
extern unsigned char arr_492[];
void test() {
  for (bool a = 0; a < (bool)var_11; a = 2)
    for (unsigned b = 0; b < var_11;
         b += 1)
      var_178 = arr_492[b] ? arr_492[b] : (char) b;
}

// driver.cpp 
unsigned int var_11 = 16U;
unsigned int var_178 = 0;
unsigned char arr_492 [16];

void test();

int main() {
    for (int i = 0; i < 16; ++i)
        arr_492 [i] = (unsigned char)128;
    test();
    __builtin_printf("%u\n", var_178);
    if (var_178 != 128)
        __builtin_abort();
    return 0;
}

Error:
>$ g++ -O0 func.cpp driver.cpp -march=skylake-avx512 && sde -skx -- ./a.out 
128
>$ g++ -O3 func.cpp driver.cpp -march=skylake-avx512 && sde -skx -- ./a.out 
4294967168
Aborted (core dumped)

g++ (git://gcc.gnu.org/git/gcc.git:master
58aeb75d4097010ad9bb72b964265b18ab284f93) 12.0.1 20220213 (experimental)

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

* [Bug tree-optimization/104551] [12 Regression] Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids
  2022-02-15 18:01 [Bug tree-optimization/104551] New: Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids vsevolod.livinskij at frtk dot ru
@ 2022-02-15 23:21 ` pinskia at gcc dot gnu.org
  2022-02-16  1:52 ` crazylht at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-15 23:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
            Summary|Wrong code with -O3 for     |[12 Regression] Wrong code
                   |skylake-avx512,             |with -O3 for
                   |icelake-server, and         |skylake-avx512,
                   |sapphirerapids              |icelake-server, and
                   |                            |sapphirerapids
   Target Milestone|---                         |12.0
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-02-15

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, single file version:
unsigned int var_11 = 16U;
unsigned int var_178 = 0;
unsigned char arr_492 [128];
[[gnu::noipa]]
void test() {
  for (bool a = 0; a < (bool)var_11; a = 2)
    for (unsigned b = 0; b < var_11;
         b += 1)
      var_178 = arr_492[b] ? arr_492[b] : (char) b;
}
int main() {
    for (int i = 0; i < 128; ++i)
        arr_492 [i] = (unsigned char)128;
    test();
    __builtin_printf("%u\n", var_178);
    if (var_178 != 128)
        __builtin_abort();
    return 0;
}

----- CUT -----

I increasing the array size to 128 allowed me to merge it, I don't know why
though; maybe because it allowed the code to be vectorize while 16 was not
going to.

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

* [Bug tree-optimization/104551] [12 Regression] Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids
  2022-02-15 18:01 [Bug tree-optimization/104551] New: Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids vsevolod.livinskij at frtk dot ru
  2022-02-15 23:21 ` [Bug tree-optimization/104551] [12 Regression] " pinskia at gcc dot gnu.org
@ 2022-02-16  1:52 ` crazylht at gmail dot com
  2022-02-16  2:34 ` crazylht at gmail dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: crazylht at gmail dot com @ 2022-02-16  1:52 UTC (permalink / raw)
  To: gcc-bugs

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

Hongtao.liu <crazylht at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |crazylht at gmail dot com

--- Comment #2 from Hongtao.liu <crazylht at gmail dot com> ---
let me take a look.

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

* [Bug tree-optimization/104551] [12 Regression] Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids
  2022-02-15 18:01 [Bug tree-optimization/104551] New: Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids vsevolod.livinskij at frtk dot ru
  2022-02-15 23:21 ` [Bug tree-optimization/104551] [12 Regression] " pinskia at gcc dot gnu.org
  2022-02-16  1:52 ` crazylht at gmail dot com
@ 2022-02-16  2:34 ` crazylht at gmail dot com
  2022-02-16  3:57 ` crazylht at gmail dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: crazylht at gmail dot com @ 2022-02-16  2:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Hongtao.liu <crazylht at gmail dot com> ---
(In reply to Hongtao.liu from comment #2)
> let me take a look.

Start with r12-7216

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

* [Bug tree-optimization/104551] [12 Regression] Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids
  2022-02-15 18:01 [Bug tree-optimization/104551] New: Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids vsevolod.livinskij at frtk dot ru
                   ` (2 preceding siblings ...)
  2022-02-16  2:34 ` crazylht at gmail dot com
@ 2022-02-16  3:57 ` crazylht at gmail dot com
  2022-02-17 11:01 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: crazylht at gmail dot com @ 2022-02-16  3:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Hongtao.liu <crazylht at gmail dot com> ---
(In reply to Hongtao.liu from comment #3)
> (In reply to Hongtao.liu from comment #2)
> > let me take a look.
> 
> Start with r12-7216

  for (bool a = 0; a < (bool)var_11; a = 2)
    for (unsigned b = 0; b < var_11;
         b += 1)
      var_178 = arr_492[b] ? arr_492[b] : (char) b;

arr_492[b] is unsigned char, and (char) b is sign char,
vect_recog_cond_expr_convert_pattern shouldn't hanlde this since it's
zero_extend with sign_extend, it's not equal to

    var_178 = arr_492[b] ? (char)arr_492[b] : (char) b;

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

* [Bug tree-optimization/104551] [12 Regression] Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids
  2022-02-15 18:01 [Bug tree-optimization/104551] New: Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids vsevolod.livinskij at frtk dot ru
                   ` (3 preceding siblings ...)
  2022-02-16  3:57 ` crazylht at gmail dot com
@ 2022-02-17 11:01 ` cvs-commit at gcc dot gnu.org
  2022-02-17 11:02 ` crazylht at gmail dot com
  2022-02-18  0:37 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-02-17 11:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:754dce903ca28c4c2f2bc8614a8de5e631655f2e

commit r12-7276-g754dce903ca28c4c2f2bc8614a8de5e631655f2e
Author: liuhongt <hongtao.liu@intel.com>
Date:   Wed Feb 16 12:15:18 2022 +0800

    Restrict the two sources of vect_recog_cond_expr_convert_pattern to be of
the same type when convert is extension.

    It's not equal to transform

     (cond (cmp @1 @2) (convert@3 @4) (convert@5 @6))

     to

     (convert (cmp @1 @2) (convert)@4 @6)

    when(convert@3 @4) is extension because it's zero_extend vs sign_extend.

    gcc/ChangeLog:

            PR tree-optimization/104551
            PR tree-optimization/103771
            * match.pd (cond_expr_convert_p): Add types_match check when
            convert is extension.
            * tree-vect-patterns.cc
            (gimple_cond_expr_convert_p): Adjust comments.
            (vect_recog_cond_expr_convert_pattern): Ditto.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr104551.c: New test.

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

* [Bug tree-optimization/104551] [12 Regression] Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids
  2022-02-15 18:01 [Bug tree-optimization/104551] New: Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids vsevolod.livinskij at frtk dot ru
                   ` (4 preceding siblings ...)
  2022-02-17 11:01 ` cvs-commit at gcc dot gnu.org
@ 2022-02-17 11:02 ` crazylht at gmail dot com
  2022-02-18  0:37 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: crazylht at gmail dot com @ 2022-02-17 11:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Hongtao.liu <crazylht at gmail dot com> ---
Fixed in GCC12.

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

* [Bug tree-optimization/104551] [12 Regression] Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids
  2022-02-15 18:01 [Bug tree-optimization/104551] New: Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids vsevolod.livinskij at frtk dot ru
                   ` (5 preceding siblings ...)
  2022-02-17 11:02 ` crazylht at gmail dot com
@ 2022-02-18  0:37 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-18  0:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

end of thread, other threads:[~2022-02-18  0:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 18:01 [Bug tree-optimization/104551] New: Wrong code with -O3 for skylake-avx512, icelake-server, and sapphirerapids vsevolod.livinskij at frtk dot ru
2022-02-15 23:21 ` [Bug tree-optimization/104551] [12 Regression] " pinskia at gcc dot gnu.org
2022-02-16  1:52 ` crazylht at gmail dot com
2022-02-16  2:34 ` crazylht at gmail dot com
2022-02-16  3:57 ` crazylht at gmail dot com
2022-02-17 11:01 ` cvs-commit at gcc dot gnu.org
2022-02-17 11:02 ` crazylht at gmail dot com
2022-02-18  0:37 ` 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).