From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675455234; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-to:resent-from:resent-message-id; bh=H5pODeunGHnQIJ+XCQ2abBHLivEQuFSS+pp1XQUEhnU=; b=fA7nlb4Kj8bU02oowMo5TgMyJVHKwmasoXeAfTzP8a9RgKTHKX3yZHVY2UrHwvXz0743Vd FkNgudyXvZXfxQGHjS+p1rOT/H26v4V+OivsOID27+mMAbP+l508SjXdTWUa/A2YKn2wSH RbJ+4yRxpgMUJld/eMMZb+DFICN2Sc8= 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 From: Jakub Jelinek 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: Reply-To: Jakub Jelinek 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-Type: multipart/mixed; boundary="S4M1tPMQKZpZ08Y1" 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 List-Id: --S4M1tPMQKZpZ08Y1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. --- 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; + } +} Jakub --S4M1tPMQKZpZ08Y1 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=R782a 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; + } +} --S4M1tPMQKZpZ08Y1--