This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/34864] New: ldexp variants, folding
- From: "tbptbp at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Jan 2008 08:08:48 -0000
- Subject: [Bug c++/34864] New: ldexp variants, folding
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Briefly: of all the ldexp variants only straight ldexp consistently get folded.
The overloaded c++ version, std::ldexp, is the easiest to derail, as this
testcase demonstrates (note: you can't get much more than 1 such call folded);
but it has also happened to me with ldexpf, it's just harder to trigger.
$ cat pr-ldexp.cc
#include <cmath>
#define L1(x) ldexp((float)(x | (1<<23)), -23)
#define L2(x) std::ldexp((float)(x | (1<<23)), -23)
int main(int argc, char *argv[]) {
const float tbl[] = { L(0), L(1), L(2), L(3) };
return int(tbl[argc]);
}
$ /usr/local/gcc-4.3-20080104/bin/g++ -O2 -march=k8 -DL=L1 pr-ldexp.cc -o pr1
$ /usr/local/gcc-4.3-20080104/bin/g++ -O2 -march=k8 -DL=L2 pr-ldexp.cc -o pr2
pr1:
401091: f3 0f 10 04 9d 00 20 movss 0x402000(,%ebx,4),%xmm0
40109e: f3 0f 2c c0 cvttss2si %xmm0,%eax
4010a2: c9 leave
pr2:
401090: c7 45 e8 00 00 80 3f movl $0x3f800000,0xffffffe8(%ebp)
401097: c7 45 ec 01 00 80 3f movl $0x3f800001,0xffffffec(%ebp)
40109e: c7 45 f0 02 00 80 3f movl $0x3f800002,0xfffffff0(%ebp)
4010a5: c7 45 f4 03 00 80 3f movl $0x3f800003,0xfffffff4(%ebp)
4010ac: f3 0f 10 44 9d e8 movss 0xffffffe8(%ebp,%ebx,4),%xmm0
4010b2: 8b 5d fc mov 0xfffffffc(%ebp),%ebx
4010b5: f3 0f 2c c0 cvttss2si %xmm0,%eax
4010b9: c9 leave
(k8/sse codegen selected for clarity)
--
Summary: ldexp variants, folding
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tbptbp at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34864