From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16227 invoked by alias); 7 Apr 2010 18:38:46 -0000 Received: (qmail 16215 invoked by uid 22791); 7 Apr 2010 18:38:44 -0000 X-SWARE-Spam-Status: No, hits=0.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,SARE_MSGID_LONG45,TW_DD,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-gw0-f47.google.com (HELO mail-gw0-f47.google.com) (74.125.83.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 07 Apr 2010 18:38:40 +0000 Received: by gwj21 with SMTP id 21so629482gwj.20 for ; Wed, 07 Apr 2010 11:38:38 -0700 (PDT) MIME-Version: 1.0 Received: by 10.151.101.4 with HTTP; Wed, 7 Apr 2010 11:38:36 -0700 (PDT) Date: Wed, 07 Apr 2010 18:47:00 -0000 Received: by 10.150.131.8 with SMTP id e8mr9323437ybd.270.1270665516689; Wed, 07 Apr 2010 11:38:36 -0700 (PDT) Message-ID: Subject: [alpha] Wrong code produced at -Os, -O2, and -O3 From: Matt Turner To: gcc@gcc.gnu.org Cc: Uros Bizjak , Richard Henderson Content-Type: multipart/mixed; boundary=000e0cd4cdb6c02bdd0483a9dedb Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2010-04/txt/msg00122.txt.bz2 --000e0cd4cdb6c02bdd0483a9dedb Content-Type: text/plain; charset=ISO-8859-1 Content-length: 1452 Hi Uros and Richard, I was rewriting the Alpha sched_find_first_bit implementation for the Linux Kernel, and in the process I think I've come across a gcc bug. I rewrote the function using cmov instructions, and wrote a small program to test its correctness and performance. I wrote the function initially as an external .S file, and once I was reasonably sure it was correct, converted it to C function with inline assembly. Compiling both produce the exact same output, as shown. : ldq t0,0(a0) clr t2 ldq t1,8(a0) cmoveq t0,0x40,t2 cmoveq t0,t1,t0 cttz t0,t3 addq t3,t2,v0 ret In my test program, I found that when I executed the rewritten implementation _before_ the reference implementation that it produced bogus results. This only happens when using the C/inline asm function. When compiled with the external .S file, the results are correct. Attached is a tar.gz with my test code. Compile the test program with `gcc -O -mcpu=... find.c rewritten.S test.c -o test` with optional -D__REWRITTEN_INLINE and -D__REWRITTEN_FIRST. At -Os, -O2, or -O3 and -D__REWRITTEN_INLINE and -D__REWRITTEN_FIRST the program will produce incorrect results and assert(). At -O0 or -O1 or without one or both of the -D flags, it will produce correct results. I've tested with gcc-4.3.4 and gcc-4.4.2. Thanks. Let me know what I can do to help further. Matt Turner --000e0cd4cdb6c02bdd0483a9dedb Content-Type: application/x-gzip; name="sched_find_first_bit.tar.gz" Content-Disposition: attachment; filename="sched_find_first_bit.tar.gz" Content-Transfer-Encoding: base64 X-Attachment-Id: f_g7qhfs0x0 Content-length: 1985 H4sIAEnRvEsAA+0Ya2/bNjBfqV/B+THIjpaIkmUHSbN9WboFCPKhzdYPnWHI Mp0wkyWPotPHkP++O+plyUrTAUaLbjrAFnlv8o7HRxLc8cVsKSL8k4mazYU6 Ptgv2AATz9NfgPpXtxlzvQnzbM9mBzZzJ7Z3QL09+9EIm0T5ktIDGcfqU3zP 0b9RSJrir3iijoK92cAAj0cj/LKJZ2dflsffcxwni/9o4jkuxH/sOvYBtffm wScgj//KVypRJydP8T1H/0ahK6Ig3Cw4fZGohYiP7n40KqhQzKs4P0m4VIgz ugsOicPpbCbXQQCf+UaESkQzP1zf+Rq5xbOWfMlVcLfFl6NKVVcX17/c/Eqd oUOPh9ShmygRtxFf0DCObhOL+tECsCJSCV1zqbF0eAzyYgkaQPXLy+ufZ5fX V5fXF0aX0sL6n1xGPJwFSn003w+ohtKRQH0MAW0YkAxKBGAgRLGKdWBfLhOz insXy8XA+Nsg4O2bO86PKL34fTyhgR/BLww2oa84FYouhOSBCj8AA/hLJFc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