public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/60482] New: Loop optimization regression
@ 2014-03-10 12:10 yvan.roux at linaro dot org
  2014-03-10 14:29 ` [Bug middle-end/60482] " jakub at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: yvan.roux at linaro dot org @ 2014-03-10 12:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60482

            Bug ID: 60482
           Summary: Loop optimization regression
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yvan.roux at linaro dot org

Created attachment 32323
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32323&action=edit
trunk.s

Hi,

I didn't had time to investigate further, but I want to raise quickly that the
code bellow was optimized at r204283 by taking into account the trip count
information of the loop and is not with the trunk (I spotted the issue on
AArch64 and x86_64).

code:

typedef double adouble __attribute__ ((__aligned__(16)));

double p1(adouble *x, int n)
{
  double p1_ = 0.0;

  (!(n % 128) == 0) ? __builtin_unreachable() : 1 ;

  for (int i=0; i<n; i++)
    p1_ += x[i] ;
  return p1_ ;
}

compiled with flags : -Ofast -std=c99

x86_64 generated assembly at r204283:

p1:
.LFB0:
        .cfi_startproc
        testl   %esi, %esi
        jle     .L5
        pxor    %xmm1, %xmm1
        shrl    %esi
        xorl    %eax, %eax
.L4:
        movq    %rax, %rdx
        addq    $1, %rax
        salq    $4, %rdx
        cmpl    %eax, %esi
        addpd   (%rdi,%rdx), %xmm1
        ja      .L4
        movapd  %xmm1, %xmm0
        unpckhpd        %xmm1, %xmm1
        addsd   %xmm1, %xmm0
        ret
        .p2align 4,,10
        .p2align 3
.L5:
        pxor    %xmm0, %xmm0
        ret
        .cfi_endproc


X86_64 trunk generated assembly is attached.

Thanks,
Yvan


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

* [Bug middle-end/60482] Loop optimization regression
  2014-03-10 12:10 [Bug middle-end/60482] New: Loop optimization regression yvan.roux at linaro dot org
@ 2014-03-10 14:29 ` jakub at gcc dot gnu.org
  2014-03-10 17:31 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-03-10 14:29 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60482

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

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 32325
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32325&action=edit
gcc49-pr60482.patch

Untested fix.  Apparently the problem is that we add an ASSERT_EXPR right
before the __builtin_unreachable, even when it obviously isn't needed there.
The comment talks about pre-4.4 FOUND_IN_SUBGRAPH stuff, at least right now
with live_on_edge that function returns false in this case.


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

* [Bug middle-end/60482] Loop optimization regression
  2014-03-10 12:10 [Bug middle-end/60482] New: Loop optimization regression yvan.roux at linaro dot org
  2014-03-10 14:29 ` [Bug middle-end/60482] " jakub at gcc dot gnu.org
@ 2014-03-10 17:31 ` jakub at gcc dot gnu.org
  2014-03-11  9:18 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-03-10 17:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60482

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

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The patch regresses the tree-ssa/ssa-ifcombine-10.c testcase, but that to me
just looks as tree-ssa-ifcombine.c being not enough flexible.  The difference
starting with VRP1 without -> with the patch is just:
@@ -27,14 +27,14 @@ f (int x, int a, int b)
   <bb 3>:
   _5 = x_3(D) & 4;
   if (_5 != 0)
-    goto <bb 4>;
-  else
     goto <bb 5>;
+  else
+    goto <bb 4>;

   <bb 4>:

   <bb 5>:
-  # t_1 = PHI <0(2), 3(4), 0(3)>
+  # t_1 = PHI <0(2), 3(3), 0(4)>
   return t_1;

which I'd say is quite unimportant difference ifcombine shouldn't care about,
but apparently it does.


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

* [Bug middle-end/60482] Loop optimization regression
  2014-03-10 12:10 [Bug middle-end/60482] New: Loop optimization regression yvan.roux at linaro dot org
  2014-03-10 14:29 ` [Bug middle-end/60482] " jakub at gcc dot gnu.org
  2014-03-10 17:31 ` jakub at gcc dot gnu.org
