[Bug middle-end/66867] Suboptimal code generation for atomic_compare_exchange

2016-07-18 Thread dhowells at redhat dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66867

--- Comment #11 from dhowells at redhat dot com  ---
I applied the patch to the Fedora cross-gcc-6.1.1 rpm with one minor fixup. 
Using the example code I added in bug 70825 I now see:

 :
   0:   ba 2a 00 00 00  mov$0x2a,%edx
   5:   b8 17 00 00 00  mov$0x17,%eax
   a:   f0 0f b1 17 lock cmpxchg %edx,(%rdi)
   e:   c3  retq   

there's now no extraneous store before the locked instruction.  And:

000f :
   f:   ba 2a 00 00 00  mov$0x2a,%edx
  14:   b8 17 00 00 00  mov$0x17,%eax
  19:   f0 0f b1 17 lock cmpxchg %edx,(%rdi)
  1d:   c3  retq   

it now just passes the return value of cmpxchg back directly without
potentially putting on and off the stack and maybe jumping round that bit. 
And:

0043 :
  43:   ba 2a 00 00 00  mov$0x2a,%edx
  48:   b8 17 00 00 00  mov$0x17,%eax
  4d:   f0 0f b1 17 lock cmpxchg %edx,(%rdi)
  51:   c3  retq   

where it makes no difference changing how the the return-statements are
contructed in C.

I've also booted a kernel built with the patched compiler.

[Bug middle-end/66867] Suboptimal code generation for atomic_compare_exchange

2016-06-28 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66867

Jakub Jelinek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #10 from Jakub Jelinek  ---
Hopefully fixed for 7+.

[Bug middle-end/66867] Suboptimal code generation for atomic_compare_exchange

2016-06-28 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66867

--- Comment #9 from Jakub Jelinek  ---
Author: jakub
Date: Tue Jun 28 08:27:18 2016
New Revision: 237814

URL: https://gcc.gnu.org/viewcvs?rev=237814&root=gcc&view=rev
Log:
PR middle-end/66867
* builtins.c (expand_ifn_atomic_compare_exchange_into_call,
expand_ifn_atomic_compare_exchange): New functions.
* internal-fn.c (expand_ATOMIC_COMPARE_EXCHANGE): New function.
* tree.h (build_call_expr_internal_loc): Rename to ...
(build_call_expr_internal_loc_array): ... this.  Fix up type of
last argument.
* internal-fn.def (ATOMIC_COMPARE_EXCHANGE): New internal fn.
* predict.c (expr_expected_value_1): Handle IMAGPART_EXPR of
ATOMIC_COMPARE_EXCHANGE result.
* builtins.h (expand_ifn_atomic_compare_exchange): New prototype.
* gimple-fold.h (optimize_atomic_compare_exchange_p,
fold_builtin_atomic_compare_exchange): New prototypes.
* gimple-fold.c (optimize_atomic_compare_exchange_p,
fold_builtin_atomic_compare_exchange): New functions..
* tree-ssa.c (execute_update_addresses_taken): If
optimize_atomic_compare_exchange_p, ignore &var in 2nd argument
of call when finding addressable vars, and if such var becomes
non-addressable, call fold_builtin_atomic_compare_exchange.

Modified:
trunk/gcc/ChangeLog
trunk/gcc/builtins.c
trunk/gcc/builtins.h
trunk/gcc/gimple-fold.c
trunk/gcc/gimple-fold.h
trunk/gcc/internal-fn.c
trunk/gcc/internal-fn.def
trunk/gcc/predict.c
trunk/gcc/tree-ssa.c
trunk/gcc/tree.h

[Bug middle-end/66867] Suboptimal code generation for atomic_compare_exchange

2016-06-22 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66867

Jakub Jelinek  changed:

   What|Removed |Added

  Attachment #38740|0   |1
is obsolete||
 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org

--- Comment #8 from Jakub Jelinek  ---
Created attachment 38749
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38749&action=edit
gcc7-pr66867.patch

Patch I'm going to bootstrap/regtest.

[Bug middle-end/66867] Suboptimal code generation for atomic_compare_exchange

2016-06-21 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66867

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #7 from Jakub Jelinek  ---
Created attachment 38740
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38740&action=edit
gcc7-pr66867-wip.patch

WIP untested patch using the same technique as we use for __builtin_*_overflow*
builtins.  I'll need to still finish writing the expansion for the case when we
should expand it to external calls, once that is tested disable the ifn folding
for !flag_inline_atomics, fix up -fsanitize=threads, use for other spots that
look at atomic builtins.
And, we need some optimization that would optimize the case where REALPART_EXPR
is conditionally stored into a non-addressable var - we can store the oldval
there unconditionally then, because it can't create a race.

[Bug middle-end/66867] Suboptimal code generation for atomic_compare_exchange

2016-06-20 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66867

Andrew Pinski  changed:

   What|Removed |Added

 CC||tkoeppe at google dot com

--- Comment #5 from Andrew Pinski  ---
*** Bug 66713 has been marked as a duplicate of this bug. ***

[Bug middle-end/66867] Suboptimal code generation for atomic_compare_exchange

2016-06-20 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66867

Andrew Pinski  changed:

   What|Removed |Added

 CC||dhowells at redhat dot com

--- Comment #4 from Andrew Pinski  ---
*** Bug 70825 has been marked as a duplicate of this bug. ***

[Bug middle-end/66867] Suboptimal code generation for atomic_compare_exchange

2016-06-20 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66867

Andrew Pinski  changed:

   What|Removed |Added

 CC||jianjin2016 at fb dot com

--- Comment #6 from Andrew Pinski  ---
*** Bug 71599 has been marked as a duplicate of this bug. ***