From patchwork Fri Aug 4 10:15:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 131068 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp158101vqb; Fri, 4 Aug 2023 03:16:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGsm+RlRN6xgQzp4k+8ZmkH9YYxNDvu7tX0tVi/ngMxBZ2HlJ/E0aI72lD/PwAhQbRjvMyy X-Received: by 2002:a17:906:5191:b0:99c:a2ca:4f54 with SMTP id y17-20020a170906519100b0099ca2ca4f54mr1231986ejk.34.1691144180875; Fri, 04 Aug 2023 03:16:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691144180; cv=none; d=google.com; s=arc-20160816; b=IN9t6GXG228Vir8LV2AYxvP0bWALk2pwch2aKx7VJBfDEj9MRttPvQTsQSb58SarEb nUfXmc+v5Yy94Y4pLxUpmHTPPzevfq0FUgarHYi+wU1gNIAb4PD2UfeeCva9X+uUSNQu 122YlvgFfdVI5s/+8ivMdpYib8eYWy4c3b+aYCCE0xCa8J58xmPhH7mGyKqRCVuYXO80 dJctomNell10xWsnF1FufN3tL3vH+0g190EuccSz+nAVKnUbxdaImbOtDM71qtTr2vEK lhEyrBG7PQZuazRQafI6A83dd45J3nUcmfxGIk9Yx3TWzYHzXn+mX+2r4gZowYF+8D0X a9/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=wfqnJTzsvQ++9EdmP0cY1Svu1glcrUwCRY1eNScZQvE=; fh=etb9MYHN7HLF/sff76ICVdPeKiI8ZsjoOL2bcdG0aog=; b=w042mrZcg5qtfqNqnD1HoxNUktJu1qW7hhP9TP06q5IAFJJsw9v9qZDgwKHeO7Mko6 +KSTzgNu+zLbPXRFEqN9Cwobyiwnntkp++2/cCxhnPuQD3tUdGKjgk9UKKH3sy4tZcA8 DRtlV8PZxrEeab7XjXNHctIUbTAtMdy8/50Ja0ZjmGReVjJpaAhsfBH+jJZ4xTst6M4a +iHHkz+aepzzMwBNZcrd217Vatpt8l+EVEY+tTD+zMVYxASvUw49qFu0gR4wyKYB+JDT ox0+cW5hmeBEshvZn6CUZOPLMqhL6CgljvNGDFvYf50e8UybvUqmZ0S9w8KYOkfvgpdn KNzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=G2buZQzP; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id jt23-20020a170906ca1700b00988c552332fsi306225ejb.300.2023.08.04.03.16.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 03:16:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=G2buZQzP; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C68C8385770A for ; Fri, 4 Aug 2023 10:16:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C68C8385770A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691144179; bh=wfqnJTzsvQ++9EdmP0cY1Svu1glcrUwCRY1eNScZQvE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=G2buZQzPdfrlQGziIHjKmvByCIwtl7Z9kqifYISRw+578OscZhcoHZqFga3mnRo37 r4ipoAZHjWC5KMhSI4sigQ/yr05I/SDv1lbPNj4E2vxefe8pZCb437P4uOL2zkwAS0 UZJKMCuUa9jRioJdXWRaeD4hU+2rvF2blv4zRc9M= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id C52E33858C2D for ; Fri, 4 Aug 2023 10:15:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C52E33858C2D Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D260A21889 for ; Fri, 4 Aug 2023 10:15:37 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C02F313904 for ; Fri, 4 Aug 2023 10:15:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ekO+LcnPzGSGLgAAMHmgww (envelope-from ) for ; Fri, 04 Aug 2023 10:15:37 +0000 Date: Fri, 4 Aug 2023 12:15:37 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/110838 - less aggressively fold out-of-bound shifts MIME-Version: 1.0 Message-Id: <20230804101537.C02F313904@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773293200682018576 X-GMAIL-MSGID: 1773293200682018576 The following adjusts the shift simplification patterns to avoid touching out-of-bound shift value arithmetic right shifts of possibly negative values. While simplifying those to zero isn't wrong it's violating the principle of least surprise. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/110838 * match.pd (([rl]shift @0 out-of-bounds) -> zero): Restrict the arithmetic right-shift case to non-negative operands. --- gcc/match.pd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gcc/match.pd b/gcc/match.pd index 53e622bf28f..a1a82a5f954 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1064,6 +1064,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (shift @0 uniform_integer_cst_p@1) (if ((GIMPLE || !sanitize_flags_p (SANITIZE_SHIFT_EXPONENT)) + /* Leave arithmetic right shifts of possibly negative values alone. */ + && (TYPE_UNSIGNED (type) + || shift == LSHIFT_EXPR + || tree_expr_nonnegative_p (@0)) /* Use a signed compare to leave negative shift counts alone. */ && wi::ges_p (wi::to_wide (uniform_integer_cst_p (@1)), element_precision (type)))