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 474063858D28 for ; Wed, 30 Nov 2022 09:47:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 474063858D28 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=1669801634; 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: content-transfer-encoding:content-transfer-encoding; bh=N1upMGQvhW5JnT+ZIrePvTGvQ6wFM4XDOP/V5snR1jg=; b=EpyCJe39rzvZU+bHQ+lfFxvjVWReWRMUrmcCvJp3eKF0H7/5sL3g5n80D14WuC8RF+NEvH /ctTDzqA5N62LJAI9XjktdRNHFVUyQds1gYt6WFmCYaXL8RSIBSzvDNXPgPsjl7KpXzjZ/ 4B14x3hkNW19CA4eAY0z792pdSEP0CA= 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 From: Jakub Jelinek To: Richard Biener , Roger Sayle Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-chrec: Fix up ICE on pointer multiplication [PR107835] Message-ID: Reply-To: Jakub Jelinek 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 List-Id: 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 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