public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/102383] New: Missing optimization for PRE after enable O2 vectorization
@ 2021-09-17  2:35 crazylht at gmail dot com
  2021-09-17  3:15 ` [Bug tree-optimization/102383] " crazylht at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: crazylht at gmail dot com @ 2021-09-17  2:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102383
           Summary: Missing optimization for PRE after enable O2
                    vectorization
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          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-*-*

testcase is form gcc.dg/tree-ssa/predcom-1.c

void abort (void);

unsigned fib[1000];

__attribute__ ((noinline))
void count_fib(void)
{
  int i;

  fib[0] = 0;
  fib[1] = 1;
  for (i = 2; i < 1000; i++)
    fib[i] = (fib[i-1] + fib[i - 2]) & 0xffff;
}

git diff novectorize vectorize dump

diff --git a/../novectorize/predcom-1.c.248t.optimized
b/./predcom-1.c.248t.optimized
index 9e4783d..7846af6 100644
--- a/../novectorize/predcom-1.c.248t.optimized
+++ b/./predcom-1.c.248t.optimized
@@ -5,53 +5,57 @@ Removing basic block 5
 __attribute__((noinline))
 void count_fib ()
 {
-  sizetype ivtmp.13;
+  sizetype ivtmp.16;
+  unsigned int fib_I_lsm1.6;
   unsigned int fib_I_lsm0.5;
   int i;
-  unsigned int _2;
-  unsigned int _4;
   unsigned int _5;
   unsigned int _6;
-  unsigned int prephitmp_21;
-  unsigned int prephitmp_24;
-  unsigned int _41;
+  unsigned int _19;
+  unsigned int _20;
+  unsigned int _21;
+  unsigned int _37;
+  int _38;
+  unsigned int _46;
   unsigned int _47;
-  unsigned int _48;
-  unsigned int _59;
-  int _65;
-  unsigned int pretmp_66;
+  int _54;
+  unsigned int _55;
+  unsigned int _56;
+  unsigned int _57;

   <bb 2> [local count: 10737416]:
-  MEM <unsigned long> [(unsigned int *)&fib] = 4294967296;
+  MEM <vector(2) unsigned int> [(unsigned int *)&fib] = { 0, 1 };

   <bb 3> [local count: 10737417]:
-  # prephitmp_21 = PHI <1(2), _48(3)>
-  # prephitmp_24 = PHI <0(2), _6(3)>
-  # fib_I_lsm0.5_38 = PHI <1(2), _48(3)>
-  # ivtmp.13_7 = PHI <4(2), ivtmp.13_8(3)>
-  _5 = prephitmp_21 + prephitmp_24;
+  # fib_I_lsm0.5_32 = PHI <0(2), _6(3)>
+  # fib_I_lsm1.6_33 = PHI <1(2), _47(3)>
+  # ivtmp.16_11 = PHI <4(2), ivtmp.16_10(3)>
+  _5 = fib_I_lsm0.5_32 + fib_I_lsm1.6_33;
   _6 = _5 & 65535;
-  MEM[(unsigned int *)&fib + -8B + ivtmp.13_7 * 4] = _6;
-  _47 = _6 + fib_I_lsm0.5_38;
-  _48 = _47 & 65535;
-  MEM[(unsigned int *)&fib + -4B + ivtmp.13_7 * 4] = _48;
-  ivtmp.13_8 = ivtmp.13_7 + 2;
-  if (ivtmp.13_8 != 1000)
+  MEM[(unsigned int *)&fib + -8B + ivtmp.16_11 * 4] = _6;
+  _46 = _6 + fib_I_lsm1.6_33;
+  _47 = _46 & 65535;
+  MEM[(unsigned int *)&fib + -4B + ivtmp.16_11 * 4] = _47;
+  ivtmp.16_10 = ivtmp.16_11 + 2;
+  if (ivtmp.16_10 != 1000)
     goto <bb 3>; [98.00%]
   else
     goto <bb 4>; [2.00%]

   <bb 4> [local count: 10737416]:
-  i_51 = (int) ivtmp.13_7;
-  _41 = _6 + _48;
-  _59 = _41 & 65535;
-  fib[i_51] = _59;
-  i_61 = i_51 + 1;
-  _65 = i_51 + -1;
-  pretmp_66 = fib[_65];
-  _2 = _59 + pretmp_66;
-  _4 = _2 & 65535;
-  fib[i_61] = _4;
+  i_50 = (int) ivtmp.16_11;
+  _38 = i_50 + -1;
+  _37 = fib[_38]; ----- missing optimization here
+  _54 = i_50 + -2;
+  _55 = fib[_54]; ----- and here.
+  _56 = _37 + _55;
+  _57 = _56 & 65535;
+  fib[i_50] = _57;
+  i_59 = i_50 + 1;
+  _19 = fib[_38];
+  _20 = _19 + _57;
+  _21 = _20 & 65535;
+  fib[i_59] = _21;
   return;

 }

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

end of thread, other threads:[~2023-11-02 13:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-17  2:35 [Bug tree-optimization/102383] New: Missing optimization for PRE after enable O2 vectorization crazylht at gmail dot com
2021-09-17  3:15 ` [Bug tree-optimization/102383] " crazylht at gmail dot com
2021-09-17  7:06 ` rguenth at gcc dot gnu.org
2021-09-17  7:56 ` crazylht at gmail dot com
2021-09-17  8:12 ` linkw at gcc dot gnu.org
2023-11-01  4:10 ` crazylht at gmail dot com
2023-11-02 13:20 ` 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).