public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/52933] New: SH Target: Use div0s for integer sign comparisons
@ 2012-04-11 11:03 olegendo at gcc dot gnu.org
  2012-04-11 11:04 ` [Bug target/52933] " olegendo at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: olegendo at gcc dot gnu.org @ 2012-04-11 11:03 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52933
           Summary: SH Target: Use div0s for integer sign comparisons
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: olegendo@gcc.gnu.org
            Target: sh*-*-*


Created attachment 27130
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27130
Experimental patch to use div0s for sign comparisons

The div0s instruction can be used to implement some integer sign comparison
patterns such as:

int a = ...;
int b = ...;

(a ^ b) >= 0;
(a < 0) == (b < 0);
(a ^ b) >> 31;

etc.

For example, the following function

bool test (int a, int b)
{
  return (a ^ b) >= 0;
}

is compiled into:
        xor     r4,r5
        not     r5,r0
        mov     #-31,r1
        shld    r1,r0
        rts
        extu.b  r0,r0

but could be:
        div0s   r5,r4
        mov     #-1,r0
        rts
        negc    r0,r0


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

* [Bug target/52933] SH Target: Use div0s for integer sign comparisons
  2012-04-11 11:03 [Bug target/52933] New: SH Target: Use div0s for integer sign comparisons olegendo at gcc dot gnu.org
@ 2012-04-11 11:04 ` olegendo at gcc dot gnu.org
  2012-08-14 17:59 ` olegendo at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: olegendo at gcc dot gnu.org @ 2012-04-11 11:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Oleg Endo <olegendo at gcc dot gnu.org> 2012-04-11 11:04:09 UTC ---
Created attachment 27131
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27131
Before/After Examples


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

* [Bug target/52933] SH Target: Use div0s for integer sign comparisons
  2012-04-11 11:03 [Bug target/52933] New: SH Target: Use div0s for integer sign comparisons olegendo at gcc dot gnu.org
  2012-04-11 11:04 ` [Bug target/52933] " olegendo at gcc dot gnu.org
@ 2012-08-14 17:59 ` olegendo at gcc dot gnu.org
  2012-08-15 16:05 ` olegendo at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: olegendo at gcc dot gnu.org @ 2012-08-14 17:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Oleg Endo <olegendo at gcc dot gnu.org> 2012-08-14 17:59:11 UTC ---
Author: olegendo
Date: Tue Aug 14 17:59:03 2012
New Revision: 190396

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190396
Log:
    PR target/52933
    * config/sh/sh.md (cmp_div0s_0, cmp_div0s_1, *cmp_div0s_0,
    *cmp_div0s_1, *cbranch_div0s, *movsicc_div0s): New insns.
    * config/sh/sh.c (sh_rtx_costs): Handle div0s patterns.

    PR target/52933
    * gcc.target/sh/pr52933-1.c: New.
    * gcc.target/sh/pr52933-2.c: New.


Added:
    trunk/gcc/testsuite/gcc.target/sh/pr52933-1.c
    trunk/gcc/testsuite/gcc.target/sh/pr52933-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/sh/sh.c
    trunk/gcc/config/sh/sh.md
    trunk/gcc/testsuite/ChangeLog


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

* [Bug target/52933] SH Target: Use div0s for integer sign comparisons
  2012-04-11 11:03 [Bug target/52933] New: SH Target: Use div0s for integer sign comparisons olegendo at gcc dot gnu.org
  2012-04-11 11:04 ` [Bug target/52933] " olegendo at gcc dot gnu.org
  2012-08-14 17:59 ` olegendo at gcc dot gnu.org
@ 2012-08-15 16:05 ` olegendo at gcc dot gnu.org
  2013-05-06 20:10 ` olegendo at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: olegendo at gcc dot gnu.org @ 2012-08-15 16:05 UTC (permalink / raw)
  To: gcc-bugs

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

Oleg Endo <olegendo at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2012-08-15
         AssignedTo|unassigned at gcc dot       |olegendo at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1


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

