From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 7BD953858C20 for ; Wed, 9 Mar 2022 07:15:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7BD953858C20 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 2CBCE210F3; Wed, 9 Mar 2022 07:15:43 +0000 (UTC) Received: from murzim.suse.de (murzim.suse.de [10.160.4.192]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 03F20A3B83; Wed, 9 Mar 2022 07:15:43 +0000 (UTC) Date: Wed, 9 Mar 2022 08:15:42 +0100 (CET) From: Richard Biener To: Jakub Jelinek cc: Jeff Law , gcc-patches@gcc.gnu.org, Roger Sayle Subject: Re: [PATCH] simplify-rtx: Fix up SUBREG_PROMOTED_SET arguments [PR104839] In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-List-Received-Date: Wed, 09 Mar 2022 07:15:46 -0000 On Tue, 8 Mar 2022, Jakub Jelinek wrote: > Hi! > > The following testcase is miscompiled on powerpc64le-linux at -O1 and higher > (except for -Og). The bug was introduced in r12-3252-gcad36f38576a6a7 > which for SIGN_EXTEND from SUBREG_PROMOTED_SIGNED_P SUBREG used > SUBREG_PROMOTED_SET (temp, 1) (but that makes temp > SUBREG_PROMOTED_UNSIGNED_P because SRP_UNSIGNED is 1) and similarly the > ZERO_EXTEND from SUBREG_PROMOTED_UNSIGNED_P SUBREG used > SUBREG_PROMOTED_SET (temp, 0) (but that makes temp > SUBREG_PROMOTED_SIGNED_P because SRP_SIGNED is 0). > The following patch fixes that (swaps the 0s and 1s), but for better > readability uses the SRP_* constants. > rtl.h has: > /* Valid for subregs which are SUBREG_PROMOTED_VAR_P(). In that case > this gives the necessary extensions: > 0 - signed (SPR_SIGNED) > 1 - normal unsigned (SPR_UNSIGNED) > 2 - value is both sign and unsign extended for mode > (SPR_SIGNED_AND_UNSIGNED). > -1 - pointer unsigned, which most often can be handled like unsigned > extension, except for generating instructions where we need to > emit special code (ptr_extend insns) on some architectures > (SPR_POINTER). */ > The expr.c change in the same commit looks ok to me (passes unsignedp > to SUBREG_PROMOTED_SET, so 0 for signed, 1 for unsigned). > > Starting bootstrap/regtest on powerpc64{,le}-linux now, ok for trunk? OK. > 2022-03-08 Jakub Jelinek > > PR rtl-optimization/104839 > * simplify-rtx.cc (simplify_unary_operation_1) : > Use SRP_SIGNED instead of incorrect 1 in SUBREG_PROMOTED_SET. > (simplify_unary_operation_1) : Use SRP_UNSIGNED > instead of incorrect 0 in SUBREG_PROMOTED_SET. > > * gcc.c-torture/execute/pr104839.c: New test. > > --- gcc/simplify-rtx.cc.jj 2022-02-23 09:17:04.000000000 +0100 > +++ gcc/simplify-rtx.cc 2022-03-08 16:31:20.823246404 +0100 > @@ -1527,7 +1527,7 @@ simplify_context::simplify_unary_operati > if (partial_subreg_p (temp)) > { > SUBREG_PROMOTED_VAR_P (temp) = 1; > - SUBREG_PROMOTED_SET (temp, 1); > + SUBREG_PROMOTED_SET (temp, SRP_SIGNED); > } > return temp; > } > @@ -1662,7 +1662,7 @@ simplify_context::simplify_unary_operati > if (partial_subreg_p (temp)) > { > SUBREG_PROMOTED_VAR_P (temp) = 1; > - SUBREG_PROMOTED_SET (temp, 0); > + SUBREG_PROMOTED_SET (temp, SRP_UNSIGNED); > } > return temp; > } > --- gcc/testsuite/gcc.c-torture/execute/pr104839.c.jj 2022-03-08 16:46:51.418440078 +0100 > +++ gcc/testsuite/gcc.c-torture/execute/pr104839.c 2022-03-08 16:46:27.044774203 +0100 > @@ -0,0 +1,37 @@ > +/* PR rtl-optimization/104839 */ > + > +__attribute__((noipa)) short > +foo (void) > +{ > + return -1; > +} > + > +__attribute__((noipa)) int > +bar (void) > +{ > + short i = foo (); > + if (i == -2) > + return 2; > + long k = i; > + int j = -1; > + volatile long s = 300; > + if (k < 0) > + { > + k += s; > + if (k < 0) > + j = 0; > + } > + else if (k >= s) > + j = 0; > + if (j != -1) > + return 1; > + return 0; > +} > + > +int > +main () > +{ > + if (bar () != 0) > + __builtin_abort (); > + return 0; > +} > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Ivo Totev; HRB 36809 (AG Nuernberg)