From owner-freebsd-hackers@FreeBSD.ORG Sat Nov 19 15:26:45 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BAB24106566C for ; Sat, 19 Nov 2011 15:26:45 +0000 (UTC) (envelope-from mdf356@gmail.com) Received: from mail-yx0-f182.google.com (mail-yx0-f182.google.com [209.85.213.182]) by mx1.freebsd.org (Postfix) with ESMTP id 7B4FF8FC08 for ; Sat, 19 Nov 2011 15:26:45 +0000 (UTC) Received: by yenl11 with SMTP id l11so5036227yen.13 for ; Sat, 19 Nov 2011 07:26:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=eaJDJ7lyrUkC/1HHESuNDJ91LzbDg7oO2Y7G/D0MAdo=; b=DANtUlk0BuYCLyG3ypOA91pmoJKKQFsNMy7iBmdQ/aMOJ32yCa7DX4A7MAAjMXsW8t WTWkW00lN58WMJ1dhXO9j4W7aY+BbvYB1DO5baMwvg4OrgWoTPpYl6FjFugk8BlM20i7 PTuW1O1MxnCIg9ebKtqDIz71LeVyfD5LhG/js= MIME-Version: 1.0 Received: by 10.68.59.73 with SMTP id x9mr14380265pbq.42.1321716404321; Sat, 19 Nov 2011 07:26:44 -0800 (PST) Sender: mdf356@gmail.com Received: by 10.68.56.97 with HTTP; Sat, 19 Nov 2011 07:26:44 -0800 (PST) In-Reply-To: <20111119100150.GA1560@reks> References: <20111119100150.GA1560@reks> Date: Sat, 19 Nov 2011 07:26:44 -0800 X-Google-Sender-Auth: WgKoJTlMnz30PrxC_Zw-1TPrl3Q Message-ID: From: mdf@FreeBSD.org To: Gleb Kurtsou Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-hackers@freebsd.org Subject: Re: gcc 4.2 miscompilation with -O2 -fno-omit-frame-pointer on amd64 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Nov 2011 15:26:45 -0000 On Sat, Nov 19, 2011 at 2:01 AM, Gleb Kurtsou wrote: > Hi, > > I was lucky to write a bit of code which gcc 4.2 fails to compile > correctly with -O2. Too keep long story short the code fails for gcc > from base system and last gcc 4.2 snapshot from ports. It works with gcc > 4.3, gcc 4.4 on FreeBSD and Linux. Clang from base is also good. -O and > -Os optimization levels are fine (I've tried with all -f* flags > mentioned in documentation) > > -O2 -fno-omit-frame-pointer combination is troublesome on amd64. I > presume i386 should be fine. These options are also used for > compilation of kernel (with debugging enabled) and modules. > > I'm not able to share the code, but have a test case reproducing the > bug. I've encountered the issue over a week ago and tried narrowing it down > to a simple test I could share but without much success. > > The code itself is very common: initialize two structs on stack, call a > function with pointers to those stucts as arguments. A number of inlined > assertion functions. gcc fails to correctly optimize struct assignments > with -fno-omit-frame-pointer, I have a number of small structs assigned, > gcc decides not to use data coping but to assign fields directly. I've > tried disabling sra, tweaking sra parameters -- no luck in forcing it > to copy data. Replacing one particular assignment with memcpy produces > correct code, but that's not a solution. How small are the structs? gcc has an optimization for structs that are no larger than a register, but it's buggy in 4.2 and we disabled it at $WORK. I can dig up the patch if this is the problem. Thanks, matthew