From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id 5B1AD385842C; Sun, 4 Jun 2023 21:03:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B1AD385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685912633; bh=gsSyMRYag67RuuqTe+lwhCBJBsdWpdecPOp3I3+7Xng=; h=From:To:Subject:Date:From; b=G1Mri0MDBsC6UZFLQ1cQA8y1IgIhh28ACfpBXghwi+5I7q9NlARs/r0eedmKuAWkF 9NJqcIP8/nq/AZh3f3xER3VdZOuF3sz3lboRhuDZgQrxBGSWMi5tfAYpUEahmAKo0O ch7k+Xl26MCY947nJecA6FXESiy4T8oXYQB6lpWg= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-1535] Improve do_store_flag for comparing single bit against that bit X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 908e5ab5c11c64ce92f1aa6e12d571ff5eb9d72a X-Git-Newrev: 6cf856f873c1a2ab39d8fb0a93b5f4505a22feb6 Message-Id: <20230604210353.5B1AD385842C@sourceware.org> Date: Sun, 4 Jun 2023 21:03:53 +0000 (GMT) List-Id: https://gcc.gnu.org/g:6cf856f873c1a2ab39d8fb0a93b5f4505a22feb6 commit r14-1535-g6cf856f873c1a2ab39d8fb0a93b5f4505a22feb6 Author: Andrew Pinski Date: Thu May 18 22:17:07 2023 +0000 Improve do_store_flag for comparing single bit against that bit This is a case which I noticed while working on the previous patch. Sometimes we end up with `a == CST` instead of comparing against 0. This happens in the following code: ``` unsigned f(unsigned t) { if (t & ~(1<<30)) __builtin_unreachable(); t ^= (1<<30); return t != 0; } ``` We should handle the case where the nonzero bits is the same as the comparison operand. Changes from v1: * v2: Updated for the bit extraction changes. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * expr.cc (do_store_flag): Improve for single bit testing not against zero but against that single bit. Diff: --- gcc/expr.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gcc/expr.cc b/gcc/expr.cc index 6027e7ffca5..58f5fe76372 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -13159,12 +13159,15 @@ do_store_flag (sepops ops, rtx target, machine_mode mode) than an scc insn even if we have it. */ if ((code == NE || code == EQ) - && integer_zerop (arg1) + && (integer_zerop (arg1) + || integer_pow2p (arg1)) && (TYPE_PRECISION (ops->type) != 1 || TYPE_UNSIGNED (ops->type))) { wide_int nz = tree_nonzero_bits (arg0); - if (wi::popcount (nz) == 1) + if (wi::popcount (nz) == 1 + && (integer_zerop (arg1) + || wi::to_wide (arg1) == nz)) { tree op0; int bitnum; @@ -13182,7 +13185,9 @@ do_store_flag (sepops ops, rtx target, machine_mode mode) op0 = arg0; bitnum = wi::exact_log2 (nz); } - enum tree_code tcode = code == NE ? NE_EXPR : EQ_EXPR; + enum tree_code tcode = EQ_EXPR; + if ((code == NE) ^ !integer_zerop (arg1)) + tcode = NE_EXPR; type = lang_hooks.types.type_for_mode (mode, unsignedp); return expand_single_bit_test (loc, tcode,