public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ipa/99776] New: missed optimization for dead code elimination at -O3 (vs. -O1)
@ 2021-03-25 21:35 zhendong.su at inf dot ethz.ch
  2021-03-26  8:31 ` [Bug tree-optimization/99776] " rguenth at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2021-03-25 21:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99776
           Summary: missed optimization for dead code elimination at -O3
                    (vs. -O1)
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhendong.su at inf dot ethz.ch
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

[687] % gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/local/suz-local/software/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/11.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --disable-bootstrap
--prefix=/local/suz-local/software/local/gcc-trunk --enable-languages=c,c++
--disable-werror --enable-multilib --with-system-zlib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.1 20210325 (experimental) [master revision
08103e4d6ad:4e4f8ee0bf5:a29124d28253cdf603ba1977db2f09c9f233fea5] (GCC) 
[688] % 
[688] % gcctk -O1 -S -o small_O1.s small.c
[689] % gcctk -O3 -S -o small_O3.s small.c
[690] % 
[690] % wc small_O1.s small_O3.s 
  23   52  455 small_O1.s
  37   82  682 small_O3.s
  60  134 1137 total
[691] % 
[691] % grep foo small_O1.s 
[692] % grep foo small_O3.s 
        call    foo
[693] % 
[693] % cat small.c
extern void foo(void);

static int a[2], b, *c[2];

int main() {
  for (b = 0; b < 2; b++)
    c[b] = &a[1];
  if (!c[0])
    foo();
  return 0;
}

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

* [Bug tree-optimization/99776] missed optimization for dead code elimination at -O3 (vs. -O1)
  2021-03-25 21:35 [Bug ipa/99776] New: missed optimization for dead code elimination at -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
@ 2021-03-26  8:31 ` rguenth at gcc dot gnu.org
  2021-03-26  8:47 ` 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-03-26  8:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-03-26
           Keywords|                            |missed-optimization
            Version|unknown                     |11.0
          Component|ipa                         |tree-optimization
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  At -O3 we're vectorizing the loop to

  _10 = (long unsigned int) &a[1];
  vect_cst__4 = {_10, _10};
  MEM <vector(2) long unsigned int> [(int * *)&c] = vect_cst__4;
  vectp_c.8_16 = &c + 16;
  ivtmp_19 = 1;
  b = 2;
  _3 = c[0];
  if (_3 == 0B)
    goto <bb 5>; [17.43%]
  else
    goto <bb 6>; [82.57%]

  <bb 5> [local count: 20586852]:
  foo ();

which FRE optimizes only to

  _10 = (long unsigned int) &a[1];
  vect_cst__4 = {_10, _10};
  MEM <vector(2) long unsigned int> [(int * *)&c] = vect_cst__4;
  b = 2;
  _11 = BIT_FIELD_REF <vect_cst__4, 64, 0>;
  if (_11 == 0B)

failing to resolve the bit-field-ref.  This looks like a missed match.pd
case.

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

* [Bug tree-optimization/99776] missed optimization for dead code elimination at -O3 (vs. -O1)
  2021-03-25 21:35 [Bug ipa/99776] New: missed optimization for dead code elimination at -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
  2021-03-26  8:31 ` [Bug tree-optimization/99776] " rguenth at gcc dot gnu.org
