public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/102659] New: [false diagnosis] extra warning info after O2 vectorization for gcc.dg/torture/pr69760.c
@ 2021-10-09  4:54 crazylht at gmail dot com
  2021-10-11  8:55 ` [Bug tree-optimization/102659] -O2 vectorization if-conversion produces wrong code " rguenth at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: crazylht at gmail dot com @ 2021-10-09  4:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102659
           Summary: [false diagnosis] extra warning info after O2
                    vectorization for gcc.dg/torture/pr69760.c
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: crazylht at gmail dot com
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-*-* i?86-*-*

options:
../gcc/xgcc -B ../gcc -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects
../../../gcc/intel-innersource/O2_vectorization/gcc/testsuite/gcc.dg/torture/pr69760.c
-m32 -march=cascadelake

../../../gcc/intel-innersource/O2_vectorization/gcc/testsuite/gcc.dg/torture/pr69760.c:
In function ‘test_func’:
../../../gcc/intel-innersource/O2_vectorization/gcc/testsuite/gcc.dg/torture/pr69760.c:16:10:
warning: iteration 54 invokes undefined behavior
[-Waggressive-loop-optimizations]
   16 |         a[L * k] = 0.0;
      |          ^
../../../gcc/intel-innersource/O2_vectorization/gcc/testsuite/gcc.dg/torture/pr69760.c:12:17:
note: within this loop
   12 |   for (i = 0; i < N; i++)
      |                 ^


dump is quite the same as adding -fno-tree-vectorize

@@ -6,44 +6,44 @@ Removing basic block 8
 __attribute__((noclone, noinline))
 void test_func (double * a, int L, int m, int n, int N)
 {
+  unsigned int ivtmp.9;
   unsigned int ivtmp.8;
-  unsigned int ivtmp.7;
-  unsigned int _14;
-  int _26;
-  unsigned int _31;
-  unsigned int _32;
-  double * _33;
-  unsigned int _34;
-  unsigned int _38;
-  void * _39;
+  unsigned int _4;
+  unsigned int _5;
+  double * _6;
+  unsigned int _7;
+  unsigned int _25;
+  unsigned int _26;
+  int _27;
+  void * _40;

   <bb 2> [local count: 118111600]:
-  _26 = -m_13(D);
-  ivtmp.7_1 = (unsigned int) _26;
-  _31 = (unsigned int) m_13(D);
-  _32 = _31 * 4214967296;
-  _33 = a_17(D) + _32;
-  ivtmp.8_30 = (unsigned int) _33;
-  _34 = (unsigned int) a_17(D);
-  _14 = _34 + 1935228928;
-  _38 = _14 + _32;
+  _27 = -m_13(D);
+  ivtmp.8_8 = (unsigned int) _27;
+  _4 = (unsigned int) m_13(D);
+  _5 = _4 * 4214967296;
+  _6 = a_17(D) + _5;
+  ivtmp.9_21 = (unsigned int) _6;
+  _7 = (unsigned int) a_17(D);
+  _26 = _7 + 1935228928;
+  _25 = _5 + _26;

   <bb 3> [local count: 955630225]:
-  # ivtmp.7_3 = PHI <ivtmp.7_2(5), ivtmp.7_1(2)>
-  # ivtmp.8_28 = PHI <ivtmp.8_29(5), ivtmp.8_30(2)>
-  if (ivtmp.7_3 <= 3)
+  # ivtmp.8_3 = PHI <ivtmp.8_8(2), ivtmp.8_38(5)>
+  # ivtmp.9_24 = PHI <ivtmp.9_21(2), ivtmp.9_14(5)>
+  if (ivtmp.8_3 <= 3)
     goto <bb 4>; [50.00%]
   else
     goto <bb 5>; [50.00%]

   <bb 4> [local count: 477815112]:
-  _39 = (void *) ivtmp.8_28;
-  MEM[(double *)_39] = 0.0;
+  _40 = (void *) ivtmp.9_24;
+  MEM[(double *)_40] = 0.0;

   <bb 5> [local count: 955630225]:
-  ivtmp.7_2 = ivtmp.7_3 + 1;
-  ivtmp.8_29 = ivtmp.8_28 + 80000000;
-  if (ivtmp.8_29 != _38)
+  ivtmp.8_38 = ivtmp.8_3 + 1;
+  ivtmp.9_14 = ivtmp.9_24 + 80000000;
+  if (ivtmp.9_14 != _25)
     goto <bb 3>; [87.64%]
   else
     goto <bb 6>; [12.36%]

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

* [Bug tree-optimization/102659] -O2 vectorization if-conversion produces wrong code for gcc.dg/torture/pr69760.c
  2021-10-09  4:54 [Bug debug/102659] New: [false diagnosis] extra warning info after O2 vectorization for gcc.dg/torture/pr69760.c crazylht at gmail dot com
@ 2021-10-11  8:55 ` rguenth at gcc dot gnu.org
  2021-10-11  8:57 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-11  8:55 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-10-11
            Summary|[false diagnosis] extra     |-O2 vectorization
                   |warning info after O2       |if-conversion produces
                   |vectorization for           |wrong code for
                   |gcc.dg/torture/pr69760.c    |gcc.dg/torture/pr69760.c
          Component|debug                       |tree-optimization
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           Keywords|diagnostic                  |wrong-code

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
With -flto we have range info on the test_func function arguments (w/o -flto as
well if you make the function static).

  # RANGE [10000000, 10000000] NONZERO 10000000
  int L_16(D) = L;
  # RANGE [0, 400] NONZERO 508
  int m_13(D) = m;
  # RANGE [4, 4] NONZERO 4
  int n_15(D) = n;
  # RANGE [400, 400] NONZERO 400
  int N_12(D) = N;

