From patchwork Fri Jan 10 06:39:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 104451 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C34EA3858C33 for ; Fri, 10 Jan 2025 06:41:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C34EA3858C33 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=HLxV2aB2 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-vs1-xe31.google.com (mail-vs1-xe31.google.com [IPv6:2607:f8b0:4864:20::e31]) by sourceware.org (Postfix) with ESMTPS id 71C803858D20 for ; Fri, 10 Jan 2025 06:40:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 71C803858D20 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 71C803858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::e31 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736491211; cv=none; b=kMljhwlr9Xgc9/zW2LPy8Fh2fZIVVZ+iyesP/RVIgUyXmIn9kbmVLR/jXcaItDNzx+QZIp14l7xhfhhrCy/OEtZqkN7pc3Ut0xN3hIoUpwvTqRtmGQ2PguG2SQVnENmxEeahfyTA9wzudvuicaqOkkFxcOwjU/keulW/6Rm7Nb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736491211; c=relaxed/simple; bh=orD6CvBh1pqPkdzuOtwrCfab085CwVZjRAzjdXV10sg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EZvLu7lwLPx8aTFKL38hSEgkHJNLTOCPfWRxxuEkTXtEbQAIW/zgAnaAGssexlJ1BI754I6Q7WEfjfE+EZ4g0K25nhdxzW3oKt33zUCgX/95L9rPM7FKzh5KtaG8qv0epsuJBKpOq5RFvq37Q5tickmwiynaRZ5rKI5VjaCoLAE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71C803858D20 Received: by mail-vs1-xe31.google.com with SMTP id ada2fe7eead31-4aff1c57377so939986137.0 for ; Thu, 09 Jan 2025 22:40:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1736491211; x=1737096011; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=LTTVQ9lNqPGuJ+XA1BU7M4fdPkbM1n++ODQxqCWjIZ4=; b=HLxV2aB2UPZC/msNt6uC26LLFT35jIvv/lNtBKjEKS4vI2hu8Jd49ZOflsm0mp+WUD ZDfUzhgeXNjBNO5k1ib3QPaqiUE+jvdPBQRscgnCxSAaLDvhegyjKYhT8FTkvs1vqLf+ 4yf0QbfVKRtnNmURWsfvRqhRRG/jpA29T1Pwm+QJzuT4I9+5pltd/m6mm32CM7AfzTY/ kixzOk1NfSwbY5fsVBOab7nzqVcsQsJ04CQGm5VN7+kS2o9kFVFSp7K4ZOp/GuQuT7OW /M3LIqyx89jdb9RzONlibFaKCacQmcz2qFcQMFc61lD6QgJ7k/3Lh6VY7lxsStMl7dJI 0zQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736491211; x=1737096011; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LTTVQ9lNqPGuJ+XA1BU7M4fdPkbM1n++ODQxqCWjIZ4=; b=mAtq99j0vLJxcmK71PSx7RWgHzFOhHWFV3+Ow920L/N9prUzNo9sqrEhNH5703YcJ1 NBt71lQuLvqTiXBNXhei6LKVN/Y4tqZ8wVBWGFTDLazARytfA+BVTNKxLdSlQqG46LVj reGhgxdI1j7yzt6T5HHvfrxYFKNSFkdwvfC1EAtEweyXJpfxzS3nCo67ZNqEpZ1GIWZP FrS4Kwyr83kG2d/+/JnqseodmraKAJg5f63Wd7iADYt6GUHOi4F0tKfLFnFBxvBEIV6+ FThyc8OG9k+W5EI70bqsocUjYWF77nwv1rferFFOq3LZ9JneNzwvcJRjVI3CNk2rhrWY fE4Q== X-Gm-Message-State: AOJu0YzDOcp5+rWHUq/HyrzJz9oZWiT5tXturdzxZOr7GXV6Z+VhKnYj Nau1FesmLMej9LjP7WKidKLbQ50uWD6xFlNUmuKAbrf82+axNP7N3udRC5Klu2aXJELcwCBPYR8 = X-Gm-Gg: ASbGnctXtBygbWIhX0FCbGuc7pPAt465hDIV2zMZE7JF+wHYoqv4Z1bSuOLYnuC584U 8yCKKQL4QkWKL2LROIli7Z9M2Tcp7MLb20R9ruwM+xiZJbUGZSX3IYVWOoL92oMauxnIfSp2Gvq VTnRIoA7J1revxLXT76TFRStb5LOT48m+K9nGA1KssQpmg0o8Y7IRD9CyGUYgljk/agl9OZaWL9 fs7J3Q8juFbGO63c2UmyDr32UAGFAOmUxzZFTtpN6vZiaLksIpu X-Google-Smtp-Source: AGHT+IGSsaMdl2UAY+nPSgMlDusjquSi7b9zC2FBpwUHb9LO2HzsBRf6QT4bMYVF398KMQM4eEuYzw== X-Received: by 2002:a05:6102:3f4f:b0:4b5:c302:37b3 with SMTP id ada2fe7eead31-4b5c3023886mr6639127137.5.1736491210713; Thu, 09 Jan 2025 22:40:10 -0800 (PST) Received: from free.home ([2804:7f1:218b:ab6e:fda0:ed9c:e12e:80b7]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-8623154b10fsm2187611241.23.2025.01.09.22.40.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 22:40:10 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 50A6dwGk951249 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 10 Jan 2025 03:39:59 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: jakub@redhat.com, rguenther@suse.de Subject: [PATCH] [ifcombine] reuse left-hand mask to decode right-hand xor operand Organization: Free thinker, does not speak for AdaCore Date: Fri, 10 Jan 2025 03:39:58 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org If fold_truth_andor_for_ifcombine applies a mask to an xor, say because the result of the xor is compared with a power of two [minus one], we have to apply the same mask when processing both the left- and right-hand xor paths for the transformation to be sound. Arrange for decode_field_reference to propagate the incoming mask along with the expression to the right-hand operand. Don't require the right-hand xor operand to be a constant, that was a cut&pasto. Regstrapped on x86_64-linux-gnu. Ok to install? for gcc/ChangeLog * gimple-fold.cc (decode_field_reference): Add xor_pand_mask. Propagate pand_mask to the right-hand xor operand. Don't require the right-hand xor operand to be a constant. (fold_truth_andor_for_ifcombine): Pass right-hand mask when appropriate. --- gcc/gimple-fold.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index d95f04213ee40..0ad92de3a218f 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -7519,8 +7519,9 @@ gimple_binop_def_p (enum tree_code code, tree t, tree op[2]) *XOR_P is to be FALSE if EXP might be a XOR used in a compare, in which case, if XOR_CMP_OP is a zero constant, it will be overridden with *PEXP, - *XOR_P will be set to TRUE, and the left-hand operand of the XOR will be - decoded. If *XOR_P is TRUE, XOR_CMP_OP is supposed to be NULL, and then the + *XOR_P will be set to TRUE, *XOR_PAND_MASK will be copied from *PAND_MASK, + and the left-hand operand of the XOR will be decoded. If *XOR_P is TRUE, + XOR_CMP_OP and XOR_PAND_MASK are supposed to be NULL, and then the right-hand operand of the XOR will be decoded. *LOAD is set to the load stmt of the innermost reference, if any, @@ -7537,7 +7538,7 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT *pbitsize, HOST_WIDE_INT *pbitpos, bool *punsignedp, bool *preversep, bool *pvolatilep, wide_int *pand_mask, bool *psignbit, - bool *xor_p, tree *xor_cmp_op, + bool *xor_p, tree *xor_cmp_op, wide_int *xor_pand_mask, gimple **load, location_t loc[4]) { tree exp = *pexp; @@ -7599,15 +7600,14 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT *pbitsize, and_mask = *pand_mask; /* Turn (a ^ b) [!]= 0 into a [!]= b. */ - if (xor_p && gimple_binop_def_p (BIT_XOR_EXPR, exp, res_ops) - && uniform_integer_cst_p (res_ops[1])) + if (xor_p && gimple_binop_def_p (BIT_XOR_EXPR, exp, res_ops)) { /* No location recorded for this one, it's entirely subsumed by the compare. */ if (*xor_p) { exp = res_ops[1]; - gcc_checking_assert (!xor_cmp_op); + gcc_checking_assert (!xor_cmp_op && !xor_pand_mask); } else if (!xor_cmp_op) /* Not much we can do when xor appears in the right-hand compare @@ -7618,6 +7618,7 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT *pbitsize, *xor_p = true; exp = res_ops[0]; *xor_cmp_op = *pexp; + *xor_pand_mask = *pand_mask; } } @@ -8152,19 +8153,21 @@ fold_truth_andor_for_ifcombine (enum tree_code code, tree truth_type, bool l_xor = false, r_xor = false; ll_inner = decode_field_reference (&ll_arg, &ll_bitsize, &ll_bitpos, &ll_unsignedp, &ll_reversep, &volatilep, - &ll_and_mask, &ll_signbit, &l_xor, &lr_arg, + &ll_and_mask, &ll_signbit, + &l_xor, &lr_arg, &lr_and_mask, &ll_load, ll_loc); lr_inner = decode_field_reference (&lr_arg, &lr_bitsize, &lr_bitpos, &lr_unsignedp, &lr_reversep, &volatilep, - &lr_and_mask, &lr_signbit, &l_xor, 0, + &lr_and_mask, &lr_signbit, &l_xor, 0, 0, &lr_load, lr_loc); rl_inner = decode_field_reference (&rl_arg, &rl_bitsize, &rl_bitpos, &rl_unsignedp, &rl_reversep, &volatilep, - &rl_and_mask, &rl_signbit, &r_xor, &rr_arg, + &rl_and_mask, &rl_signbit, + &r_xor, &rr_arg, &rr_and_mask, &rl_load, rl_loc); rr_inner = decode_field_reference (&rr_arg, &rr_bitsize, &rr_bitpos, &rr_unsignedp, &rr_reversep, &volatilep, - &rr_and_mask, &rr_signbit, &r_xor, 0, + &rr_and_mask, &rr_signbit, &r_xor, 0, 0, &rr_load, rr_loc); /* It must be true that the inner operation on the lhs of each