@ 2021-03-26  8:47 ` rguenth at gcc dot gnu.org
  2021-03-26  9:10 ` zhendong.su at inf dot ethz.ch
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-03-26  8:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
diff --git a/gcc/match.pd b/gcc/match.pd
index 036f92fa959..61c93b5edd1 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6168,9 +6168,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 (simplify
  (BIT_FIELD_REF CONSTRUCTOR@0 @1 @2)
  (if (VECTOR_TYPE_P (TREE_TYPE (@0))
-      && (types_match (type, TREE_TYPE (TREE_TYPE (@0)))
+      && tree_fits_uhwi_p (TYPE_SIZE (type))
+      && ((tree_to_uhwi (TYPE_SIZE (type))
+          == tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (@0)))))
           || (VECTOR_TYPE_P (type)
-             && types_match (TREE_TYPE (type), TREE_TYPE (TREE_TYPE (@0))))))
+             && (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (type)))
+                 == tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (@0))))))))
   (with
    {
      tree ctor = (TREE_CODE (@0) == SSA_NAME

works to fix the testcase.  The issue is that we vectorize pointer data
as unsigned long and the type mismatch prevents the folding.  With the above
FRE4 produces

  <bb 2> [local count: 118111601]:
  _10 = (long unsigned int) &a[1];
  vect_cst__4 = {_10, _10};
  MEM <vector(2) long unsigned int> [(int * *)&c] = vect_cst__4;
  b = 2;
  return 0;

as desired.  Queued for GCC 12.

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

* [Bug tree-optimization/99776] missed optimization for dead code elimination at -O3 (vs. -O1)
  2021-03-25 21:35 [Bug ipa/99776] New: missed optimization for dead code elimination at -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
  2021-03-26  8:31 ` [Bug tree-optimization/99776] " rguenth at gcc dot gnu.org
  2021-03-26  8:47 ` rguenth at gcc dot gnu.org
@ 2021-03-26  9:10 ` zhendong.su at inf dot ethz.ch
  2021-04-13  7:35 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2021-03-26  9:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Zhendong Su <zhendong.su at inf dot ethz.ch> ---
Awesome!  Thanks for looking into this so quickly, Richard!

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

* [Bug tree-optimization/99776] missed optimization for dead code elimination at -O3 (vs. -O1)
  2021-03-25 21:35 [Bug ipa/99776] New: missed optimization for dead code elimination at -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2021-03-26  9:10 ` zhendong.su at inf dot ethz.ch
@ 2021-04-13  7:35 ` rguenth at gcc dot gnu.org
  2021-04-27  7:16 ` 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-04-13  7:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
*** Bug 100050 has been marked as a duplicate of this bug. ***

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

* [Bug tree-optimization/99776] missed optimization for dead code elimination at -O3 (vs. -O1)
  2021-03-25 21:35 [Bug ipa/99776] New: missed optimization for dead code elimination at -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2021-04-13  7:35 ` rguenth at gcc dot gnu.org
@ 2021-04-27  7:16 ` cvs-commit at gcc dot gnu.org
  2021-04-27  7:17 ` rguenth at gcc dot gnu.org
  2021-05-04 12:29 ` rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-27  7:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- 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:7d6bb80931b429631f63e0fd27bee95f32eb57a9

commit r12-139-g7d6bb80931b429631f63e0fd27bee95f32eb57a9
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Mar 26 09:50:03 2021 +0100

    tree-optimization/99776 - relax condition on vector ctor element extract

    This relaxes the condition for the match.pd pattern doing vector ctor
    element extracts to not require type identity but only size equality.
    Since we vectorize pointer data as unsigned integer data such mismatches
    have to be tolerated to optimize scalar code uses of vector results.

    2021-03-26  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/99776
            * match.pd (bit_field_ref (ctor)): Relax element extract
            type compatibility checks.

            * gcc.dg/tree-ssa/ssa-fre-91.c: New testcase.

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

* [Bug tree-optimization/99776] missed optimization for dead code elimination at -O3 (vs. -O1)
  2021-03-25 21:35 [Bug ipa/99776] New: missed optimization for dead code elimination at -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
                   ` (4 preceding siblings ...)
  2021-04-27  7:16 ` cvs-commit at gcc dot gnu.org
@ 2021-04-27  7:17 ` rguenth at gcc dot gnu.org
  2021-05-04 12:29 ` rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-04-27  7:17 UTC (permalink / raw)
  To: gcc-bugs

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

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 for GCC 12.

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

* [Bug tree-optimization/99776] missed optimization for dead code elimination at -O3 (vs. -O1)
  2021-03-25 21:35 [Bug ipa/99776] New: missed optimization for dead code elimination at -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
                   ` (5 preceding siblings ...)
  2021-04-27  7:17 ` rguenth at gcc dot gnu.org
@ 2021-05-04 12:29 ` rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-05-04 12:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
*** Bug 99986 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2021-05-04 12:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-25 21:35 [Bug ipa/99776] New: missed optimization for dead code elimination at -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
2021-03-26  8:31 ` [Bug tree-optimization/99776] " rguenth at gcc dot gnu.org
2021-03-26  8:47 ` rguenth at gcc dot gnu.org
2021-03-26  9:10 ` zhendong.su at inf dot ethz.ch
2021-04-13  7:35 ` rguenth at gcc dot gnu.org
2021-04-27  7:16 ` cvs-commit at gcc dot gnu.org
2021-04-27  7:17 ` rguenth at gcc dot gnu.org
2021-05-04 12:29 ` rguenth 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).