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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id B61FF398B8A6 for ; Wed, 14 Jul 2021 22:15:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B61FF398B8A6 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-265-X8vcKjUuMsWjR-60fop5nw-1; Wed, 14 Jul 2021 18:15:24 -0400 X-MC-Unique: X8vcKjUuMsWjR-60fop5nw-1 Received: by mail-qt1-f198.google.com with SMTP id d11-20020ac851cb0000b02902536d2bea0fso2786294qtn.19 for ; Wed, 14 Jul 2021 15:15:24 -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:from:subject:message-id:date:user-agent :mime-version:content-language; bh=RT1+9V8+GEoMacE4jzQiCeBaQT/rRhvwJuAzGHnvkZo=; b=uCfwINrs3P0SUgZ8ZdPsgNdcX0o/HoOa8yfexzCXnknXdztc6tuNyBWkwh/CZThZhm WHF/1I8u5K7upd5Ori14+h77lBd0pQarwgM2JA2yY/E3ouNzrONF0rZb+aJmG1vvuRtT 6M+ivoprx0/e/f0eb/JAlMaEDQ2bGr7HEW3qPjF8p1lIizioJqfye+RSZ8By1z0qpn1b m2YplqszpCNMSXT8CuGMpDpgF6Bp1uonmn7TguxAh+3z/vstNpPPBWlFqMyd6SiK33wR RegUuu99EX8yjNjch3IKwBf5lB9Yn1Nw6WEuwNADNDnpMbNH0Z5HFxcnSKfjCAkjI6VZ 2kVA== X-Gm-Message-State: AOAM5325cDVMqZ2BGTu7d6XgauvGv0QMt8PDtVoDpXllZzsFv6WE6Oyy Gp3KKHCPSEm2ObsB4CZTo0UyrIUGkpMqfOaYPAHzy4mi4SItspBeWwste43SWYuUrtbmcsadNEw Ide4rDwI77k2yM6d85oQzWmanpx6uSiPwsD5gLMyLqOt/wJ/144pbULBPsvObq5lgisUUdA== X-Received: by 2002:a05:6214:20ef:: with SMTP id 15mr339165qvk.54.1626300924072; Wed, 14 Jul 2021 15:15:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRvHyxEP9yWhL0XgP9H8TXWa+V8XUgXrpdeMGG42whBZzF7s30Y68cPmdAs6+sDs4TFhnlAw== X-Received: by 2002:a05:6214:20ef:: with SMTP id 15mr339147qvk.54.1626300923866; Wed, 14 Jul 2021 15:15:23 -0700 (PDT) Received: from [192.168.0.102] ([104.219.122.163]) by smtp.gmail.com with ESMTPSA id i21sm514632qtw.68.2021.07.14.15.15.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Jul 2021 15:15:23 -0700 (PDT) To: gcc-patches From: Andrew MacLeod Subject: [GCC 11] [COMMITTED] Fix build_gt and build_lt for signed 1 bit values. Message-ID: Date: Wed, 14 Jul 2021 18:15:22 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="------------D91B9AE2A9E991EF97CF12BC" Content-Language: en-CA X-Spam-Status: No, score=-12.2 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_H4, 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-List-Received-Date: Wed, 14 Jul 2021 22:15:28 -0000 This is a multi-part message in MIME format. --------------D91B9AE2A9E991EF97CF12BC Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Cherry picked from 84f7bab89279ca1234fef88929c74caeda8cb55e Bootstrapped on x86_64-pc-linux-gnu with no regressions. pushed. Andrew --------------D91B9AE2A9E991EF97CF12BC Content-Type: text/x-patch; charset=UTF-8; name="0008-Fix-build_gt-and-build_lt-for-signed-1-bit-values.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0008-Fix-build_gt-and-build_lt-for-signed-1-bit-values.patch" >From b977e6b29c67be81df882d1f5cc7eb6a5d8c98a0 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 30 Jun 2021 14:15:53 -0400 Subject: [PATCH 8/8] Fix build_gt and build_lt for signed 1 bit values. Signed 1 bit values have a range of [-1, 0] but neither (0 - 1) nor (-1 + 1) can be represented. For signed values, add or subtract -1 as appropriate. PR tree-optimization/101223 gcc/ * range-op.cc (build_lt): Add -1 for signed values. (built_gt): Subtract -1 for signed values. gcc/testsuite/ * gcc.dg/pr101223.c: New. (cherry picked from commit 84f7bab89279ca1234fef88929c74caeda8cb55e) --- gcc/range-op.cc | 18 ++++++++++++-- gcc/testsuite/gcc.dg/pr101223.c | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr101223.c diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 3a35a2fb25b..c33f4edc2c1 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -562,7 +562,14 @@ static void build_lt (irange &r, tree type, const wide_int &val) { wi::overflow_type ov; - wide_int lim = wi::sub (val, 1, TYPE_SIGN (type), &ov); + wide_int lim; + signop sgn = TYPE_SIGN (type); + + // Signed 1 bit cannot represent 1 for subtraction. + if (sgn == SIGNED) + lim = wi::add (val, -1, sgn, &ov); + else + lim = wi::sub (val, 1, sgn, &ov); // If val - 1 underflows, check if X < MIN, which is an empty range. if (ov) @@ -585,7 +592,14 @@ static void build_gt (irange &r, tree type, const wide_int &val) { wi::overflow_type ov; - wide_int lim = wi::add (val, 1, TYPE_SIGN (type), &ov); + wide_int lim; + signop sgn = TYPE_SIGN (type); + + // Signed 1 bit cannot represent 1 for addition. + if (sgn == SIGNED) + lim = wi::sub (val, -1, sgn, &ov); + else + lim = wi::add (val, 1, sgn, &ov); // If val + 1 overflows, check is for X > MAX, which is an empty range. if (ov) r.set_undefined (); diff --git a/gcc/testsuite/gcc.dg/pr101223.c b/gcc/testsuite/gcc.dg/pr101223.c new file mode 100644 index 00000000000..6d5a247fa6c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr101223.c @@ -0,0 +1,44 @@ +/* PR tree-optimization/101223 */ +/* { dg-do run } */ +/* { dg-options "-O2 " } */ + +struct { + int a : 1; +} b; +int c = 1, d; +int foo1() { + for (; d < 2; d++) { + int e = ~c, f = 0, g; + if (e) { + f = c; + g = b.a; + b.a = f; + if (b.a >= g) + __builtin_abort(); + } + c = f; + b.a = g; + } + return 0; +} + +int foo2() { + for (; d < 2; d++) { + int e = ~c, f = 0, g; + if (e) { + f = c; + g = b.a; + b.a = f; + if (g <= b.a) + __builtin_abort(); + } + c = f; + b.a = g; + } + return 0; +} +int main () +{ + return foo1() + foo2(); +} + -- 2.17.2 --------------D91B9AE2A9E991EF97CF12BC--