From patchwork Wed Oct 26 13:49:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1694974 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=U2xJXhlv; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4My9DM1kVRz20S2 for ; Thu, 27 Oct 2022 00:50:11 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6886D385D0E9 for ; Wed, 26 Oct 2022 13:50:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6886D385D0E9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666792208; bh=Got71Tebf0O572ePlzNuahy/QMXOHz80YLEl4BNAUr0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=U2xJXhlvoMhkTTyUAQcw3mk1xp+4sPXj2zguS98sxLJT9unIl5T3P89UrnChA+xqQ BtvcNe8apy5I72IoU9g06LjXDYNgEwNApAyCL/YFjE0cUM7DmLDI3SwOiSSkzJl6yK tnKVxslZl92pi9xWmtan5BO/SfjE3itWFI8UmjIE= 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 47939385D0CD for ; Wed, 26 Oct 2022 13:49:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 47939385D0CD Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-322-lKzvq-kRODei7mwN21XeOw-1; Wed, 26 Oct 2022 09:49:41 -0400 X-MC-Unique: lKzvq-kRODei7mwN21XeOw-1 Received: by mail-il1-f197.google.com with SMTP id i8-20020a056e0212c800b002f9a4c75658so13402803ilm.3 for ; Wed, 26 Oct 2022 06:49:40 -0700 (PDT) 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=OAfPAEFYjzVVHaDjTOrdJd9KhPWlitfvhIUMsU5AY20=; b=ljomEnZpNkrdNrfsViJoqujzqRdCnnTqRIjVM6ZSOhSRdejJrYl9PApVtHOiEffkEA 0cVD/DVwGWXOljfy/DFemPAIcmrpkOENNCbZ0QIZM4jKK2JXb/dbWrXlkE7I/5JTD/bk AouP5+DmZhaceCR6iLj0sO18aDydN3pJh9bvPTgUf2iApOfjfjuPqFe8Y/S/LVLfw8cM 6cZyZGLJOyhlj8QErwAyRg891lJswxDY6NkmC762zG1Yy1OZ3co9BZrcPa3eABxarPrG lOnVn4wuR3GW2imjMYCnfRntsNtWeVWwf5aeJ3HxPiDmdDE/siUzIrVKtNe9R5N5xCAS 9Oqw== X-Gm-Message-State: ACrzQf2rybamtdr2fiQc2yuOu0wS3prtJryjUJXGOlkMV+R5GEl2AkUi 0ngxKewK6vZijmaWF5bu4XQTuEXAPbxFOGoFBl9DYr6PDca+GfxJG8OAQZnV4Bwr/tC9vzVDRLA /75cF4zeIL6B4WTUaljagkAgYqAJXMMeVe57D6whTEEIlermd5gMvJi9eaQIQ87U/JblU9A== X-Received: by 2002:a05:6638:3391:b0:374:1739:3795 with SMTP id h17-20020a056638339100b0037417393795mr9034291jav.87.1666792178551; Wed, 26 Oct 2022 06:49:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Y0XaRve/VdUh3rPm8jitRih7idOqGmrRNHNgES23oIMrc4KsqJGq91KfXLW3ZZysnZwN5jw== X-Received: by 2002:a05:6638:3391:b0:374:1739:3795 with SMTP id h17-20020a056638339100b0037417393795mr9034276jav.87.1666792178290; Wed, 26 Oct 2022 06:49:38 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::72c3? ([2607:fea8:a263:f600::72c3]) by smtp.gmail.com with ESMTPSA id p10-20020a056638216a00b003635a42d653sm1960175jak.134.2022.10.26.06.49.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Oct 2022 06:49:37 -0700 (PDT) Message-ID: Date: Wed, 26 Oct 2022 09:49:36 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 To: gcc-patches Subject: [COMMITTED] Check if varying may also be non-negative. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.7 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" When strict enums are in use, we don't always get ranges reduced sufficiently thru casts and such.  Ranger vrp has been missing the odd case because I didn't notice that gimple_stmt_nonnegative_warnv_p() use to be called on all integral results that were varying, not just calls like it was doing. this corrects that. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew commit a87819b8f1b890d36a3f05bd9de80be20e9525dd Author: Andrew MacLeod Date: Tue Oct 25 15:16:47 2022 -0400 Check if varying may also be non-negative. When using strict enums, we can sometimes turn varying into a better range. * gimple-range-fold.cc (fold_using_range::fold_stmt): Check if stmt is non-negative and adjust the range. diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index f91923782dc..a899d8260b3 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -494,6 +494,14 @@ fold_using_range::fold_stmt (vrange &r, gimple *s, fur_source &src, tree name) else if (is_a (s) && gimple_assign_rhs_code (s) == COND_EXPR) res = range_of_cond_expr (r, as_a (s), src); + // If the result is varying, check for basic nonnegativeness. + // Specifically this helps for now with strict enum in cases like + // g++.dg/warn/pr33738.C. + bool so_p; + if (res && r.varying_p () && INTEGRAL_TYPE_P (r.type ()) + && gimple_stmt_nonnegative_warnv_p (s, &so_p)) + r.set_nonnegative (r.type ()); + if (!res) { // If no name specified or range is unsupported, bail.