From patchwork Fri Jul 30 19:12:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1511770 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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: 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=vHTIDRHl; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GbxsJ49Y9z9sS8 for ; Sat, 31 Jul 2021 05:14:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5975A397B833 for ; Fri, 30 Jul 2021 19:14:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5975A397B833 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1627672449; bh=TPAAeeOKwhKvNvTa6xdKUbFoXEdSBqI2mX/Bj74utAA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=vHTIDRHlRS6s15JlIf1Dei4AcmG9tGHgUfJyyyBARwIQOKRXtwJrXRfAen596vayZ 45FeKL0M4uSITPuYCD8dMoei8d7gujZb1gThT4uNYPmvWozBgexCP0jLTIPN0dq/VE z8d7h5m9yYcwV7bYoSQGKRYJuKcFNHPGHilqFR+Q= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 127BB397EC19 for ; Fri, 30 Jul 2021 19:12:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 127BB397EC19 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-351-oArYuVs8OdSznLllB4A13A-1; Fri, 30 Jul 2021 15:12:39 -0400 X-MC-Unique: oArYuVs8OdSznLllB4A13A-1 Received: by mail-qv1-f72.google.com with SMTP id v19-20020ad455530000b029032620cab853so6657388qvy.8 for ; Fri, 30 Jul 2021 12:12:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=TPAAeeOKwhKvNvTa6xdKUbFoXEdSBqI2mX/Bj74utAA=; b=HcDmYC05bOlFe+E6PVCDg1VkFfTd6ZjvUV46qvn/7b8PLwt1mjllsik4hTqkcqac99 kd0lITD409rxCmgtVlq6cevPk0gAg1gOmy94LiKfYqWR4dFwHsY9I8vjqwD5Vt0xhU3U 6JPElpLewZVidF05ZGDRAKu0F7EIwtThS+YnukY3LzSH5BypXIn32+EGSujonHBYQK23 liplV5EOV0pqQAhhb2JRlPPwyrF6ZN9ks+rBCye8/pSpGjayQQ4Lh/Pwnbt+Rrnicpw0 ZHh7oMPmN1EEHdNfFhRwrTuojG46myFTABbnw48d+RKQzB+PE9uhAFEklBWfGb9VWr2Q tKsw== X-Gm-Message-State: AOAM533FOV8ESjMByiSZTdHQ19mBNvOouGIUGFMSFRQ7vJYBCECTPhVE lAKvGxJ5dVZEP5fPriod+FUr+B3CKpPFHG/j3tZGMdJhNl8VpyMYoZGnSoV6TOtdZy1s35yVLrX fZFNiLFDQ60ib+KrVrQ== X-Received: by 2002:a05:620a:120e:: with SMTP id u14mr3698734qkj.309.1627672359163; Fri, 30 Jul 2021 12:12:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzlfiYdRoqGD/d2zGSb0Y7K7HhewB0Jziwu/QeeBTGghXP3JiuMNTt5+UjvSU1zAHGh4Z0Fg== X-Received: by 2002:a05:620a:120e:: with SMTP id u14mr3698721qkj.309.1627672359021; Fri, 30 Jul 2021 12:12:39 -0700 (PDT) Received: from [192.168.0.102] ([104.219.123.55]) by smtp.gmail.com with ESMTPSA id 18sm1405210qkv.118.2021.07.30.12.12.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 30 Jul 2021 12:12:38 -0700 (PDT) To: gcc-patches Subject: [COMMITTED] Change integral divide by zero to produce UNDEFINED range. Message-ID: Date: Fri, 30 Jul 2021 15:12:37 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-12.4 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_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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" This patch changes divide by 0 to produce an UNDEFINED range rather than VARYING.   This can help in propagating values by ignoring / 0 results rather than bailing. Bootstrapped on x86_64-pc-linux-gnu and powerpc64-unknown-linux-gnu with no regressions.  Pushed. Andrew From ebbcdd7fae1f802763850e4afedfdfa09cf10e1a Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 28 Jul 2021 13:14:22 -0400 Subject: [PATCH 2/3] Change integral divide by zero to produce UNDEFINED. Instead of VARYING, we can get better results by treating divide by zero as producing an undefined result. gcc/ * range-op.cc (operator_div::wi_fold): Return UNDEFINED for [0, 0] divisor. gcc/testsuite/ * gcc.dg/tree-ssa/pr61839_2.c: Adjust. --- gcc/range-op.cc | 9 +-------- gcc/testsuite/gcc.dg/tree-ssa/pr61839_2.c | 3 +-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index b1fb25c77f8..69228882930 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1785,13 +1785,6 @@ operator_div::wi_fold (irange &r, tree type, const wide_int &lh_lb, const wide_int &lh_ub, const wide_int &rh_lb, const wide_int &rh_ub) const { - // If we know we will divide by zero... - if (rh_lb == 0 && rh_ub == 0) - { - r.set_varying (type); - return; - } - const wide_int dividend_min = lh_lb; const wide_int dividend_max = lh_ub; const wide_int divisor_min = rh_lb; @@ -1818,7 +1811,7 @@ operator_div::wi_fold (irange &r, tree type, // If we're definitely dividing by zero, there's nothing to do. if (wi_zero_p (type, divisor_min, divisor_max)) { - r.set_varying (type); + r.set_undefined (); return; } diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr61839_2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr61839_2.c index cfec54de991..f1b8feb4e9d 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr61839_2.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr61839_2.c @@ -45,9 +45,8 @@ int bar2 () return 0; } - /* Dont optimize 972195717 / 0 in function foo. */ -/* { dg-final { scan-tree-dump-times "972195717 / " 1 "evrp" } } */ +/* { dg-final { scan-tree-dump-times "972195717 / " 0 "evrp" } } */ /* Dont optimize 972195717 % 0 in function bar. */ /* { dg-final { scan-tree-dump-times "972195717 % " 1 "evrp" } } */ /* May optimize in function bar2, but EVRP doesn't perform this yet. */ -- 2.17.2