public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/51241] New: SH Target: Unnecessary sign/zero extensions
@ 2011-11-20 18:42 oleg.endo@t-online.de
  2011-11-21  2:06 ` [Bug target/51241] " kkojima at gcc dot gnu.org
  2012-07-11 23:45 ` olegendo at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: oleg.endo@t-online.de @ 2011-11-20 18:42 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51241
           Summary: SH Target: Unnecessary sign/zero extensions
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: oleg.endo@t-online.de
                CC: kkojima@gcc.gnu.org
            Target: sh*-*-*


Created attachment 25868
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25868
Examples

Under some circumstances unnecessary sign/zero extension insns are generated as
shown in the attached example.

sh-elf-gcc -v
Using built-in specs.
COLLECT_GCC=sh-elf-gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/sh-elf/4.7.0/lto-wrapper
Target: sh-elf
Configured with: ../gcc-trunk/configure --target=sh-elf --prefix=/usr/local
--enable-languages=c,c++ --enable-multilib --disable-libssp --disable-nls
--disable-werror --enable-lto --with-newlib --with-gnu-as --with-gnu-ld
--with-system-zlib
Thread model: single
gcc version 4.7.0 20111119 (experimental) (GCC)


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

* [Bug target/51241] SH Target: Unnecessary sign/zero extensions
  2011-11-20 18:42 [Bug target/51241] New: SH Target: Unnecessary sign/zero extensions oleg.endo@t-online.de
@ 2011-11-21  2:06 ` kkojima at gcc dot gnu.org
  2012-07-11 23:45 ` olegendo at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: kkojima at gcc dot gnu.org @ 2011-11-21  2:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Kazumoto Kojima <kkojima at gcc dot gnu.org> 2011-11-21 01:52:22 UTC ---
Please put the description of the problem into the trail itself
instead of attachment next time.

The problem looks to be splitted into several issues.

>	mov.b	@r4+,r3	! 40	*extendqisi2_compact_mem_inc
>	extu.b	r3,r3	! 41	*zero_extendqisi2_compact   <--- extu.b r3, r0
>	mov	r3,r0	! 75	movsi_ie/2                  <--- ??

This mov insn is generated with reload.  After all, SH's and #imm,*
would be too restrictive.

>	exts.b	r3,r3	! 50	*extendqisi2_compact        <--- ??
>	and	#127,r0	! 45	*andsi3_compact/1     <--- makes extu.b useless
>	cmp/pz	r3	! 51	cmpgesi_t/2

As you pointed out, if cmp/pz is placed at just after mov.b insn,
exts.b is not required.  I don't know whether such pass exists or not.

>	mov.l	@r4,r1	! 7	movsi_ie/7	[length = 2]
>	swap.w	r1,r1	! 13	rotlsi3_16	[length = 2]
>	exts.w	r1,r1	! 14	*extendhisi2_compact/1	[length = 2]
>	rts		! 21	*return_i	[length = 2]
>	mov.b	r1,@r5	! 10	*movqi/4	[length = 2]

The sequence of swap.w and exts.w are generated ashrsi2_16 insn
and its splitter.  exts.w could be removed by the combine pass,
though the split is done after combine.  Perhaps with replacing
that insn and splitter with an expand like

(define_expand "ashrsi2_16"
  [(set (match_operand:SI 0 "arith_reg_dest" "")
        (rotate:SI (match_operand:SI 1 "arith_reg_operand" "")
                   (const_int 16)))
   (set (match_dup 0) (sign_extend:SI (match_dup 2)))]
  "TARGET_SH1"
  "operands[2] = gen_lowpart (HImode, operands[0]);")

the combine will do the work.

>	negc	r1,r1	! 10	negc	[length = 2]
>	extu.b	r1,r0	! 12	*zero_extendqisi2_compact	[length = 2]

Again, usually the combine pass can remove such extu.b.
Perhaps negc has a pattern

  [(set (match_operand:SI 0 "arith_reg_dest" "=r")
    (neg:SI (plus:SI (reg:SI T_REG)
             (match_operand:SI 1 "arith_reg_operand" "r"))))
   (set (reg:SI T_REG)
    (ne:SI (ior:SI (reg:SI T_REG) (match_dup 1))
           (const_int 0)))]

which would be too complex for combine.


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

* [Bug target/51241] SH Target: Unnecessary sign/zero extensions
  2011-11-20 18:42 [Bug target/51241] New: SH Target: Unnecessary sign/zero extensions oleg.endo@t-online.de
  2011-11-21  2:06 ` [Bug target/51241] " kkojima at gcc dot gnu.org
@ 2012-07-11 23:45 ` olegendo at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: olegendo at gcc dot gnu.org @ 2012-07-11 23:45 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |olegendo at gcc dot gnu.org
         Resolution|                            |WORKSFORME

--- Comment #2 from Oleg Endo <olegendo at gcc dot gnu.org> 2012-07-11 23:44:40 UTC ---
As of rev 189427 this seems to be OK.  Probably the described cases were side
effects of other issues which have been solved.


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

end of thread, other threads:[~2012-07-11 23:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-20 18:42 [Bug target/51241] New: SH Target: Unnecessary sign/zero extensions oleg.endo@t-online.de
2011-11-21  2:06 ` [Bug target/51241] " kkojima at gcc dot gnu.org
2012-07-11 23:45 ` 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).