Bug 45160 - [4.4.x/4.5.x regression] Invalid assembly code is generated for x86 architecture for faad2 library (AAC decode algorithm)
Summary: [4.4.x/4.5.x regression] Invalid assembly code is generated for x86 architect...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: inline-asm (show other bugs)
Version: 4.4.5
: P3 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-01 23:59 UTC by Artem S. Tashkinov
Modified: 2010-09-06 20:19 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
faad2 2.7.0 complete sources with -save-temps (923.79 KB, application/octet-stream)
2010-08-02 00:31 UTC, Artem S. Tashkinov
Details
faad2 2.7.0 complete sources with -save-temps for GCC 4.5.1 (764.69 KB, application/octet-stream)
2010-08-02 13:10 UTC, Artem S. Tashkinov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Artem S. Tashkinov 2010-08-01 23:59:07 UTC
A testcase for x86 architecture (Intel Core i5 CPU here):

1) Download http://sourceforge.net/projects/faac/files/faad2-src/faad2-2.6/faad2-2.6.1.tar.gz/download

2) Build it using these commands

perl -pi -e 's|dnl AC_PROG_CXX|AC_PROG_CXX|' configure.in
autoreconf -vif
configure --disable-static

using GCC 4.2.4 and GCC 4.4.x

3) faad binary compiled with GCC 4.4.x will fail to properly decode some AAC files (a sample file can be downloaded here http://bugzilla.mplayerhq.hu/attachment.cgi?id=651 )

faad -o outfile.wav out.aac
...

Decoding out.aac took:  0.21 sec. 285.83x real-time. (GCC 4.2.x)
Decoding out.aac took:  1.55 sec.  38.72x real-time. (GCC 4.4.x)

So, we have two bugs here:

1) faad2's AAC decode algorithm fails to work correctly under GCC 4.4.x (even with gcc -O2 -march=i686).
3) faad2's AAC decode algorithm compiled with GCC 4.4.x works an order of magnitude slower than the same code code compiled using GCC 4.2.x.
Comment 1 Artem S. Tashkinov 2010-08-02 00:09:32 UTC
faad2 2.7.0 exhibits the same misbehavior, you can download it here:

http://downloads.sourceforge.net/faac/faad2-2.7.tar.bz2

No extra commands are required for compilation, just ./configure && make

---

P.S. You may want to use 

./configure --enable-static --disable-shared

in order to get a single binary which doesn't use any external libraries (thus it will be easier to verify the bug).
Comment 2 Artem S. Tashkinov 2010-08-02 00:31:00 UTC
Created attachment 21368 [details]
faad2 2.7.0 complete sources with -save-temps

Complete sources with -save-temps for GCC 4.2.4 and GCC 4.4.4.

The same compilation flags:

-march=i686 -O2 -pipe -save-temps
Comment 3 Artem S. Tashkinov 2010-08-02 13:09:20 UTC
I've just tested GCC 4.5.1 and it also miscompiles the source code.
Comment 4 Artem S. Tashkinov 2010-08-02 13:10:03 UTC
Created attachment 21369 [details]
faad2 2.7.0 complete sources with -save-temps for GCC 4.5.1
Comment 5 Artem S. Tashkinov 2010-08-02 13:15:36 UTC
I've found the culprit (or better say mplayer developer hinted), it is -fstrict-aliasing optimization.

With -fno-strict-aliasing GCC 4.4.x and 4.5.x produce proper code.

Please, advise.
Comment 6 Richard Biener 2010-08-02 14:12:12 UTC
Why CC me?  I have no clue about faad2, the strict-aliasing thing hints
at errors in faad2, not gcc.
Comment 7 Artem S. Tashkinov 2010-08-02 15:49:19 UTC
(In reply to comment #6)
> Why CC me?  I have no clue about faad2, the strict-aliasing thing hints
> at errors in faad2, not gcc.
> 

Richard, I don't know who is who amongst GCC developers, but you are a prominent person, so I thought you know someone who can help shed light on this issue.

Like I said GCC 4.2.x has no problems compiling this library, so I have no idea who to blame and who else I should get in touch with.
Comment 8 Andrew Pinski 2010-08-02 16:21:19 UTC
> Like I said GCC 4.2.x has no problems compiling this library, so I have no idea
> who to blame and who else I should get in touch with.

I would get into contact with the developers of the library first.  Yes GCC has some bugs but the library could have a bug still.  Since the problem disappreas with -fno-strict-aliasing that normally points at a bug in the library.  In that it does not follow the C/C++ alisaing rules.
Comment 9 Artem S. Tashkinov 2010-08-02 20:27:09 UTC
The culprit is the ic_predict.c file. When I compile it with -fno-strict-aliasing (while everything else is being compiled with -fstrict-aliasing) libfaad works correctly.

These are the warnings which I get from GCC:

ic_predict.c: In function 'flt_round':
ic_predict.c:58: warning: dereferencing type-punned pointer will break strict-aliasing rules
ic_predict.c:58: warning: dereferencing type-punned pointer will break strict-aliasing rules
ic_predict.c:58: warning: dereferencing type-punned pointer will break strict-aliasing rules
ic_predict.c:60: warning: dereferencing type-punned pointer will break strict-aliasing rules
ic_predict.c: In function 'ic_prediction':
ic_predict.c:78: warning: dereferencing pointer 'tmp' does break strict-aliasing rules
ic_predict.c:77: note: initialized from here
ic_predict.c:78: warning: dereferencing pointer 'tmp' does break strict-aliasing rules
ic_predict.c:77: note: initialized from here
ic_predict.c:78: warning: dereferencing pointer 'tmp' does break strict-aliasing rules
ic_predict.c:77: note: initialized from here
ic_predict.c:78: warning: dereferencing pointer 'tmp' does break strict-aliasing rules
ic_predict.c:77: note: initialized from here
ic_predict.c:78: warning: dereferencing pointer 'tmp' does break strict-aliasing rules
ic_predict.c:77: note: initialized from here
ic_predict.c:78: warning: dereferencing pointer 'tmp' does break strict-aliasing rules
ic_predict.c:77: note: initialized from here

Maybe GCC developers could devise a patch for this file because http://www.audiocoding.com/faad2.html site seems to be dead.
Comment 10 Richard Biener 2010-08-30 15:47:42 UTC
Not a gcc bug.
Comment 11 Artem S. Tashkinov 2010-09-06 20:19:48 UTC
(In reply to comment #9)
> Maybe GCC developers could devise a patch for this file because
> http://www.audiocoding.com/faad2.html site seems to be dead.
> 

(In reply to comment #10)
> Not a gcc bug.
> 

FAAD developers don't answer my e-mails, so what I can do? Resort to compile FAAD library using a specially compiled GCC? What about other less experienced users? There just a few warnings which I suppose can be easily resolved ...