From patchwork Tue Mar 6 06:06:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yasushi SHOJI X-Patchwork-Id: 882004 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="C+RG4C+i"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3zwZSr59BPz9shV for ; Tue, 6 Mar 2018 22:35:06 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id C4E8DC21F5B; Tue, 6 Mar 2018 11:34:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id ECDBBC21CB6; Tue, 6 Mar 2018 11:34:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6548FC21E62; Tue, 6 Mar 2018 06:06:11 +0000 (UTC) Received: from mail-lf0-f67.google.com (mail-lf0-f67.google.com [209.85.215.67]) by lists.denx.de (Postfix) with ESMTPS id E7351C21DA2 for ; Tue, 6 Mar 2018 06:06:10 +0000 (UTC) Received: by mail-lf0-f67.google.com with SMTP id o145so26714655lff.0 for ; Mon, 05 Mar 2018 22:06:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=gQzDCIJd1+43Tcg3IcWeKWilJKmVQ/A2zVDBZeRnY4Q=; b=C+RG4C+i8rrW2B41pbL7mmoxCnO+QB1S3yhE+bLZZl2PKzcvfsoyyVbMVjpkDyrgjp VD6GkHNGgnYQoKZSzTc72KVPLV6Eo/ddG795SfnIicdZhcSFPtEThqSJsZ5feq3bNcT9 cBXoMJ/CGnTPz6vGVkAlVRPZ9qJdxgOpMWUUpB1vTcZStWkRrqPAazVRZPGkrcWe2K0I A/gMP7V/+ZMj11KMsMttA2sdG+1IuzjpVw+iHXfUe3FU/NY0v3Rel3vjNkVVF1SRcsro DwMbqOzKafM2AdI4nSy0MCSZDtpq9eZGbqiPwAh1AC9Dlf7wsl+eayYVwVIPHNRCL2Aw s9Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=gQzDCIJd1+43Tcg3IcWeKWilJKmVQ/A2zVDBZeRnY4Q=; b=EaGVwsn4Pa/FS9OcA7L/b2/xZ10FuyctdLhCxtAsAKy2aM6+nRM41R+Op4dfvJRLPj nNJb2gXVtBA0ijC3B0J5qpwlQtMifoVV2loi1ExU1+UAJ4PBwo1D01+kLCIFfw72wJS1 fQvam2kN1IEcmLRib9AtkGPwGWVLmDJrcay0YuTY+/ZKODAxXQ3JB7mJWGhDRaIGM3zj zCuH+b7opr6hTsz3t5kjt7TF2maF9OwmY5BtdjHm7Lo2rTYKgLn+eqq4JfIRpfIoQoZr Dddk7ZAKB2PE2dC6wOvbUEnr6GuA+ZzpfWgbJCwM1RE25MMrsAXmCpZMar5cy0mFqN3Q kFwg== X-Gm-Message-State: AElRT7FS1qPaURp+ZYym4A/HWs3Y2gIoQV2eI3KzN/b5FnoO8jSviKLq OUiesK9svY7y47gjrjW1kj+EfQrxuOn+GiesivbC7Q== X-Google-Smtp-Source: AG47ELsAE7FqfE2qEjzgzgkBSeBJwiWibDlDQIZmd9F3rktIxCmeV4V7Z1ETYKb7pJ8gj55NLB6YIifuk4mP8Rw3wkw= X-Received: by 10.25.42.143 with SMTP id q15mr11279878lfq.84.1520316369824; Mon, 05 Mar 2018 22:06:09 -0800 (PST) MIME-Version: 1.0 Received: by 10.46.72.17 with HTTP; Mon, 5 Mar 2018 22:06:08 -0800 (PST) From: Yasushi SHOJI Date: Tue, 6 Mar 2018 15:06:08 +0900 Message-ID: To: u-boot@lists.denx.de X-Mailman-Approved-At: Tue, 06 Mar 2018 11:34:52 +0000 Cc: fabio.estevam@nxp.com Subject: [U-Boot] imx: get_ticks in syscounter.c get miscompiled by GCC 6 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Hi, It seems to me that both GCC 6.3 and 6.4 mis-compiles arch/arm/mach-imx/syscounter.c. I'm attaching two files, bad.txt is the original syscounter.c and good.txt is the one with the following patch. The target code is the while loop in the __udelay. void __udelay(unsigned long usec) { unsigned long long tmp; ulong tmo; tmo = us_to_tick(usec); tmp = get_ticks() + tmo; /* get current timestamp */ while (get_ticks() < tmp) /* loop till event */ /*NOP*/; } Here is the mis compiled asm from the above code (whole function is attached as bad.txt) 88: 428b cmp r3, r1 8a: f8ce 20a4 str.w r2, [lr, #164] ; 0xa4 8e: bf08 it eq 90: 4282 cmpeq r2, r0 92: f8ce 30a0 str.w r3, [lr, #160] ; 0xa0 96: d3f7 bcc.n 88 <__udelay+0x88> Note that the last bcc.n to 88 and we don't see mrrc. This seems to be that both get_ticks() are inlined and "mrrc"s are duplicated in the __udealy() and GCC sees it as an opportunity to optimize out. GCC 5 and 8 seems to work fine. Unfortunately I don't have GCC 7 ATM so no idea how it compiles. Does anyone see this? diff --git a/arch/arm/mach-imx/syscounter.c b/arch/arm/mach-imx/syscounter.c index 9290918dca..30ed0109a2 100644 --- a/arch/arm/mach-imx/syscounter.c +++ b/arch/arm/mach-imx/syscounter.c @@ -82,7 +82,7 @@ unsigned long long get_ticks(void) { unsigned long long now; - asm("mrrc p15, 0, %Q0, %R0, c14" : "=r" (now)); + asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (now)); gd->arch.tbl = (unsigned long)(now & 0xffffffff); gd->arch.tbu = (unsigned long)(now >> 32);