the warning is emitted from the max_loop_iterations call in
vect_truncate_gather_scatter_offset, so it's not because something is
vectorized but because we run the vectorizer.  It's also emitted on
the if-converted code only because only then the address computation
of the a[L * k] = 0.0; store can be used to bound the number of iterations.

And indeed the address calculation overflows 32bit memory so this is a problem
with if-conversion since n == 4 and thus

      if (k >= 0 && k < n)
        a[L * k] = 0.0;

will never trigger in iteration 54.

if-conversion doesn't check whether it makes conditional integer overflow
non-conditional.  I think we might have a duplicate report of the problem
somewhere though.

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

* [Bug tree-optimization/102659] -O2 vectorization if-conversion produces wrong code for gcc.dg/torture/pr69760.c
  2021-10-09  4:54 [Bug debug/102659] New: [false diagnosis] extra warning info after O2 vectorization for gcc.dg/torture/pr69760.c crazylht at gmail dot com
  2021-10-11  8:55 ` [Bug tree-optimization/102659] -O2 vectorization if-conversion produces wrong code " rguenth at gcc dot gnu.org
@ 2021-10-11  8:57 ` rguenth at gcc dot gnu.org
  2021-10-11  8:58 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-11  8:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
If you change the testcase as follows the issue pops up at plain -O2 as well

diff --git a/gcc/testsuite/gcc.dg/torture/pr69760.c
b/gcc/testsuite/gcc.dg/torture/pr69760.c
index 53733c7c6a4..47e01ae59bd 100644
--- a/gcc/testsuite/gcc.dg/torture/pr69760.c
+++ b/gcc/testsuite/gcc.dg/torture/pr69760.c
@@ -1,11 +1,10 @@
 /* PR tree-optimization/69760 */
 /* { dg-do run { target { { *-*-linux* *-*-gnu* *-*-uclinux* } && mmap } } }
*/
-/* { dg-options "-O2" } */

 #include <unistd.h>
 #include <sys/mman.h>