* [Bug target/52933] SH Target: Use div0s for integer sign comparisons
  2012-04-11 11:03 [Bug target/52933] New: SH Target: Use div0s for integer sign comparisons olegendo at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2012-08-15 16:05 ` olegendo at gcc dot gnu.org
@ 2013-05-06 20:10 ` olegendo at gcc dot gnu.org
  2014-12-17  1:52 ` olegendo at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: olegendo at gcc dot gnu.org @ 2013-05-06 20:10 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from Oleg Endo <olegendo at gcc dot gnu.org> 2013-05-06 20:10:11 UTC ---
http://gcc.gnu.org/viewcvs/gcc?view=revision&revision=198646

  PR target/52933
  * config/sh/sh.md (*cmp_div0s_0, *cmp_div0s_1, *movsicc_div0s): Add
  variations of these patterns.


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

* [Bug target/52933] SH Target: Use div0s for integer sign comparisons
  2012-04-11 11:03 [Bug target/52933] New: SH Target: Use div0s for integer sign comparisons olegendo at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2013-05-06 20:10 ` olegendo at gcc dot gnu.org
@ 2014-12-17  1:52 ` olegendo at gcc dot gnu.org
  2014-12-22 16:19 ` olegendo at gcc dot gnu.org
  2015-01-24 13:05 ` olegendo at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: olegendo at gcc dot gnu.org @ 2014-12-17  1:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Oleg Endo <olegendo at gcc dot gnu.org> ---
Some of the original test cases are still not working.  In particular cases
where bit positions != 31 are compared/xor'ed:

bool cmp_signs_24 (int a, int b)
{
  return (a & 0x8000) ^ (b & 0x8000);
}

bool cmp_signs_25 (int a, int b)
{
  return (a & 0x8000) != (b & 0x8000);
}

bool cmp_signs_26 (short a, short b)
{
  return (a < 0) == (b < 0);
}

bool cmp_signs_27 (short a, short b)
{
  return (a < 0) != (b < 0);
}

int cmp_signs_28 (short a, short b)
{
  return (a < 0) != (b < 0) ? 40 : -10;
}

Such cases can be improved by shifting the tested bit into MSB position and
using div0s.


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

* [Bug target/52933] SH Target: Use div0s for integer sign comparisons
  2012-04-11 11:03 [Bug target/52933] New: SH Target: Use div0s for integer sign comparisons olegendo at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2014-12-17  1:52 ` olegendo at gcc dot gnu.org
@ 2014-12-22 16:19 ` olegendo at gcc dot gnu.org
  2015-01-24 13:05 ` olegendo at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: olegendo at gcc dot gnu.org @ 2014-12-22 16:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Oleg Endo <olegendo at gcc dot gnu.org> ---
Author: olegendo
Date: Mon Dec 22 16:19:11 2014
New Revision: 219017

URL: https://gcc.gnu.org/viewcvs?rev=219017&root=gcc&view=rev
Log:
gcc/testsuite/
    PR target/52933
    * gcc.target/sh/sh/pr52933-3.c: New.

Added:
    trunk/gcc/testsuite/gcc.target/sh/pr52933-3.c
Modified:
    trunk/gcc/testsuite/ChangeLog


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

* [Bug target/52933] SH Target: Use div0s for integer sign comparisons
  2012-04-11 11:03 [Bug target/52933] New: SH Target: Use div0s for integer sign comparisons olegendo at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2014-12-22 16:19 ` olegendo at gcc dot gnu.org
@ 2015-01-24 13:05 ` olegendo at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: olegendo at gcc dot gnu.org @ 2015-01-24 13:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Oleg Endo <olegendo at gcc dot gnu.org> ---
Author: olegendo
Date: Sat Jan 24 13:04:53 2015
New Revision: 220081

