From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: rth@redhat.com (Richard Henderson)
Cc: gcc-patches@gcc.gnu.org
Subject: Re: s390: Avoid CAS boolean output inefficiency
Date: Wed, 08 Aug 2012 18:05:00 -0000 [thread overview]
Message-ID: <201208081805.q78I5B97009459@d06av02.portsmouth.uk.ibm.com> (raw)
In-Reply-To: <50219309.5000403@redhat.com> from "Richard Henderson" at Aug 07, 2012 03:13:29 PM
Richard Henderson wrote:
> On 08/07/2012 10:02 AM, Ulrich Weigand wrote:
> > The following patch changes the builtin expander to pass a MEM oldval
> > as-is to the back-end expander, so that the back-end can move the
> > store to before the CC operation. With that patch I'm also seeing
> > all the IPMs disappear.
> ...
> > What do you think about this solution? It has the advantage that
> > we still get the same xor code if we actually do need the ipm ...
>
> I'm ok with that patch.
Thanks! I've checked in the following version.
Tested on s390x-ibm-linux with no regressions.
Bye,
Ulrich
ChangeLog:
* builtins.c (expand_builtin_atomic_compare_exchange): Pass old
value operand as MEM to expand_atomic_compare_and_swap.
* config/s390/s390.md ("atomic_compare_and_swap<mode>"): Accept
nonimmediate_operand for old value; generate load and store if
needed.
* config/s390/s390.c (s390_expand_cs_hqi): Accept any operand
as vtarget.
Index: gcc/builtins.c
===================================================================
*** gcc/builtins.c (revision 190226)
--- gcc/builtins.c (working copy)
*************** expand_builtin_atomic_compare_exchange (
*** 5376,5381 ****
--- 5376,5382 ----
expect = expand_normal (CALL_EXPR_ARG (exp, 1));
expect = convert_memory_address (Pmode, expect);
+ expect = gen_rtx_MEM (mode, expect);
desired = expand_expr_force_mode (CALL_EXPR_ARG (exp, 2), mode);
weak = CALL_EXPR_ARG (exp, 3);
*************** expand_builtin_atomic_compare_exchange (
*** 5383,5396 ****
if (host_integerp (weak, 0) && tree_low_cst (weak, 0) != 0)
is_weak = true;
! oldval = copy_to_reg (gen_rtx_MEM (mode, expect));
!
if (!expand_atomic_compare_and_swap ((target == const0_rtx ? NULL : &target),
&oldval, mem, oldval, desired,
is_weak, success, failure))
return NULL_RTX;
! emit_move_insn (gen_rtx_MEM (mode, expect), oldval);
return target;
}
--- 5384,5398 ----
if (host_integerp (weak, 0) && tree_low_cst (weak, 0) != 0)
is_weak = true;
! oldval = expect;
if (!expand_atomic_compare_and_swap ((target == const0_rtx ? NULL : &target),
&oldval, mem, oldval, desired,
is_weak, success, failure))
return NULL_RTX;
! if (oldval != expect)
! emit_move_insn (expect, oldval);
!
return target;
}
Index: gcc/config/s390/s390.c
===================================================================
*** gcc/config/s390/s390.c (revision 190226)
--- gcc/config/s390/s390.c (working copy)
*************** s390_expand_cs_hqi (enum machine_mode mo
*** 4825,4831 ****
rtx res = gen_reg_rtx (SImode);
rtx csloop = NULL, csend = NULL;
- gcc_assert (register_operand (vtarget, VOIDmode));
gcc_assert (MEM_P (mem));
init_alignment_context (&ac, mem, mode);
--- 4825,4830 ----
Index: gcc/config/s390/s390.md
===================================================================
*** gcc/config/s390/s390.md (revision 190226)
--- gcc/config/s390/s390.md (working copy)
***************
*** 8870,8876 ****
(define_expand "atomic_compare_and_swap<mode>"
[(match_operand:SI 0 "register_operand") ;; bool success output
! (match_operand:DGPR 1 "register_operand") ;; oldval output
(match_operand:DGPR 2 "memory_operand") ;; memory
(match_operand:DGPR 3 "register_operand") ;; expected intput
(match_operand:DGPR 4 "register_operand") ;; newval intput
--- 8870,8876 ----
(define_expand "atomic_compare_and_swap<mode>"
[(match_operand:SI 0 "register_operand") ;; bool success output
! (match_operand:DGPR 1 "nonimmediate_operand");; oldval output
(match_operand:DGPR 2 "memory_operand") ;; memory
(match_operand:DGPR 3 "register_operand") ;; expected intput
(match_operand:DGPR 4 "register_operand") ;; newval intput
***************
*** 8879,8887 ****
(match_operand:SI 7 "const_int_operand")] ;; failure model
""
{
! rtx cc, cmp;
emit_insn (gen_atomic_compare_and_swap<mode>_internal
! (operands[1], operands[2], operands[3], operands[4]));
cc = gen_rtx_REG (CCZ1mode, CC_REGNUM);
cmp = gen_rtx_EQ (SImode, cc, const0_rtx);
emit_insn (gen_cstorecc4 (operands[0], cmp, cc, const0_rtx));
--- 8879,8900 ----
(match_operand:SI 7 "const_int_operand")] ;; failure model
""
{
! rtx cc, cmp, output = operands[1];
!
! if (!register_operand (output, <MODE>mode))
! output = gen_reg_rtx (<MODE>mode);
!
emit_insn (gen_atomic_compare_and_swap<mode>_internal
! (output, operands[2], operands[3], operands[4]));
!
! /* We deliberately accept non-register operands in the predicate
! to ensure the write back to the output operand happens *before*
! the store-flags code below. This makes it easier for combine
! to merge the store-flags code with a potential test-and-branch
! pattern following (immediately!) afterwards. */
! if (output != operands[1])
! emit_move_insn (operands[1], output);
!
cc = gen_rtx_REG (CCZ1mode, CC_REGNUM);
cmp = gen_rtx_EQ (SImode, cc, const0_rtx);
emit_insn (gen_cstorecc4 (operands[0], cmp, cc, const0_rtx));
***************
*** 8890,8896 ****
(define_expand "atomic_compare_and_swap<mode>"
[(match_operand:SI 0 "register_operand") ;; bool success output
! (match_operand:HQI 1 "register_operand") ;; oldval output
(match_operand:HQI 2 "memory_operand") ;; memory
(match_operand:HQI 3 "general_operand") ;; expected intput
(match_operand:HQI 4 "general_operand") ;; newval intput
--- 8903,8909 ----
(define_expand "atomic_compare_and_swap<mode>"
[(match_operand:SI 0 "register_operand") ;; bool success output
! (match_operand:HQI 1 "nonimmediate_operand") ;; oldval output
(match_operand:HQI 2 "memory_operand") ;; memory
(match_operand:HQI 3 "general_operand") ;; expected intput
(match_operand:HQI 4 "general_operand") ;; newval intput
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com
next prev parent reply other threads:[~2012-08-08 18:05 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-29 21:32 [CFT] s390: Convert from sync to atomic optabs Richard Henderson
2012-07-30 14:19 ` Ulrich Weigand
2012-07-30 15:12 ` Richard Henderson
2012-07-30 15:51 ` Ulrich Weigand
2012-07-30 18:53 ` Richard Henderson
2012-07-30 22:33 ` [PATCH 0/2] Convert s390 to atomic optabs, v2 Richard Henderson
2012-07-30 22:33 ` [PATCH 1/2] s390: Reorg s390_expand_insv Richard Henderson
2012-07-30 22:36 ` [PATCH 2/2] s390: Convert from sync to atomic optabs Richard Henderson
2012-08-06 18:34 ` Ulrich Weigand
2012-08-06 18:51 ` Richard Henderson
2012-08-06 19:45 ` Richard Henderson
2012-08-06 22:40 ` s390: Avoid CAS boolean output inefficiency Richard Henderson
2012-08-07 17:02 ` Ulrich Weigand
2012-08-07 22:13 ` Richard Henderson
2012-08-08 18:05 ` Ulrich Weigand [this message]
2012-08-09 16:55 ` Eric Botcazou
2012-07-31 9:11 ` [PATCH 0/2] Convert s390 to atomic optabs, v2 Richard Guenther
2012-07-31 15:27 ` Andrew MacLeod
2012-07-31 16:07 ` Richard Henderson
2012-08-01 8:41 ` Richard Guenther
2012-08-01 15:59 ` Richard Henderson
2012-08-01 17:14 ` Richard Guenther
2012-08-01 19:42 ` Richard Henderson
2012-07-31 18:36 ` Ulrich Weigand
2012-07-31 19:54 ` Richard Henderson
2012-08-01 23:23 ` Richard Henderson
2012-08-03 12:20 ` Ulrich Weigand
2012-08-03 14:21 ` Ulrich Weigand
2012-08-06 16:44 ` Ulrich Weigand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201208081805.q78I5B97009459@d06av02.portsmouth.uk.ibm.com \
--to=uweigand@de.ibm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=rth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).