-__attribute__((noinline, noclone)) void
+__attribute__((noinline, noclone)) static void
 test_func (double *a, int L, int m, int n, int N)
 {
   int i, k;

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

* [Bug tree-optimization/102659] -O2 vectorization if-conversion produces wrong code for gcc.dg/torture/pr69760.c
  2021-10-09  4:54 [Bug debug/102659] New: [false diagnosis] extra warning info after O2 vectorization for gcc.dg/torture/pr69760.c crazylht at gmail dot com
  2021-10-11  8:55 ` [Bug tree-optimization/102659] -O2 vectorization if-conversion produces wrong code " rguenth at gcc dot gnu.org
  2021-10-11  8:57 ` rguenth at gcc dot gnu.org
@ 2021-10-11  8:58 ` rguenth at gcc dot gnu.org
  2021-10-11 10:31 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-11  8:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
I will have a look.

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

* [Bug tree-optimization/102659] -O2 vectorization if-conversion produces wrong code for gcc.dg/torture/pr69760.c
  2021-10-09  4:54 [Bug debug/102659] New: [false diagnosis] extra warning info after O2 vectorization for gcc.dg/torture/pr69760.c crazylht at gmail dot com
                   ` (2 preceding siblings ...)
  2021-10-11  8:58 ` rguenth at gcc dot gnu.org
@ 2021-10-11 10:31 ` rguenth at gcc dot gnu.org
  2021-10-13 11:11 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-11 10:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Created attachment 51584
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51584&action=edit
patch I am testing

I'm testing this patch, hopefully without bad side-effects on SCEV/data-ref
analysis ... (but I fear not...)

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

* [Bug tree-optimization/102659] -O2 vectorization if-conversion produces wrong code for gcc.dg/torture/pr69760.c
  2021-10-09  4:54 [Bug debug/102659] New: [false diagnosis] extra warning info after O2 vectorization for gcc.dg/torture/pr69760.c crazylht at gmail dot com
                   ` (3 preceding siblings ...)
  2021-10-11 10:31 ` rguenth at gcc dot gnu.org
@ 2021-10-13 11:11 ` cvs-commit at gcc dot gnu.org
  2021-10-13 11:12 ` rguenth at gcc dot gnu.org
  2021-10-14 12:58 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-13 11:11 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:3c0194d7ff21d61c02f3c6b111c83ef24a69e1f0

commit r12-4369-g3c0194d7ff21d61c02f3c6b111c83ef24a69e1f0
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Oct 11 12:27:10 2021 +0200

    tree-optimization/102659 - avoid undefined overflow after if-conversion

    The following makes sure to rewrite arithmetic with undefined behavior
    on overflow to a well-defined variant when moving them to be always
    executed as part of doing if-conversion for loop vectorization.

    2021-10-11  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/102659
            * tree-if-conv.c (need_to_rewrite_undefined): New flag.
            (if_convertible_gimple_assign_stmt_p): Mark the loop for
            rewrite when stmts with undefined behavior on integer
            overflow appear.
            (combine_blocks): Predicate also when we need to rewrite stmts.
            (predicate_statements): Rewrite affected stmts to something
            with well-defined behavior on overflow.
            (tree_if_conversion): Initialize need_to_rewrite_undefined.

            * gcc.dg/torture/pr69760.c: Adjust the testcase.
            * gcc.target/i386/avx2-vect-mask-store-move1.c: Expect to move
            the conversions to unsigned as well.

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

* [Bug tree-optimization/102659] -O2 vectorization if-conversion produces wrong code for gcc.dg/torture/pr69760.c
  2021-10-09  4:54 [Bug debug/102659] New: [false diagnosis] extra warning info after O2 vectorization for gcc.dg/torture/pr69760.c crazylht at gmail dot com
                   ` (4 preceding siblings ...)
  2021-10-13 11:11 ` cvs-commit at gcc dot gnu.org
@ 2021-10-13 11:12 ` rguenth at gcc dot gnu.org
  2021-10-14 12:58 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-13 11:12 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
      Known to work|                            |12.0
         Resolution|---                         |FIXED

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed on trunk, not planning to backport at this point (we've not run into this
in the wild).

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

* [Bug tree-optimization/102659] -O2 vectorization if-conversion produces wrong code for gcc.dg/torture/pr69760.c
  2021-10-09  4:54 [Bug debug/102659] New: [false diagnosis] extra warning info after O2 vectorization for gcc.dg/torture/pr69760.c crazylht at gmail dot com
                   ` (5 preceding siblings ...)
  2021-10-13 11:12 ` rguenth at gcc dot gnu.org
@ 2021-10-14 12:58 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-14 12:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:9b2ad21ab3ebc21a3408108327fa1a7cbedaf217

commit r12-4398-g9b2ad21ab3ebc21a3408108327fa1a7cbedaf217
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Oct 14 09:00:25 2021 +0200

    tree-optimization/102659 - really avoid undef overflow in if-conversion

    This plugs the remaining hole of POINTER_PLUS_EXPR with undefined
    overflow.  Unfortunately we have to go through some lengths to
    not put invariant conversions into the loop body since that confuses
    the vectorizers gather/scatter discovery which relies on identifying
    an invariant component of plus and minus expressions.  We can
    emit those in the loop preheader but then we have to accept that
    being non-empty when looking for the LOOP_VECTORIZED internal
    function call in the vectorizer.

    2021-10-14  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/102659
            * tree-if-conv.c (if_convertible_gimple_assign_stmt_p): Also
            rewrite pointer typed undefined overflow operations.
            (predicate_statements): Likewise.  Make sure to emit invariant
            conversions in the preheader.
            * tree-vectorizer.c (vect_loop_vectorized_call): Look through
            non-empty preheaders.
            * tree-data-ref.c (dr_analyze_indices): Strip useless
            conversions to the MEM_REF base type.

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

end of thread, other threads:[~2021-10-14 12:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-09  4:54 [Bug debug/102659] New: [false diagnosis] extra warning info after O2 vectorization for gcc.dg/torture/pr69760.c crazylht at gmail dot com
2021-10-11  8:55 ` [Bug tree-optimization/102659] -O2 vectorization if-conversion produces wrong code " rguenth at gcc dot gnu.org
2021-10-11  8:57 ` rguenth at gcc dot gnu.org
2021-10-11  8:58 ` rguenth at gcc dot gnu.org
2021-10-11 10:31 ` rguenth at gcc dot gnu.org
2021-10-13 11:11 ` cvs-commit at gcc dot gnu.org
2021-10-13 11:12 ` rguenth at gcc dot gnu.org
2021-10-14 12:58 ` cvs-commit 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).