From patchwork Wed Oct 5 14:06:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrill Tkachov X-Patchwork-Id: 678468 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3spyJj6Zx5z9ryv for ; Thu, 6 Oct 2016 01:07:01 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=hrUiG292; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=Iqf1HTkHWCfM865RzOCMUAPXCuHbpf1/M8ormen5C/j2sX 91g5aRZRJKu0+D17Pz7LoBD+EWqWuaibsitgyybIdIwZfGhDmrpY36ukPlcPdZ+L G5IODAkKlNwknzlKA2NoLaKKjXh3A3ryD60h1gWGYhIn+WGo3tp5vdM1AaYfw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=AJwLsOuGggYLujdrQGpdJTmRBws=; b=hrUiG292Gzc82ktLXej5 ZY0rWhtP75ZRnGlvOuXbfq39vTkkoLhtI4qNf+SXd7N7VA5gYSaoyUr0Pw8+6fZO NM08zfMzxCAqMYjMYpyndIoJEUm1HiEAlaQM/jXC1bt2ASiJ5pnoe79/KUqyW38h PNfcyEfg716M1hlV0yC12GI= Received: (qmail 55093 invoked by alias); 5 Oct 2016 14:06:53 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 55082 invoked by uid 89); 5 Oct 2016 14:06:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, UNSUBSCRIBE_BODY autolearn=no version=3.3.2 spammy=MIN, fold-const.c, foldconstc, bitpos X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Oct 2016 14:06:42 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7EAD629 for ; Wed, 5 Oct 2016 07:06:40 -0700 (PDT) Received: from [10.2.207.77] (e100706-lin.cambridge.arm.com [10.2.207.77]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2E1733F218 for ; Wed, 5 Oct 2016 07:06:40 -0700 (PDT) Message-ID: <57F508EE.6020804@foss.arm.com> Date: Wed, 05 Oct 2016 15:06:38 +0100 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: GCC Patches Subject: [PATCH][fold-const] Fix native_encode_real for HFmode constants Hi all, I encountered a wrong-code issue with my WIP store merging pass when it was trying to encode HFmode constants. I am using native_encode_real to write the constants to a byte array and it's breaking on big-endian. For a 2-byte constant it ended up writing bytes at offsets 3 and 2 rather than 1 and 0. The fix in this patch makes the logic in native_encode_real match the logic in native_interpret_real, I just copied the logic across. I don't have a testcase against clean trunk that demonstrates the issue but with my store merging patch the testcase gcc.target/aarch64/advsimd-intrinsics/vldX.c starts failing without this patch because adjacent 16-bit float constants are not being merged correctly. Bootstrapped and tested on aarch64-none-linux-gnu. As this patch only affects the big-endian code path I also tested it on aarch64_be-none-elf. Ok for trunk? Do you think this needs to be backported? Thanks, Kyrill 2016-10-05 Kyrylo Tkachov * fold-const.c (native_encode_real): Fix logic for selecting offset to write to when BYTES_BIG_ENDIAN. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 81671e9fec68a3281b744626db1b94f26d19aabc..564d086e9636743104d629cd6f5620ac2ee6a544 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -7142,7 +7142,16 @@ native_encode_real (const_tree expr, unsigned char *ptr, int len, int off) offset += byte % UNITS_PER_WORD; } else - offset = BYTES_BIG_ENDIAN ? 3 - byte : byte; + { + offset = byte; + if (BYTES_BIG_ENDIAN) + { + /* Reverse bytes within each long, or within the entire float + if it's smaller than a long (for HFmode). */ + offset = MIN (3, total_bytes - 1) - offset; + gcc_assert (offset >= 0); + } + } offset = offset + ((bitpos / BITS_PER_UNIT) & ~3); if (offset >= off && offset - off < len)