URL: https://gcc.gnu.org/viewcvs?rev=220081&root=gcc&view=rev
Log:
gcc/
    PR target/49263
    PR target/53987
    PR target/64345
    PR target/59533
    PR target/52933
    PR target/54236
    PR target/51244
    * config/sh/sh-protos.h
    (sh_extending_set_of_reg::can_use_as_unextended_reg,
    sh_extending_set_of_reg::use_as_unextended_reg,
    sh_is_nott_insn, sh_movt_set_dest, sh_movrt_set_dest, sh_is_movt_insn,
    sh_is_movrt_insn, sh_insn_operands_modified_between_p,
    sh_reg_dead_or_unused_after_insn, sh_in_recog_treg_set_expr,
    sh_recog_treg_set_expr, sh_split_treg_set_expr): New functions.
    (sh_treg_insns): New class.
    * config/sh/sh.c (TARGET_LEGITIMATE_COMBINED_INSN): Define target hook.
    (scope_counter): New class.
    (sh_legitimate_combined_insn, sh_is_nott_insn, sh_movt_set_dest,
    sh_movrt_set_dest, sh_reg_dead_or_unused_after_insn,
    sh_extending_set_of_reg::can_use_as_unextended_reg,
    sh_extending_set_of_reg::use_as_unextended_reg, sh_recog_treg_set_expr,
    sh_in_recog_treg_set_expr, sh_try_split_insn_simple,
    sh_split_treg_set_expr): New functions.
    (addsubcosts): Handle treg_set_expr.
    (sh_rtx_costs): Handle IF_THEN_ELSE and ZERO_EXTRACT.
    (sh_rtx_costs): Use arith_reg_operand in SIGN_EXTEND and ZERO_EXTEND.
    (sh_rtx_costs): Handle additional bit test patterns in EQ and AND cases.
    (sh_insn_operands_modified_between_p): Make non-static.
    * config/sh/predicates.md (zero_extend_movu_operand): Allow
    simple_mem_operand in addition to displacement_mem_operand.
    (zero_extend_operand): Don't allow zero_extend_movu_operand.
    (treg_set_expr, treg_set_expr_not_const01,
    arith_reg_or_treg_set_expr): New predicates.
    * config/sh/sh.md (tstsi_t): Use arith_reg_operand and
    arith_or_int_operand instead of logical_operand.  Convert to
    insn_and_split.  Try to optimize constant operand in splitter.
    (tsthi_t, tstqi_t): Fold into *tst<mode>_t.  Convert to insn_and_split.
    (*tstqi_t_zero): Delete.
    (*tst<mode>_t_subregs): Add !sh_in_recog_treg_set_expr split condition.
    (tstsi_t_and_not): Delete.
    (tst<mode>_t_zero_extract_eq): Rename to *tst<mode>_t_zero_extract.
    Convert to insn_and_split.
    (unnamed split, tstsi_t_zero_extract_xor,
    tstsi_t_zero_extract_subreg_xor_little,
    tstsi_t_zero_extract_subreg_xor_big): Delete.
    (*tstsi_t_shift_mask): New insn_and_split.
    (cmpeqsi_t, cmpgesi_t): Add new split for const_int 0 operands and try
    to recombine with surrounding insns when splitting.
    (*negtstsi): Add !sh_in_recog_treg_set_expr condition.
    (cmp_div0s_0, cmp_div0s_1, *cmp_div0s_0, *cmp_div0s_1): Rewrite as ...
    (cmp_div0s, *cmp_div0s_1, *cmp_div0s_2, *cmp_div0s_3, *cmp_div0s_4,
    *cmp_div0s_5, *cmp_div0s_6): ... these new insn_and_split patterns.
    (*cbranch_div0s: Delete.
    (*addc): Convert to insn_and_split.  Use treg_set_expr as 3rd operand.
    Try to recombine with surrounding insns when splitting.  Add operand
    order variants.
    (*addc_t_r, *addc_r_t): Use treg_set_expr_not_const01.
    (*addc_r_r_1, *addc_r_lsb, *addc_r_r_lsb, *addc_r_lsb_r, *addc_r_msb,
    *addc_r_r_msb, *addc_2r_msb): Delete.
    (*addc_2r_lsb): Rename to *addc_2r_t.  Use treg_set_expr.  Add operand
    order variant.
    (*addc_negreg_t): New insn_and_split.
    (*subc): Convert to insn_and_split.  Use treg_set_expr as 3rd operand.
    Try to recombine with surrounding insns when splitting.
    Add operand order variants.  
    (*subc_negt_reg, *subc_negreg_t, *reg_lsb_t, *reg_msb_t): New
    insn_and_split patterns.
    (*rotcr): Use arith_reg_or_treg_set_expr.  Try to recombine with
    surrounding insns when splitting.
    (unnamed rotcr split): Use arith_reg_or_treg_set_expr.
    (*rotcl): Likewise.  Add zero_extract variant.
    (*ashrsi2_31): New insn_and_split.
    (*negc): Convert to insn_and_split.  Use treg_set_expr.
    (*zero_extend<mode>si2_disp_mem): Update comment.
    (movrt_negc, *movrt_negc, nott): Add !sh_in_recog_treg_set_expr split
    condition.
    (*mov_t_msb_neg, mov_neg_si_t): Use treg_set_expr.  Try to recombine
    with surrounding insns when splitting.
    (any_treg_expr_to_reg): New insn_and_split.
    (*neg_zero_extract_0, *neg_zero_extract_1, *neg_zero_extract_2,
    *neg_zero_extract_3, *neg_zero_extract_4, *neg_zero_extract_5,
    *neg_zero_extract_6, *zero_extract_0, *zero_extract_1,
    *zero_extract_2): New single bit zero extract patterns.
    (bld_reg, *bld_regqi): Fold into bld<mode>_reg.
    (*get_thread_pointersi, store_gbr, *mov<mode>_gbr_load,
    *mov<mode>_gbr_load, *mov<mode>_gbr_load, *mov<mode>_gbr_load,
    *movdi_gbr_load): Use arith_reg_dest instead of register_operand for
    set destination.
    (set_thread_pointersi, load_gbr): Use arith_reg_operand instead of
    register_operand for set source.

gcc/testsuite/
    PR target/49263
    PR target/53987
    PR target/64345
    PR target/59533
    PR target/52933
    PR target/54236
    PR target/51244
    * gcc.target/sh/pr64345-1.c: New.
    * gcc.target/sh/pr64345-2.c: New.
    * gcc.target/sh/pr59533-1.c: New.
    * gcc.target/sh/pr49263.c: Adjust matching of expected insns.
    * gcc.target/sh/pr52933-2.c: Likewise.
    * gcc.target/sh/pr54089-1.c: Likewise.
    * gcc.target/sh/pr54236-1.c: Likewise.
    * gcc.target/sh/pr51244-20-sh2a.c: Likewise.
    * gcc.target/sh/pr49263-1.c: Remove xfails.
    * gcc.target/sh/pr49263-2.c: Likewise.
    * gcc.target/sh/pr49263-3.c: Likewise.
    * gcc.target/sh/pr53987-1.c: Likewise.
    * gcc.target/sh/pr52933-1.c: Adjust matching of expected insns.
    (test_24, test_25, test_26, test_27, test_28, test_29, test_30): New.
    * gcc.target/sh/pr51244-12.c: Adjust matching of expected insns.
    (test05, test06, test07, test08, test09, test10, test11, test12): New.
    * gcc.target/sh/pr54236-3.c: Adjust matching of expected insns.
    (test_002, test_003, test_004, test_005, test_006, test_007, test_008,
    test_009): New.
    * gcc.target/sh/pr51244-4.c: Adjust matching of expected insns.
    (test_02): New.

Added:
    trunk/gcc/testsuite/gcc.target/sh/pr59533-1.c
    trunk/gcc/testsuite/gcc.target/sh/pr64345-1.c
    trunk/gcc/testsuite/gcc.target/sh/pr64345-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/sh/predicates.md
    trunk/gcc/config/sh/sh-protos.h
    trunk/gcc/config/sh/sh.c
    trunk/gcc/config/sh/sh.md
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.target/sh/pr49263-1.c
    trunk/gcc/testsuite/gcc.target/sh/pr49263-2.c
    trunk/gcc/testsuite/gcc.target/sh/pr49263-3.c
    trunk/gcc/testsuite/gcc.target/sh/pr49263.c
    trunk/gcc/testsuite/gcc.target/sh/pr51244-12.c
    trunk/gcc/testsuite/gcc.target/sh/pr51244-20-sh2a.c
    trunk/gcc/testsuite/gcc.target/sh/pr51244-4.c
    trunk/gcc/testsuite/gcc.target/sh/pr52933-1.c
    trunk/gcc/testsuite/gcc.target/sh/pr52933-2.c
    trunk/gcc/testsuite/gcc.target/sh/pr53987-1.c
    trunk/gcc/testsuite/gcc.target/sh/pr54089-1.c
    trunk/gcc/testsuite/gcc.target/sh/pr54236-1.c
    trunk/gcc/testsuite/gcc.target/sh/pr54236-3.c


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

end of thread, other threads:[~2015-01-24 13:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-11 11:03 [Bug target/52933] New: SH Target: Use div0s for integer sign comparisons olegendo at gcc dot gnu.org
2012-04-11 11:04 ` [Bug target/52933] " olegendo at gcc dot gnu.org
2012-08-14 17:59 ` olegendo at gcc dot gnu.org
2012-08-15 16:05 ` olegendo at gcc dot gnu.org
2013-05-06 20:10 ` olegendo at gcc dot gnu.org
2014-12-17  1:52 ` olegendo at gcc dot gnu.org
2014-12-22 16:19 ` olegendo at gcc dot gnu.org
2015-01-24 13:05 ` olegendo 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).