From patchwork Mon Jan 23 23:21:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 47464 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1865216wrn; Mon, 23 Jan 2023 15:22:30 -0800 (PST) X-Google-Smtp-Source: AMrXdXtj2OVvRi+FH6nq0zbUcjG70vXnjC17rq6t+kIcfyYe4Bwn0WQ1ZT8+xa5Ij3PJGQEeWHWO X-Received: by 2002:a17:907:a2cb:b0:870:7b:94db with SMTP id re11-20020a170907a2cb00b00870007b94dbmr32295330ejc.28.1674516150590; Mon, 23 Jan 2023 15:22:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674516150; cv=none; d=google.com; s=arc-20160816; b=rSaw5bXU7wnA6vC0t4d/QNIolWWUirVDLUPBUdI0l1C69emOiDw932+fvRDFTYhj3Z TMAlT4Hpa6ldRXQPyk/BO7p9R9DFAiHQOuvKpxnx8SBZvn+LGhulImy+QCJ0jrr+cETx kUA6zRjoXvMLGrW2baM/3GJoF77gW7sMrOOgcqoqDkaAlbFBMopiDnwlVTHPupKWXvJi Y4Z0Dr9kQz5EWN6TiOa06dTPuW4lg1Pjexv1/wezuTcVE6fBuENnSvyP7Jivji1jHN4t 1Bvs5MdQE0zlGcsyfswvrqb8vaiMOESazId/XjBUVmPVZxMkOjhC6GwEukGuaqlr0ERY GHFw== 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:content-language :subject:cc:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=etQpLv9QsgsZGBkOe4kvXyQvoj8IvrS0pj0vww7TNiA=; b=vIn77WhOaCWuNs3WOOWWJQoWok0p+E7tGHJSRHR7fHSTr6G4vrUKe3tvAnlxExM2eX QjOk1iMMzN6AHguhYjRKkDOD/padZs2bC4hSUyRbyomJWoaEFeerxWGSPqwT7RFH2cLF CUMQwECNZcvgJs+p75cgfcO6ys1e+WPq0dZ2U/m6a9q5mlNoN3HDYgJwHqtNkH/R16Ny yFstNEh0Fx78TmZ8J/TcYtwr80H5Qpebnb9cMhSxRS4OJq9nkdWsnwJtAZLXjPJnoOpg Y+owVHinIaGxYh7C/SjR9BF4xuq+jEOYlE9z1c6/HTUE/f9Th80yoIvkCz0IxiLyclIu Iy3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YSLx5AFo; 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 sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ka22-20020a170907921600b0087122fab4bcsi233654ejb.153.2023.01.23.15.22.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 15:22:30 -0800 (PST) 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=YSLx5AFo; 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 91B4D3858D3C for ; Mon, 23 Jan 2023 23:22:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 91B4D3858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674516149; bh=etQpLv9QsgsZGBkOe4kvXyQvoj8IvrS0pj0vww7TNiA=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=YSLx5AFoautqSdA7QvIALRFWjMAfMKN1lgn5e25+MC5MLf7/IpvkvLZKugC23CU5L MI4ufuucHhBYYw5vVgv/dYrDkCUtTcCLqvXdyw0dEyeeNklFXqjafY0u+HTLpnWoMP l8guYfleQL2WoWTi0Y4PoWG6mPcocqNmCdf8ShEE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 954293858D33 for ; Mon, 23 Jan 2023 23:21:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 954293858D33 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-606-ajZM1FPQOMOGrl5np0UYbw-1; Mon, 23 Jan 2023 18:21:40 -0500 X-MC-Unique: ajZM1FPQOMOGrl5np0UYbw-1 Received: by mail-qv1-f70.google.com with SMTP id kr11-20020a0562142b8b00b005355b472a65so6006517qvb.7 for ; Mon, 23 Jan 2023 15:21:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nKLqQtEqNQE2zaO9D5tXZozZjdNyOFwxfmLfNQfVXUs=; b=h4lVMI8so6RHLsxmZVTj7UFPuPEYcHww+k/hUjrmU9/EyVeoRvuK0Tw1tBvh9v6oqW 0sQ3QChy41o9zWWTCyLhjWeMVfny4m/AXFrYr4fjNHxqjUbHQDO0Y1sU1jaFX461wDxP X7jakYUzLVNlQ5ZeQg98nC114+UfsRIOGQki4e2rQc/lRRYoOrSG1SYuRI2+VDGq/0j+ DzRsOPdrGMxaOX1aH5mVqQq7A4nFS5FDD/UKKxu4GBQFBnRVUBlM9U2jmqxOc5bWA7rV Z+QRbhDwhDx0SJ+PuAttla6nLCgvCub+8mbrO9g8yqqlGKfdZyS72uiZaIRp5r4+lZIv 26bA== X-Gm-Message-State: AFqh2kq92ontZYMdu6ZRha14RzlA7UESkd63GL+TiV0ooDotPoHQ+nm1 PjeXgoyFuDGKlkH8el/8gO1htq/a4s372lr7wG32q/pKJj6snvH9DyXo4G8ZXPqkbY48Pmk6N2E QX38DB3hdNIswo7JQBcdQVhtpI5Qtxs1rC2AEheeLpL5XZjeH7eKmUf3rEqCFkKFDVGMg9Q== X-Received: by 2002:ac8:4a0a:0:b0:3b6:2d6d:3546 with SMTP id x10-20020ac84a0a000000b003b62d6d3546mr37538252qtq.64.1674516099847; Mon, 23 Jan 2023 15:21:39 -0800 (PST) X-Received: by 2002:ac8:4a0a:0:b0:3b6:2d6d:3546 with SMTP id x10-20020ac84a0a000000b003b62d6d3546mr37538224qtq.64.1674516099468; Mon, 23 Jan 2023 15:21:39 -0800 (PST) Received: from ?IPV6:2607:fea8:a263:f600::27bf? ([2607:fea8:a263:f600::27bf]) by smtp.gmail.com with ESMTPSA id l24-20020ac848d8000000b003b64f1b1f40sm178730qtr.40.2023.01.23.15.21.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Jan 2023 15:21:38 -0800 (PST) Message-ID: <7030d247-5453-2344-2ee6-33899e52ed08@redhat.com> Date: Mon, 23 Jan 2023 18:21:37 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 To: gcc-patches Cc: "hernandez, aldy" Subject: [PATCH] tree-optimization/108306 - Correctly detect shifts out of range X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755857446845526819?= X-GMAIL-MSGID: =?utf-8?q?1755857446845526819?= get_shift_range was incorrectly communicating that it couldn't calculate a range when the shift value was out of range. Fix this and always return a range of [0, 0] instead of varying when the shift value is out of range. Bootstraps with no regressions on x86_64-pc-linux-gnu.  OK for trunk? Andrew From 5500762bacffd7b45a0bfa8f89333e955734820f Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 16 Jan 2023 15:02:51 -0500 Subject: [PATCH 3/3] Correctly detect shifts out of range get_shift_range was incorrectly communicating that it couldn't calculate a range when the shift values was always out fo range. Fix this and alwasy return [0, 0] when the shift value is always out of range. PR tree-optimization/108306 gcc/ * range-op.cc (operator_lshift::fold_range): Return [0, 0] not varying for shifts that are always out of void range. (operator_rshift::fold_range): Return [0, 0] not varying for shifts that are always out of void range. gcc/testsuite/ * gcc.dg/pr108306.c: New. --- gcc/range-op.cc | 4 ++-- gcc/testsuite/gcc.dg/pr108306.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr108306.c diff --git a/gcc/range-op.cc b/gcc/range-op.cc index ec75e07bc8a..6e5754e9130 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -2166,7 +2166,7 @@ operator_lshift::fold_range (irange &r, tree type, if (op2.undefined_p ()) r.set_undefined (); else - r.set_varying (type); + r.set_zero (type); return true; } @@ -2440,7 +2440,7 @@ operator_rshift::fold_range (irange &r, tree type, if (op2.undefined_p ()) r.set_undefined (); else - r.set_varying (type); + r.set_zero (type); return true; } diff --git a/gcc/testsuite/gcc.dg/pr108306.c b/gcc/testsuite/gcc.dg/pr108306.c new file mode 100644 index 00000000000..1044c646de7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108306.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-strict-overflow -fsanitize=shift -Warray-bounds" } */ + +enum psi_task_count { + NR_IOWAIT, + NR_PSI_TASK_COUNTS = 4, +}; + +unsigned int tasks[NR_PSI_TASK_COUNTS]; + +static void psi_group_change(unsigned int set) +{ + unsigned int t; + unsigned int state_mask = 0; + + for (t = 0; set; set &= ~(1 << t), t++) + if (set & (1 << t)) + tasks[t]++; +} + +void psi_task_switch(int sleep) +{ + int set = 0; + + if (sleep) + set |= (1 << NR_IOWAIT); + + psi_group_change(set); +} -- 2.39.0