From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 918733858C83; Wed, 9 Mar 2022 08:13:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 918733858C83 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7556] simplify-rtx: Fix up SUBREG_PROMOTED_SET arguments [PR104839] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 2ab70a4a5c2d5a9ffb923f13b1c3b938c60dd0f0 X-Git-Newrev: 7ca24ae5701769fccabf8cca4cad6987cb2187c6 Message-Id: <20220309081356.918733858C83@sourceware.org> Date: Wed, 9 Mar 2022 08:13:56 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Mar 2022 08:13:56 -0000 https://gcc.gnu.org/g:7ca24ae5701769fccabf8cca4cad6987cb2187c6 commit r12-7556-g7ca24ae5701769fccabf8cca4cad6987cb2187c6 Author: Jakub Jelinek Date: Wed Mar 9 09:12:38 2022 +0100 simplify-rtx: Fix up SUBREG_PROMOTED_SET arguments [PR104839] 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). 2022-03-09 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. Diff: --- gcc/simplify-rtx.cc | 4 +-- gcc/testsuite/gcc.c-torture/execute/pr104839.c | 37 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc index 3355b1a07e3..5d4939c9206 100644 --- a/gcc/simplify-rtx.cc +++ b/gcc/simplify-rtx.cc @@ -1527,7 +1527,7 @@ simplify_context::simplify_unary_operation_1 (rtx_code code, machine_mode mode, 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_operation_1 (rtx_code code, machine_mode mode, if (partial_subreg_p (temp)) { SUBREG_PROMOTED_VAR_P (temp) = 1; - SUBREG_PROMOTED_SET (temp, 0); + SUBREG_PROMOTED_SET (temp, SRP_UNSIGNED); } return temp; } diff --git a/gcc/testsuite/gcc.c-torture/execute/pr104839.c b/gcc/testsuite/gcc.c-torture/execute/pr104839.c new file mode 100644 index 00000000000..1703df64083 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr104839.c @@ -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; +}