From patchwork Fri Sep 11 05:32:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 1362253 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bnksf5qczz9sTv for ; Fri, 11 Sep 2020 15:32:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7EFD7384BC21; Fri, 11 Sep 2020 05:32:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 8023C3857C41 for ; Fri, 11 Sep 2020 05:32:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8023C3857C41 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9A005AEE0; Fri, 11 Sep 2020 05:32:25 +0000 (UTC) Subject: [committed][nvptx] Fix printing of 128-bit constant (negative case) To: Jakub Jelinek References: <20200910193132.GA12213@delia> <20200910202612.GH18149@tucnak> From: Tom de Vries Autocrypt: addr=tdevries@suse.de; keydata= xsBNBF0ltCcBCADDhsUnMMdEXiHFfqJdXeRvgqSEUxLCy/pHek88ALuFnPTICTwkf4g7uSR7 HvOFUoUyu8oP5mNb4VZHy3Xy8KRZGaQuaOHNhZAT1xaVo6kxjswUi3vYgGJhFMiLuIHdApoc u5f7UbV+egYVxmkvVLSqsVD4pUgHeSoAcIlm3blZ1sDKviJCwaHxDQkVmSsGXImaAU+ViJ5l CwkvyiiIifWD2SoOuFexZyZ7RUddLosgsO0npVUYbl6dEMq2a5ijGF6/rBs1m3nAoIgpXk6P TCKlSWVW6OCneTaKM5C387972qREtiArTakRQIpvDJuiR2soGfdeJ6igGA1FZjU+IsM5ABEB AAHNH1RvbSBkZSBWcmllcyA8dGRldnJpZXNAc3VzZS5kZT7CwKsEEwEIAD4WIQSsnSe5hKbL MK1mGmjuhV2rbOJEoAUCXSW0JwIbAwUJA8JnAAULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAh CRDuhV2rbOJEoBYhBKydJ7mEpsswrWYaaO6FXats4kSgc48H/Ra2lq5p3dHsrlQLqM7N68Fo eRDf3PMevXyMlrCYDGLVncQwMw3O/AkousktXKQ42DPJh65zoXB22yUt8m0g12xkLax98KFJ 5NyUloa6HflLl+wQL/uZjIdNUQaHQLw3HKwRMVi4l0/Jh/TygYG1Dtm8I4o708JS4y8GQxoQ UL0z1OM9hyM3gI2WVTTyprsBHy2EjMOu/2Xpod95pF8f90zBLajy6qXEnxlcsqreMaqmkzKn 3KTZpWRxNAS/IH3FbGQ+3RpWkNGSJpwfEMVCeyK5a1n7yt1podd1ajY5mA1jcaUmGppqx827 8TqyteNe1B/pbiUt2L/WhnTgW1NC1QDOwE0EXSW0JwEIAM99H34Bu4MKM7HDJVt864MXbx7B 1M93wVlpJ7Uq+XDFD0A0hIal028j+h6jA6bhzWto4RUfDl/9mn1StngNVFovvwtfzbamp6+W pKHZm9X5YvlIwCx131kTxCNDcF+/adRW4n8CU3pZWYmNVqhMUiPLxElA6QhXTtVBh1RkjCZQ Kmbd1szvcOfaD8s+tJABJzNZsmO2hVuFwkDrRN8Jgrh92a+yHQPd9+RybW2l7sJv26nkUH5Z 5s84P6894ebgimcprJdAkjJTgprl1nhgvptU5M9Uv85Pferoh2groQEAtRPlCGrZ2/2qVNe9 XJfSYbiyedvApWcJs5DOByTaKkcAEQEAAcLAkwQYAQgAJhYhBKydJ7mEpsswrWYaaO6FXats 4kSgBQJdJbQnAhsMBQkDwmcAACEJEO6FXats4kSgFiEErJ0nuYSmyzCtZhpo7oVdq2ziRKD3 twf7BAQBZ8TqR812zKAD7biOnWIJ0McV72PFBxmLIHp24UVe0ZogtYMxSWKLg3csh0yLVwc7 H3vldzJ9AoK3Qxp0Q6K/rDOeUy3HMqewQGcqrsRRh0NXDIQk5CgSrZslPe47qIbe3O7ik/MC q31FNIAQJPmKXX25B115MMzkSKlv4udfx7KdyxHrTSkwWZArLQiEZj5KG4cCKhIoMygPTA3U yGaIvI/BGOtHZ7bEBVUCFDFfOWJ26IOCoPnSVUvKPEOH9dv+sNy7jyBsP5QxeTqwxC/1ZtNS DUCSFQjqA6bEGwM22dP8OUY6SC94x1G81A9/xbtm9LQxKm0EiDH8KBMLfQ== Message-ID: <2fbf4c72-5039-62f7-bd7e-0fcc2180a7e5@suse.de> Date: Fri, 11 Sep 2020 07:32:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200910202612.GH18149@tucnak> Content-Language: en-US X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" [ was: Re: [committed][nvptx] Fix printing of 128-bit constant ] On 9/10/20 10:26 PM, Jakub Jelinek wrote: > On Thu, Sep 10, 2020 at 09:31:33PM +0200, Tom de Vries wrote: >> Currently, for this code from c-c++-common/spec-barrier-1.c: >> ... >> __int128 g = 9; >> ... >> we generate: >> ... >> // BEGIN GLOBAL VAR DEF: g >> .visible .global .align 8 .u64 g[2] = { 9, 9 }; >> ... >> and consequently the test-case fails in execution. >> >> The problem is caused by a shift in nvptx_assemble_value: >> ... >> val >>= part * BITS_PER_UNIT; >> ... >> where the shift amount is equal to the number of bits in val, which is >> undefined behaviour. >> >> Fix this by detecting the situation and setting val to 0. > > Actually, looking more at it, is nvptx_assemble_value called from > nvptx_assemble_integer with the CONST_INT and size of 16? > Then > val &= ((unsigned HOST_WIDE_INT)2 << (size * BITS_PER_UNIT - 1)) - 1; > will invoke UB too (perhaps it can just do: > if (size * BITS_PER_UNIT < HOST_BITS_PER_WIDE_INT) > val &= HOST_WIDE_INT_1U << (size * BITS_PER_UNIT); > ?), and also, TImode CONST_INTs are considered signed, i.e. > you want value of -1 rather than 0 if the MSB (of the original value before > any shifting) is set. > And, will it only ever trigger == equality of the part, or could it e.g. > emit it even in more fragments and have the shift count > > HOST_BITS_PER_WIDE_INT? > So check what you get for > __int128 h = -9; Negative __int128 indeed had a problem as well. Fixed in patch below, committed. Thanks, - Tom [nvptx] Fix printing of 128-bit constant (negative case) For this code: ... __int128 min_one = -1; ... we currently generate: ... .visible .global .align 8 .u64 min_one[2] = { -1, 0 }; ... Fix this in nvptx_assemble_value, such that we have instead: ... .visible .global .align 8 .u64 min_one[2] = { -1, -1 }; ... gcc/ChangeLog: * config/nvptx/nvptx.c (nvptx_assemble_value): Handle negative __int128. gcc/testsuite/ChangeLog: * gcc.target/nvptx/int128.c: New test. --- gcc/config/nvptx/nvptx.c | 5 ++++- gcc/testsuite/gcc.target/nvptx/int128.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c index ffcbe591a8f..4fca0ed76d9 100644 --- a/gcc/config/nvptx/nvptx.c +++ b/gcc/config/nvptx/nvptx.c @@ -2050,13 +2050,16 @@ output_init_frag (rtx sym) static void nvptx_assemble_value (unsigned HOST_WIDE_INT val, unsigned size) { + bool negative_p + = val & (HOST_WIDE_INT_1U << (HOST_BITS_PER_WIDE_INT - 1)); + val &= ((unsigned HOST_WIDE_INT)2 << (size * BITS_PER_UNIT - 1)) - 1; for (unsigned part = 0; size; size -= part) { if (part * BITS_PER_UNIT == HOST_BITS_PER_WIDE_INT) /* Avoid undefined behaviour. */ - val = 0; + val = negative_p ? -1 : 0; else val >>= (part * BITS_PER_UNIT); part = init_frag.size - init_frag.offset; diff --git a/gcc/testsuite/gcc.target/nvptx/int128.c b/gcc/testsuite/gcc.target/nvptx/int128.c new file mode 100644 index 00000000000..069dbbfe12b --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/int128.c @@ -0,0 +1,15 @@ +/* { dg-do run } */ +/* { dg-additional-options "-Wno-pedantic" } */ + +__int128 one = 1; +__int128 min_one = -1; +__int128 zero = 0; + +int +main (void) +{ + if (zero - one != min_one) + __builtin_abort (); + + return 0; +}