From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id A10C83858C83 for ; Tue, 8 Mar 2022 15:57:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A10C83858C83 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-587-8-a6evv6MaW3AjtOkxJDKw-1; Tue, 08 Mar 2022 10:56:56 -0500 X-MC-Unique: 8-a6evv6MaW3AjtOkxJDKw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B71B807353; Tue, 8 Mar 2022 15:56:55 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9FD18866D2; Tue, 8 Mar 2022 15:56:54 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 228FupRf3931793 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 8 Mar 2022 16:56:52 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 228FuoHr3931792; Tue, 8 Mar 2022 16:56:50 +0100 Date: Tue, 8 Mar 2022 16:56:50 +0100 From: Jakub Jelinek To: Richard Biener , Jeff Law Cc: gcc-patches@gcc.gnu.org, Roger Sayle Subject: [PATCH] simplify-rtx: Fix up SUBREG_PROMOTED_SET arguments [PR104839] Message-ID: Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: Tue, 08 Mar 2022 15:57:03 -0000 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? 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