From patchwork Thu Jan 19 20:04:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 63419 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 59A803858421 for ; Thu, 19 Jan 2023 20:05:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 59A803858421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674158703; bh=h+QETljPNdvkQxGGuNtDyy0eIC6Djs77rzQlVjLNqA0=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=NF4OKRBlRTXLMBfGZjJRSOL349KOBC9lWDXgN4OzAExf3obREI9/mhCd5PnctR6Dp RnfYeE4lQOisXfyxA5Ej6bAUcjz8e/P6ZGR6VVMDKLaGqvK1kocjmI/6s1dBdcjndS xNUP3UDZj/J314lClsoYpa3LaJ5ccPAcjsa2xYXw= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id C3D203858291 for ; Thu, 19 Jan 2023 20:04:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C3D203858291 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-16-4wNuO6_aNxaj45bsuKCOGw-1; Thu, 19 Jan 2023 15:04:32 -0500 X-MC-Unique: 4wNuO6_aNxaj45bsuKCOGw-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 172EA3C1069E; Thu, 19 Jan 2023 20:04:32 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB6C440C2064; Thu, 19 Jan 2023 20:04:31 +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 30JK4SDr3366224 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 19 Jan 2023 21:04:29 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 30JK4RUP3366223; Thu, 19 Jan 2023 21:04:27 +0100 Date: Thu, 19 Jan 2023 21:04:27 +0100 To: gcc-patches@gcc.gnu.org Cc: Tobias Burnus Subject: [committed] openmp: Fix up OpenMP expansion of non-rectangular loops [PR108459] 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.8 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! expand_omp_for_init_counts was using for the case where collapse(2) inner loop has init expression dependent on non-constant multiple of the outer iterator and the condition upper bound expression doesn't depend on the outer iterator fold_unary (NEGATE_EXPR, ...). This will just return NULL if it can't be folded, we need fold_build1 instead. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2023-01-19 Jakub Jelinek PR middle-end/108459 * omp-expand.cc (expand_omp_for_init_counts): Use fold_build1 rather than fold_unary for NEGATE_EXPR. * testsuite/libgomp.c/pr108459.c: New test. Jakub --- gcc/omp-expand.cc.jj 2023-01-02 09:32:49.399894958 +0100 +++ gcc/omp-expand.cc 2023-01-19 12:01:05.103410564 +0100 @@ -2003,8 +2003,8 @@ expand_omp_for_init_counts (struct omp_f t = fold_build2 (MINUS_EXPR, itype, unshare_expr (fd->loops[i].m2), unshare_expr (fd->loops[i].m1)); else if (fd->loops[i].m1) - t = fold_unary (NEGATE_EXPR, itype, - unshare_expr (fd->loops[i].m1)); + t = fold_build1 (NEGATE_EXPR, itype, + unshare_expr (fd->loops[i].m1)); else t = unshare_expr (fd->loops[i].m2); tree m2minusm1 --- libgomp/testsuite/libgomp.c/pr108459.c.jj 2023-01-19 12:22:07.191038771 +0100 +++ libgomp/testsuite/libgomp.c/pr108459.c 2023-01-19 12:21:17.973755215 +0100 @@ -0,0 +1,41 @@ +/* PR middle-end/108459 */ + +char a[17][17]; + +__attribute__((noipa)) void +foo (int x, int y) +{ + #pragma omp for collapse(2) + for (int i = 1; i <= 16; i++) + for (int j = i * x + y; j <= 16; j++) + a[i][j] = 1; +} + +int +main () +{ + #pragma omp parallel + foo (1, 1); + for (int i = 0; i <= 16; i++) + for (int j = 0; j <= 16; j++) + if (i >= 1 && j >= i + 1) + { + if (a[i][j] != 1) + __builtin_abort (); + a[i][j] = 0; + } + else if (a[i][j]) + __builtin_abort (); + #pragma omp parallel + foo (2, -2); + for (int i = 0; i <= 16; i++) + for (int j = 0; j <= 16; j++) + if (i >= 1 && j >= 2 * i - 2) + { + if (a[i][j] != 1) + __builtin_abort (); + } + else if (a[i][j]) + __builtin_abort (); + return 0; +}