From patchwork Fri Feb 3 18:59:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 52635 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1039309wrn; Fri, 3 Feb 2023 12:16:34 -0800 (PST) X-Google-Smtp-Source: AK7set8xbYDUSzMprIeUnk7bAhSw5u+B2mgIlkZ78SGk/8FkNv0Gt6yxozmuqGyD8X/6z8JnnjOj X-Received: by 2002:a17:906:5181:b0:885:5e22:c038 with SMTP id y1-20020a170906518100b008855e22c038mr11374209ejk.33.1675455394216; Fri, 03 Feb 2023 12:16:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675455394; cv=none; d=google.com; s=arc-20160816; b=Kp3MY3AefDtGHXCnTZa+AIA2XzJZGDXhD2IFy3HomwvJGLqG5U1GFL+ciJiTs+pvVa 2ie3xIN0QTeNwQqBPzYGg4e++xjSOmfFHK/m5p3VTA27LhfHT+eNH7uctVxKSLJ9IDwq Yll7zvtg48glGKgzZA5L+2BSu8j5X19aoM3eOiw9v/lZEXC62czSi99NutchkA7uvyoY YEpDxjMAPZ6vUfeFeWsyeyz3cpSJKPuualW/bTKgZqCxZ271GVJQY6m28Xr2YcJEiFV6 iBEV9SW+JWF40zDLI0UpIgb0hVk0D2iE0359Q6XaGU+H179OZV36e28RZ3zfzg/Fnj2g 0sJQ== 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-disposition:mime-version:message-id:subject:cc:to:date :resent-to:resent-message-id:resent-date:resent-from:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=H5pODeunGHnQIJ+XCQ2abBHLivEQuFSS+pp1XQUEhnU=; b=cgJQUiKY+KDkYumovfvnfU+M2JOTcNhN2QFdrecdiUtUTrCF0AJTk4ASmibomUscCB M9gzAxYpvHTTrUn+1op7NFvENxlKeu3opKeNjkl5ztqmJM38vkMEGLuhIZcoLkb2OlMz UqLKUkqpV9JNpnbP7mhtEf17XtuIFg4o+O0iBbSvSLaUP4Sr+H27Ko3cBMJqR+6iZg4Y BSBdE3zQnny1KtFgDoVocnbROOAXJB1zGB2amjMDdaV9FDaTbZDyhYf2A5D8ty0TqUuR GocGJg4H+9wzw6p+NCJckJ+wXOpPfre3Og7Dw4/8hZrcLugqVGWmmZ0rVL4qI/wkNICj igQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uIxKlI6H; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id et15-20020a170907294f00b0088e2f1b2df0si3222769ejc.752.2023.02.03.12.16.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 12:16:34 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uIxKlI6H; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 5FA2F3887F54 for ; Fri, 3 Feb 2023 20:15:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FA2F3887F54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675455321; bh=H5pODeunGHnQIJ+XCQ2abBHLivEQuFSS+pp1XQUEhnU=; h=Resent-From:Resent-Date:Resent-To:Date:To:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=uIxKlI6H6jr+I7fWldsV6ezA4m34zp8tBj7N4GR6+OrkFKBlpXK3K3ykO71X9EAiR oGMUmB1axsvVf4qdIJhkK4oLZTNS8JjOPs8I5VBrzvobCRsHRIrposEDgp1LzIDHW7 7ybVFA0imJjidNtFyVgwFz002IaIuPj6z3NQtHSQ= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id A6D63385417F for ; Fri, 3 Feb 2023 20:13:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A6D63385417F Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-539-vt-lycaJMYifhD0hqxLYuQ-1; Fri, 03 Feb 2023 15:13:49 -0500 X-MC-Unique: vt-lycaJMYifhD0hqxLYuQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BFB1D85A5A3 for ; Fri, 3 Feb 2023 20:13:48 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8036940149B6; Fri, 3 Feb 2023 20:13:48 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 313KDkT81415124 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 3 Feb 2023 21:13:46 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 313KDj2g1415123; Fri, 3 Feb 2023 21:13:45 +0100 Resent-From: Jakub Jelinek Resent-Date: Fri, 3 Feb 2023 21:13:45 +0100 Resent-Message-ID: Resent-To: Aldy Hernandez , Andrew MacLeod , gcc-patches@gcc.gnu.org Date: Fri, 3 Feb 2023 19:59:39 +0100 To: Aldy Hernandez , Andrew MacLeod Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] range-op: Handle op?.undefined_p () in op[12]_range of comparisons [PR108647] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek 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?1756842315315997152?= X-GMAIL-MSGID: =?utf-8?q?1756842315315997152?= Hi! As mentioned in the PR, we ICE because lhs is singleton [0, 0] or [1, 1] but op2 (or in other cases op1) is undefined and op?.*_bound () ICEs on those because there are no pairs for UNDEFINED. The following patch makes us set r to varying or return false in those cases. Included is a version of the patch I've bootstrapped/regtested successfully on x86_64-linux and i686-linux, attached is a slight modification more consistent with the range-op-float.cc patch. Ok for trunk (and which one)? 2023-02-03 Jakub Jelinek PR tree-optimization/108647 * range-op.cc (operator_equal::op1_range, operator_not_equal::op1_range): Don't test op2 bound equality if op2.undefined_p (), instead set_varying. (operator_lt::op1_range, operator_le::op1_range, operator_gt::op1_range, operator_ge::op1_range): Return false if op2.undefined_p (). (operator_lt::op2_range, operator_le::op2_range, operator_gt::op2_range, operator_ge::op2_range): Return false if op1.undefined_p (). * g++.dg/torture/pr108647.C: New test. Jakub 2023-02-03 Jakub Jelinek PR tree-optimization/108647 * range-op.cc (operator_equal::op1_range, operator_not_equal::op1_range): Don't test op2 bound equality if op2.undefined_p (), instead set_varying. (operator_lt::op1_range, operator_le::op1_range, operator_gt::op1_range, operator_ge::op1_range): Return false if op2.undefined_p (). (operator_lt::op2_range, operator_le::op2_range, operator_gt::op2_range, operator_ge::op2_range): Return false if op1.undefined_p (). * g++.dg/torture/pr108647.C: New test. --- gcc/range-op.cc.jj 2023-02-03 10:51:40.699003658 +0100 +++ gcc/range-op.cc 2023-02-03 19:43:28.082326069 +0100 @@ -642,7 +642,8 @@ operator_equal::op1_range (irange &r, tr case BRS_FALSE: // If the result is false, the only time we know anything is // if OP2 is a constant. - if (wi::eq_p (op2.lower_bound(), op2.upper_bound())) + if (!op2.undefined_p () + && wi::eq_p (op2.lower_bound(), op2.upper_bound())) { r = op2; r.invert (); @@ -755,7 +756,8 @@ operator_not_equal::op1_range (irange &r case BRS_TRUE: // If the result is true, the only time we know anything is if // OP2 is a constant. - if (wi::eq_p (op2.lower_bound(), op2.upper_bound())) + if (!op2.undefined_p () + && wi::eq_p (op2.lower_bound(), op2.upper_bound())) { r = op2; r.invert (); @@ -923,10 +925,14 @@ operator_lt::op1_range (irange &r, tree switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: + if (op2.undefined_p ()) + return false; build_lt (r, type, op2.upper_bound ()); break; case BRS_FALSE: + if (op2.undefined_p ()) + return false; build_ge (r, type, op2.lower_bound ()); break; @@ -945,10 +951,14 @@ operator_lt::op2_range (irange &r, tree switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: + if (op1.undefined_p ()) + return false; build_gt (r, type, op1.lower_bound ()); break; case BRS_FALSE: + if (op1.undefined_p ()) + return false; build_le (r, type, op1.upper_bound ()); break; @@ -1034,10 +1044,14 @@ operator_le::op1_range (irange &r, tree switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: + if (op2.undefined_p ()) + return false; build_le (r, type, op2.upper_bound ()); break; case BRS_FALSE: + if (op2.undefined_p ()) + return false; build_gt (r, type, op2.lower_bound ()); break; @@ -1056,10 +1070,14 @@ operator_le::op2_range (irange &r, tree switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: + if (op1.undefined_p ()) + return false; build_ge (r, type, op1.lower_bound ()); break; case BRS_FALSE: + if (op1.undefined_p ()) + return false; build_lt (r, type, op1.upper_bound ()); break; @@ -1144,10 +1162,14 @@ operator_gt::op1_range (irange &r, tree switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: + if (op2.undefined_p ()) + return false; build_gt (r, type, op2.lower_bound ()); break; case BRS_FALSE: + if (op2.undefined_p ()) + return false; build_le (r, type, op2.upper_bound ()); break; @@ -1166,10 +1188,14 @@ operator_gt::op2_range (irange &r, tree switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: + if (op1.undefined_p ()) + return false; build_lt (r, type, op1.upper_bound ()); break; case BRS_FALSE: + if (op1.undefined_p ()) + return false; build_ge (r, type, op1.lower_bound ()); break; @@ -1255,10 +1281,14 @@ operator_ge::op1_range (irange &r, tree switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: + if (op2.undefined_p ()) + return false; build_ge (r, type, op2.lower_bound ()); break; case BRS_FALSE: + if (op2.undefined_p ()) + return false; build_lt (r, type, op2.upper_bound ()); break; @@ -1277,10 +1307,14 @@ operator_ge::op2_range (irange &r, tree switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: + if (op1.undefined_p ()) + return false; build_le (r, type, op1.upper_bound ()); break; case BRS_FALSE: + if (op1.undefined_p ()) + return false; build_gt (r, type, op1.lower_bound ()); break; --- gcc/testsuite/g++.dg/torture/pr108647.C.jj 2023-02-03 16:36:18.347255058 +0100 +++ gcc/testsuite/g++.dg/torture/pr108647.C 2023-02-03 16:32:16.338811259 +0100 @@ -0,0 +1,25 @@ +// PR tree-optimization/108647 +// { dg-do compile } + +bool a; +int b, c; + +inline const bool & +foo (bool &e, const bool &f) +{ + return f < e ? f : e; +} + +void +bar (signed char e, bool *f, bool *h, bool *g) +{ + for (;;) + if (g) + for (signed char j = 0; j < 6; + j += ((f[0] & c ? g[0] : int(0 >= e)) + ? 0 : foo (g[0], g[0] > h[0]) + 1)) + { + a = 0; + b = 0; + } +} --- gcc/range-op.cc.jj 2023-02-03 10:51:40.699003658 +0100 +++ gcc/range-op.cc 2023-02-03 17:26:02.204429931 +0100 @@ -642,7 +642,8 @@ operator_equal::op1_range (irange &r, tr case BRS_FALSE: // If the result is false, the only time we know anything is // if OP2 is a constant. - if (wi::eq_p (op2.lower_bound(), op2.upper_bound())) + if (!op2.undefined_p () + && wi::eq_p (op2.lower_bound(), op2.upper_bound())) { r = op2; r.invert (); @@ -755,7 +756,8 @@ operator_not_equal::op1_range (irange &r case BRS_TRUE: // If the result is true, the only time we know anything is if // OP2 is a constant. - if (wi::eq_p (op2.lower_bound(), op2.upper_bound())) + if (!op2.undefined_p () + && wi::eq_p (op2.lower_bound(), op2.upper_bound())) { r = op2; r.invert (); @@ -920,6 +922,9 @@ operator_lt::op1_range (irange &r, tree const irange &op2, relation_trio) const { + if (op2.undefined_p ()) + return false; + switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: @@ -942,6 +947,9 @@ operator_lt::op2_range (irange &r, tree const irange &op1, relation_trio) const { + if (op1.undefined_p ()) + return false; + switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: @@ -1031,6 +1039,9 @@ operator_le::op1_range (irange &r, tree const irange &op2, relation_trio) const { + if (op2.undefined_p ()) + return false; + switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: @@ -1053,6 +1064,9 @@ operator_le::op2_range (irange &r, tree const irange &op1, relation_trio) const { + if (op1.undefined_p ()) + return false; + switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: @@ -1141,6 +1155,9 @@ operator_gt::op1_range (irange &r, tree const irange &lhs, const irange &op2, relation_trio) const { + if (op2.undefined_p ()) + return false; + switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: @@ -1163,6 +1180,9 @@ operator_gt::op2_range (irange &r, tree const irange &op1, relation_trio) const { + if (op1.undefined_p ()) + return false; + switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: @@ -1252,6 +1272,9 @@ operator_ge::op1_range (irange &r, tree const irange &op2, relation_trio) const { + if (op2.undefined_p ()) + return false; + switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: @@ -1274,6 +1297,9 @@ operator_ge::op2_range (irange &r, tree const irange &op1, relation_trio) const { + if (op1.undefined_p ()) + return false; + switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: --- gcc/testsuite/g++.dg/torture/pr108647.C.jj 2023-02-03 16:36:18.347255058 +0100 +++ gcc/testsuite/g++.dg/torture/pr108647.C 2023-02-03 16:32:16.338811259 +0100 @@ -0,0 +1,25 @@ +// PR tree-optimization/108647 +// { dg-do compile } + +bool a; +int b, c; + +inline const bool & +foo (bool &e, const bool &f) +{ + return f < e ? f : e; +} + +void +bar (signed char e, bool *f, bool *h, bool *g) +{ + for (;;) + if (g) + for (signed char j = 0; j < 6; + j += ((f[0] & c ? g[0] : int(0 >= e)) + ? 0 : foo (g[0], g[0] > h[0]) + 1)) + { + a = 0; + b = 0; + } +}