From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id 722223858CDA for ; Wed, 9 Nov 2022 17:21:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 722223858CDA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ispras.ru Received: from [10.10.3.121] (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTPS id 50740419E9FC; Wed, 9 Nov 2022 17:21:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 50740419E9FC Date: Wed, 9 Nov 2022 20:21:33 +0300 (MSK) From: Alexander Monakov To: Philipp Tomsich cc: gcc-patches@gcc.gnu.org, Vineet Gupta , Kito Cheng , Jojo R , Jeff Law Subject: Re: [PATCH] riscv: implement TARGET_MODE_REP_EXTENDED In-Reply-To: Message-ID: References: <20220905214437.1275139-1-philipp.tomsich@vrull.eu> <4bc6d821-21d3-764c-269a-8f822257dd33@ispras.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, 9 Nov 2022, Philipp Tomsich wrote: > > To give a specific example that will be problematic if you go far enough down > > the road of matching MIPS64 behavior: > > > > long f(void) > > { > > int x; > > asm("" : "=r"(x)); > > return x; > > } > > > > here GCC (unlike LLVM) omits sign extension of 'x', assuming that asm output > > must have been sign-extended to 64 bits by the programmer. > > In fact, with the proposed patch (but also without it), GCC will sign-extend: > f: > sext.w a0,a0 > ret > .size f, .-f I'm aware. I said "will be problematic if ...", meaning that GCC omits sign extension when targeting MIPS64, and if you match MIPS64 behavior on RISC-V, you'll get in that situation as well. > To make sure that this is not just an extension to promote the int to > long for the function return, I next added another empty asm to > consume 'x'. > This clearly shows that the extension is performed to postprocess the > output of the asm-statement: > > f: > # ./asm2.c:4: asm("" : "=r"(x)); > sext.w a0,a0 # x, x > # ./asm2.c:5: asm("" : : "r"(x)); > # ./asm2.c:7: } > ret No, you cannot distinguish post-processing the output of the first asm vs. pre-processing the input of the second asm. Try asm("" : "+r"(x)); as the second asm instead, and you'll get f: # t.c:17: asm("" : "=r"(x)); # t.c:18: asm("" : "+r"(x)); # t.c:20: } sext.w a0,a0 #, x ret If it helps, here's a Compiler Explorer link comparing with MIPS64: https://godbolt.org/z/7eobvdKdK Alexander