public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tkoenig at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/100622] Conversion to smaller unsigned type in loop
Date: Mon, 17 May 2021 09:05:26 +0000	[thread overview]
Message-ID: <bug-100622-4-nzk28FHkYD@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-100622-4@http.gcc.gnu.org/bugzilla/>

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

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|SUSPENDED                   |UNCONFIRMED
     Ever confirmed|1                           |0

--- Comment #2 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
So, with recent trunk now.

[tkoenig@gcc135 tmp]$ gcc -v
Es werden eingebaute Spezifikationen verwendet.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/tkoenig/libexec/gcc/powerpc64le-unknown-linux-gnu/12.0.0/lto-wrapper
Ziel: powerpc64le-unknown-linux-gnu
Konfiguriert mit: ../trunk/configure --prefix=/home/tkoenig
--enable-languages=c,c++,fortran
Thread-Modell: posix
Unterstützte LTO-Kompressionsalgorithmen: zlib
gcc-Version 12.0.0 20210516 (experimental) (GCC) 
[tkoenig@gcc135 tmp]$ cat add.c

unsigned int foo(unsigned int *a, int n)
{
  int i;
  unsigned int res = 0;
  for (i=0; i<n; i++)
    res += a[i];

  return res;
}

unsigned int foo2 (unsigned int *a, int n)
{
  int i;
  unsigned long res = 0;
  for (i=0; i<n; i++)
    res += a[i];

  return res;
}
[tkoenig@gcc135 tmp]$ gcc -O -c add.c  && objdump --disassemble add.o

add.o:     file format elf64-powerpcle


Disassembly of section .text:

0000000000000000 <foo>:
   0:   00 00 04 2c     cmpwi   r4,0
   4:   30 00 81 40     ble     34 <foo+0x34>
   8:   20 00 89 78     clrldi  r9,r4,32
   c:   fc ff 43 39     addi    r10,r3,-4
  10:   00 00 60 38     li      r3,0
  14:   a6 03 29 7d     mtctr   r9
  18:   04 00 0a 85     lwzu    r8,4(r10)
  1c:   14 1a 68 7c     add     r3,r8,r3
  20:   20 00 63 78     clrldi  r3,r3,32
  24:   ff ff 29 39     addi    r9,r9,-1
  28:   20 00 29 79     clrldi  r9,r9,32
  2c:   ec ff 00 42     bdnz    18 <foo+0x18>
  30:   20 00 80 4e     blr
  34:   00 00 60 38     li      r3,0
  38:   20 00 80 4e     blr
        ...

0000000000000048 <foo2>:
  48:   00 00 04 2c     cmpwi   r4,0
  4c:   30 00 81 40     ble     7c <foo2+0x34>
  50:   20 00 89 78     clrldi  r9,r4,32
  54:   fc ff 43 39     addi    r10,r3,-4
  58:   00 00 60 38     li      r3,0
  5c:   a6 03 29 7d     mtctr   r9
  60:   04 00 0a 85     lwzu    r8,4(r10)
  64:   14 42 63 7c     add     r3,r3,r8
  68:   ff ff 29 39     addi    r9,r9,-1
  6c:   20 00 29 79     clrldi  r9,r9,32
  70:   f0 ff 00 42     bdnz    60 <foo2+0x18>
  74:   20 00 63 78     clrldi  r3,r3,32
  78:   20 00 80 4e     blr
  7c:   00 00 60 38     li      r3,0
  80:   f4 ff ff 4b     b       74 <foo2+0x2c>


With -O2 -fno-unroll-loops (foo only):

0000000000000000 <foo>:
   0:   00 00 04 2c     cmpwi   r4,0
   4:   3c 00 81 40     ble     40 <foo+0x40>
   8:   20 00 8a 78     clrldi  r10,r4,32
   c:   fc ff 23 39     addi    r9,r3,-4
  10:   a6 03 49 7d     mtctr   r10
  14:   00 00 60 38     li      r3,0
  18:   00 00 00 60     nop
  1c:   00 00 42 60     ori     r2,r2,0
  20:   04 00 49 85     lwzu    r10,4(r9)
  24:   14 1a 6a 7c     add     r3,r10,r3
  28:   20 00 63 78     clrldi  r3,r3,32
  2c:   f4 ff 00 42     bdnz    20 <foo+0x20>
  30:   20 00 80 4e     blr
  34:   00 00 00 60     nop
  38:   00 00 00 60     nop
  3c:   00 00 42 60     ori     r2,r2,0
  40:   00 00 60 38     li      r3,0
  44:   20 00 80 4e     blr
        ...
  54:   00 00 00 60     nop
  58:   00 00 00 60     nop
  5c:   00 00 42 60     ori     r2,r2,0

The clrldi is still in there.

  parent reply	other threads:[~2021-05-17  9:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-16  8:37 [Bug rtl-optimization/100622] New: " tkoenig at gcc dot gnu.org
2021-05-17  8:46 ` [Bug rtl-optimization/100622] " tkoenig at gcc dot gnu.org
2021-05-17  9:05 ` tkoenig at gcc dot gnu.org [this message]
2021-05-17 12:41 ` rguenth at gcc dot gnu.org
2021-05-17 13:39 ` tkoenig at gcc dot gnu.org
2021-05-17 22:02 ` segher at gcc dot gnu.org
2021-06-08  6:25 ` guojiufu at gcc dot gnu.org
2021-06-08 12:08 ` segher at gcc dot gnu.org
2021-09-17  6:49 ` pinskia at gcc dot gnu.org

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=bug-100622-4-nzk28FHkYD@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).