@ 2014-03-11  9:18 ` jakub at gcc dot gnu.org
  2014-03-12  9:15 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-03-11  9:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60482

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 32332
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32332&action=edit
gcc49-pr60482-2.patch

Untested fix for the ssa-ifcombine-10.c regression.  It seems that previously,
with a useless ASSERT_EXPR:
  <bb 2>:
  _4 = x_3(D) & 1;
  if (_4 == 0)
    goto <bb 5>;
  else
    goto <bb 3>;

  <bb 3>:
  x_8 = ASSERT_EXPR <x_3(D), (unsigned int) x_3(D) + 4294967295 <= 4294967294>;
  x_9 = ASSERT_EXPR <x_8, x_8 != 0>;
  _5 = x_9 & 4;
  if (_5 != 0)
    goto <bb 6>;
  else
    goto <bb 4>;

  <bb 6>:
  x_7 = ASSERT_EXPR <x_9, x_9 != 0>;
  goto <bb 5>;

  <bb 4>:

  <bb 5>:
  # t_1 = PHI <0(2), 3(6), 0(4)>
  return t_1;
(the x_7 one) VRP had to create a new bb for it and while it has been removed
afterwards, it ended up swapping the basic blocks in the second condition,
from:
  <bb 3>:
  _5 = x_3(D) & 4;
  if (_5 != 0)
    goto <bb 5>;
  else
    goto <bb 4>;

  <bb 4>:

  <bb 5>:
  # t_1 = PHI <0(2), 3(3), 0(4)>
to:
  <bb 3>:
  _5 = x_3(D) & 4;
  if (_5 != 0)
    goto <bb 4>;
  else
    goto <bb 5>;

  <bb 4>:

  <bb 5>:
  # t_1 = PHI <0(2), 3(4), 0(3)>
E.g. with -fno-tree-vrp, ssa-ifcombine-10.c fails already on vanilla trunk.

The attached untested patch should handle this situation.


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

* [Bug middle-end/60482] Loop optimization regression
  2014-03-10 12:10 [Bug middle-end/60482] New: Loop optimization regression yvan.roux at linaro dot org
                   ` (2 preceding siblings ...)
  2014-03-11  9:18 ` jakub at gcc dot gnu.org
@ 2014-03-12  9:15 ` jakub at gcc dot gnu.org
  2014-03-12 10:18 ` jakub at gcc dot gnu.org
  2014-03-12 10:50 ` yvan.roux at linaro dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-03-12  9:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60482

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Wed Mar 12 09:15:08 2014
New Revision: 208506

URL: http://gcc.gnu.org/viewcvs?rev=208506&root=gcc&view=rev
Log:
    PR middle-end/60482
    * tree-vrp.c (register_edge_assert_for_1): Don't add assert
    if there are multiple uses, but op doesn't live on E edge.
    * tree-cfg.c (assert_unreachable_fallthru_edge_p): Also ignore
    clobber stmts before __builtin_unreachable.

    * gcc.dg/vect/pr60482.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/vect/pr60482.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-cfg.c
    trunk/gcc/tree-vrp.c


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

* [Bug middle-end/60482] Loop optimization regression
  2014-03-10 12:10 [Bug middle-end/60482] New: Loop optimization regression yvan.roux at linaro dot org
                   ` (3 preceding siblings ...)
  2014-03-12  9:15 ` jakub at gcc dot gnu.org
@ 2014-03-12 10:18 ` jakub at gcc dot gnu.org
  2014-03-12 10:50 ` yvan.roux at linaro dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-03-12 10:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60482

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

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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.


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

* [Bug middle-end/60482] Loop optimization regression
  2014-03-10 12:10 [Bug middle-end/60482] New: Loop optimization regression yvan.roux at linaro dot org
                   ` (4 preceding siblings ...)
  2014-03-12 10:18 ` jakub at gcc dot gnu.org
@ 2014-03-12 10:50 ` yvan.roux at linaro dot org
  5 siblings, 0 replies; 7+ messages in thread
From: yvan.roux at linaro dot org @ 2014-03-12 10:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60482

--- Comment #7 from Yvan Roux <yvan.roux at linaro dot org> ---
Thanks for the quick fix Jakub.


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

end of thread, other threads:[~2014-03-12 10:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-10 12:10 [Bug middle-end/60482] New: Loop optimization regression yvan.roux at linaro dot org
2014-03-10 14:29 ` [Bug middle-end/60482] " jakub at gcc dot gnu.org
2014-03-10 17:31 ` jakub at gcc dot gnu.org
2014-03-11  9:18 ` jakub at gcc dot gnu.org
2014-03-12  9:15 ` jakub at gcc dot gnu.org
2014-03-12 10:18 ` jakub at gcc dot gnu.org
2014-03-12 10:50 ` yvan.roux at linaro dot 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).