Message ID | Y4cmlqFFMt3p7Nz8@tucnak |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp826589wrr; Wed, 30 Nov 2022 01:48:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf6pC5Z4b+mRb7oXya12Yb6lLY874yyoq4UDuIMZeo33DXQUbLDTWCFmC4PSNmsM/LE4Pmj7 X-Received: by 2002:a17:906:2404:b0:7ad:d411:30af with SMTP id z4-20020a170906240400b007add41130afmr8330614eja.636.1669801684872; Wed, 30 Nov 2022 01:48:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669801684; cv=none; d=google.com; s=arc-20160816; b=n9yAIq5R5XiLeuGs7cyxN0cLKDjkjAv9mOBk7f58kMxszVvdQxGwnSv0dL2fUewODe FQzwhN7RFm9rtnq3QKDst9q7bXOw5f1DEbQfIzkDyaEe94wqgBq2uT3sRatZIM4kalyz j5BwfuhNcN0MKacmmzpuA/do+h/Qgx2yAEQQ1B8DeHlwcGqwaY/mt7N4tdvhUJT9eDil w73NaU5wbFdbEaX+REP7RZ3eH/Ne2YSOvKtLmDh4G0PNnEc44JXWoWW0aPZGracVTL3R dz1PgxvNsspZWRXHUD54feKJqBKai8RItVlNnqACcepDmRVHqNi4bBMrePlnzJZS2GAi Wqrw== 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-transfer-encoding:content-disposition:mime-version :message-id:subject:cc:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=N1upMGQvhW5JnT+ZIrePvTGvQ6wFM4XDOP/V5snR1jg=; b=Hq/md3H2pgLNd79xRpM68zkmEkGDbSzrG7wHb0K24kvvL/tVGfJSlwVPt9F9Dzc4F8 3sQGDrexx4lPeGyQ6VGJ/lsOiz/UgmTmhJr5pMZDbP6RlgLr7fXzAHS14Yvd+lLlP2Wm slKsPsIdjTmQ5kHCNGN7/V3SfWTLmtFGo2gaS9luWvcUSmo+1+cRlhpQGq/QjAbcduHG B154ZSjoSJzTW4FZwn7abcxCB4T5rjSCVobco2q8UjQZzki03J/9sYm6cd+NcEMvcUYo KwXZHpQOaR6ubxDozZds/2yNuJ5GALc472Cil5WSKeiKnrm5DPyYBSr8c2OTpFDTPEGG oI0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CUBv9soK; 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 cw20-20020a170906479400b0078db1258ae9si1019065ejc.555.2022.11.30.01.48.04 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 01:48:04 -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=CUBv9soK; 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 A7B71385840C for <ouuuleilei@gmail.com>; Wed, 30 Nov 2022 09:48:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A7B71385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669801683; bh=N1upMGQvhW5JnT+ZIrePvTGvQ6wFM4XDOP/V5snR1jg=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=CUBv9soKO5iQfFkTHlhMyGSpb0tu8YIqEVPIXax5zZ7bPA0jcxIAlXQEr/cQyzUZq nn9qQT/xk9NGvfSObmJQqOlqg+lx/fl27KzR+B+rwZckSTB393qZrEYMe70XHaT1dB qmgdqui7n0PUjmDQdDI/s6XlsysytAlj5wFM1jpg= 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 474063858D28 for <gcc-patches@gcc.gnu.org>; Wed, 30 Nov 2022 09:47:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 474063858D28 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-613-Gq9PCXWqOqinylaA3KlP_A-1; Wed, 30 Nov 2022 04:47:09 -0500 X-MC-Unique: Gq9PCXWqOqinylaA3KlP_A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4F898101AA47; Wed, 30 Nov 2022 09:47:09 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 057A31121314; Wed, 30 Nov 2022 09:47:08 +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 2AU9l3tt1863035 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 30 Nov 2022 10:47:04 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2AU9l2Z41863034; Wed, 30 Nov 2022 10:47:02 +0100 Date: Wed, 30 Nov 2022 10:47:02 +0100 To: Richard Biener <rguenther@suse.de>, Roger Sayle <roger@nextmovesoftware.com> Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-chrec: Fix up ICE on pointer multiplication [PR107835] Message-ID: <Y4cmlqFFMt3p7Nz8@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00, BODY_8BITS, 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Jakub Jelinek <jakub@redhat.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750913971136383432?= X-GMAIL-MSGID: =?utf-8?q?1750913971136383432?= |
Series |
tree-chrec: Fix up ICE on pointer multiplication [PR107835]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Jakub Jelinek
Nov. 30, 2022, 9:47 a.m. UTC
Hi! r13-254-gdd3c7873a61019e9 added an optimization for {a, +, a} (x-1), but as can be seen on the following testcase, the way it is written where chrec_fold_multiply is called with type doesn't work for pointers: res = build_int_cst (TREE_TYPE (x), 1); res = chrec_fold_plus (TREE_TYPE (x), x, res); res = chrec_convert_rhs (type, res, NULL); res = chrec_fold_multiply (type, chrecr, res); while what we were doing before and what is still used if the condition doesn't match is fine: res = chrec_convert_rhs (TREE_TYPE (chrecr), x, NULL); res = chrec_fold_multiply (TREE_TYPE (chrecr), chrecr, res); res = chrec_fold_plus (type, CHREC_LEFT (chrec), res); because it performs chrec_fold_multiply on TREE_TYPE (chrecr) and converts only afterwards. I think the easiest fix is to ignore the new path for pointer types. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-11-30 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/107835 * tree-chrec.cc (chrec_apply): Don't handle "{a, +, a} (x-1)" as "a*x" if type is a pointer type. * gcc.c-torture/compile/pr107835.c: New test. Jakub
Comments
On Wed, 30 Nov 2022, Jakub Jelinek wrote: > Hi! > > r13-254-gdd3c7873a61019e9 added an optimization for {a, +, a} (x-1), > but as can be seen on the following testcase, the way it is written > where chrec_fold_multiply is called with type doesn't work for pointers: > res = build_int_cst (TREE_TYPE (x), 1); > res = chrec_fold_plus (TREE_TYPE (x), x, res); > res = chrec_convert_rhs (type, res, NULL); > res = chrec_fold_multiply (type, chrecr, res); > while what we were doing before and what is still used if the condition > doesn't match is fine: > res = chrec_convert_rhs (TREE_TYPE (chrecr), x, NULL); > res = chrec_fold_multiply (TREE_TYPE (chrecr), chrecr, res); > res = chrec_fold_plus (type, CHREC_LEFT (chrec), res); > because it performs chrec_fold_multiply on TREE_TYPE (chrecr) and converts > only afterwards. > > I think the easiest fix is to ignore the new path for pointer types. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK. Thanks, Richard. > 2022-11-30 Jakub Jelinek <jakub@redhat.com> > > PR tree-optimization/107835 > * tree-chrec.cc (chrec_apply): Don't handle "{a, +, a} (x-1)" > as "a*x" if type is a pointer type. > > * gcc.c-torture/compile/pr107835.c: New test. > > --- gcc/tree-chrec.cc.jj 2022-05-10 18:33:14.641029951 +0200 > +++ gcc/tree-chrec.cc 2022-11-29 15:24:41.810400368 +0100 > @@ -622,7 +622,8 @@ chrec_apply (unsigned var, > /* "{a, +, b} (x)" -> "a + b*x". */ > else if (operand_equal_p (CHREC_LEFT (chrec), chrecr) > && TREE_CODE (x) == PLUS_EXPR > - && integer_all_onesp (TREE_OPERAND (x, 1))) > + && integer_all_onesp (TREE_OPERAND (x, 1)) > + && !POINTER_TYPE_P (type)) > { > /* We know the number of iterations can't be negative. > So {a, +, a} (x-1) -> "a*x". */ > --- gcc/testsuite/gcc.c-torture/compile/pr107835.c.jj 2022-11-29 15:31:32.565382590 +0100 > +++ gcc/testsuite/gcc.c-torture/compile/pr107835.c 2022-11-29 15:31:15.795628304 +0100 > @@ -0,0 +1,11 @@ > +/* PR tree-optimization/107835 */ > + > +int * > +foo (void) > +{ > + int *x = 0; > + unsigned n = n; > + for (; n; --n, ++x) > + ; > + return x; > +} > > Jakub > >
--- gcc/tree-chrec.cc.jj 2022-05-10 18:33:14.641029951 +0200 +++ gcc/tree-chrec.cc 2022-11-29 15:24:41.810400368 +0100 @@ -622,7 +622,8 @@ chrec_apply (unsigned var, /* "{a, +, b} (x)" -> "a + b*x". */ else if (operand_equal_p (CHREC_LEFT (chrec), chrecr) && TREE_CODE (x) == PLUS_EXPR - && integer_all_onesp (TREE_OPERAND (x, 1))) + && integer_all_onesp (TREE_OPERAND (x, 1)) + && !POINTER_TYPE_P (type)) { /* We know the number of iterations can't be negative. So {a, +, a} (x-1) -> "a*x". */ --- gcc/testsuite/gcc.c-torture/compile/pr107835.c.jj 2022-11-29 15:31:32.565382590 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr107835.c 2022-11-29 15:31:15.795628304 +0100 @@ -0,0 +1,11 @@ +/* PR tree-optimization/107835 */ + +int * +foo (void) +{ + int *x = 0; + unsigned n = n; + for (; n; --n, ++x) + ; + return x; +}