public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/31248]  New: Too much casting for char operands on tree level
@ 2007-03-17 19:09 ubizjak at gmail dot com
  2007-03-18  5:30 ` [Bug tree-optimization/31248] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ubizjak at gmail dot com @ 2007-03-17 19:09 UTC (permalink / raw)
  To: gcc-bugs

Following testcase produces unnecessary moves in short loop:

--cut here--
char table[256];

int test(void) {

  char val = 0;
  int i;

  for (i = 0; i < 10; i++)
    val += table[i];

  return val;
}
--cut here--

gcc -O2:

test:
.LFB2:
        movzbl  table(%rip), %ecx
        movl    $1, %edx
        .p2align 4,,7
.L2:
(*)     movl    %ecx, %eax
        addb    table(%rdx), %al
        addq    $1, %rdx
        cmpq    $10, %rdx
(*)     movl    %eax, %ecx
        jne     .L2
        movsbl  %al,%eax
        ret

Those unneccesary moves (*) are generated due to many (spurious?) casts in
optimized tree dump:

test ()
{
  long unsigned int ivtmp.31;
  char val;
  unsigned char D.1985;

<bb 2>:
  val = (char) (unsigned char) MEM[symbol: table];
  ivtmp.31 = 1;

<L0>:;
  D.1985 = (unsigned char) val + (unsigned char) MEM[symbol: table, index:
ivtmp.31];
  val = (char) D.1985;
  ivtmp.31 = ivtmp.31 + 1;
  if (ivtmp.31 != 10) goto <L0>; else goto <L2>;

<L2>:;
  return (int) val;


-- 
           Summary: Too much casting for char operands on tree level
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ubizjak at gmail dot com
 GCC build triplet: x86_64-pc-linux-gnu
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


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


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

end of thread, other threads:[~2008-01-09  8:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-17 19:09 [Bug tree-optimization/31248] New: Too much casting for char operands on tree level ubizjak at gmail dot com
2007-03-18  5:30 ` [Bug tree-optimization/31248] " pinskia at gcc dot gnu dot org
2007-03-29  6:16 ` [Bug rtl-optimization/31248] char adding gives an extra move or two pinskia at gcc dot gnu dot org
2007-08-28 12:02 ` [Bug rtl-optimization/31248] char adding (in loops) " ubizjak at gmail dot com
2008-01-09  9:29 ` ubizjak at gmail dot com
2008-01-09  9:46 ` ubizjak at gmail dot com

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).