[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#452431: g++-4.2: two cases of bad optimization in x86 (i686) with long long in 32bit



Package: g++-4.2
Version: 4.2.2-3
Severity: minor


the following snippet of code shows two cases of bad optimization
behaviour on gcc 4.1.3 and 4.2.3 (debian unstable).



#define PTS_MASK ((1LL << 33)-1)
#define PTS_WRAP (1LL << 33)
#define PTS_WRAP2 (1LL << 32)

long long ptsdiff_mod2_33(long long a, long long b) {
  long long d = (b + PTS_WRAP - a) & PTS_MASK;
  return (d >= PTS_WRAP2) ? d - PTS_WRAP : d;
}



the following assembler code is generated:



        .file   "test4.cpp"
        .text
        .align 2
        .p2align 4,,15
.globl _Z15ptsdiff_mod2_33xx
        .type   _Z15ptsdiff_mod2_33xx, @function
_Z15ptsdiff_mod2_33xx:
.LFB2:
        pushl   %ebp
.LCFI0:
        movl    %esp, %ebp
.LCFI1:
        movl    16(%ebp), %eax
        movl    20(%ebp), %edx
        pushl   %ebx
.LCFI2:
        addl    $0, %eax
        adcl    $2, %edx
        subl    8(%ebp), %eax
        sbbl    12(%ebp), %edx
        movl    %eax, %ecx
        movl    %edx, %ebx
        andl    $1, %ebx
        cmpl    $0, %ebx
        jl      .L2
        jle     .L2
        addl    $0, %ecx
        adcl    $-2, %ebx
.L2:
        movl    %ebx, %edx
        movl    %ecx, %eax
        popl    %ebx
        popl    %ebp
        ret
.LFE2:
        .size   _Z15ptsdiff_mod2_33xx, .-_Z15ptsdiff_mod2_33xx
.globl __gxx_personality_v0
        .ident  "GCC: (GNU) 4.1.3 20071019 (prerelease) (Debian 4.1.2-17)"
        .section        .note.GNU-stack,"",@progbits



two obvious optimization faults:

1) addl $0, reg   is totally pointless

2) jl label   followed by   jle label   is equivalent to just   jle label


i reported that bug too to gcc, but their mailer blocked the mail.


-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 2.6.23.1 (PREEMPT)
Locale: LANG=de_DE.UTF-8@euro, LC_CTYPE=de_DE.UTF-8@euro (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages g++-4.2 depends on:
ii  gcc-4.2                       4.2.2-3    The GNU C compiler
ii  gcc-4.2-base                  4.2.2-3    The GNU Compiler Collection
(base
ii  libc6                         2.6.1-6    GNU C Library: Shared libraries
ii  libstdc++6-4.2-dev            4.2.2-3    The GNU Standard C++
Library v3 (d

g++-4.2 recommends no packages.

-- no debconf information





Reply to: