From patchwork Tue Aug 16 15:28:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:38f:b0:2d5:3c95:9e21 with SMTP id 15csp2076134pxh; Tue, 16 Aug 2022 08:29:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR7uYSvaTvk6bJn3AYGRoNaORm8M4J3sky73k9mytZIyGGSr2Ll6qzpOwm7D9AWT6jJdi9TQ X-Received: by 2002:a17:907:a218:b0:734:ca71:966e with SMTP id qp24-20020a170907a21800b00734ca71966emr13852001ejc.480.1660663758584; Tue, 16 Aug 2022 08:29:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660663758; cv=none; d=google.com; s=arc-20160816; b=lJ/6Cj5vhFpPzJoD7dyXjQKXkiQTb2YU47MpEZjHOUGdF0niau5zTMxwAjuKji5gM2 bQC7SXDK7Wcc7LgL60rrQMtMolcSxVG5PT2yJUVqLO+3lRAeVIi22aTOUr4bXr1SuR7L f/UNbZm10Zdf3U1hyppEyLmPzXHxpEEMtpbSPv7qw0evYQOGC0Mp6EiLuS3Xe3TdrUYf gOYDLRG/ONAmk90R/eoJOOU8CrBRbSLi2r5noAN/Cm4fAyZWrWz9gVNHyC46Gk7XA/6V QiXLSLxe9fK1RFCmoOYl394yzAPfLwZYTkhJloARDgx4nw/TYfNg7KBJMmBesPV0s0qI O4vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:from:to :content-language:user-agent:mime-version:date:message-id :ironport-sdr:dmarc-filter:delivered-to; bh=8PuNfMpXvN98J39feaboNoLAbnhOiYZ+9R2TKx2Rjwg=; b=o5NU3yYZNT4WxXsLOP08ywmCfI9Ea2h/+UL/xu7lx3tIU0nRS52QJnXD5KS/qkxWsb wgHpUaujA4ldSxAsSYLPyDbJ9OGeLOrVlyKC4e9w1ak0pa/4HGyytxvE6JUEyem3ZJNd h970A+uDkt00pQzcHB4q64d7ll2NEwfsz9JyBYL+oviTVjU4YsV2NOzEfvNJ6xt2N8qL dd4S9poV3YIWL/kbGPo3aojbj1D7pIVZ6q5zZ7vjEsO1tPcKswbxmWJ1c2JOce3OsMHy s8NOrlFTcoAWO1gzKeutVrSp3tMFgXaxeJuhTQaNsybpPHBFk/uTpPzKR0iiFrHbWERx TOjg== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id js17-20020a17090797d100b00732fd99cdb5si10283216ejc.854.2022.08.16.08.29.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 08:29:18 -0700 (PDT) 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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 878E23858005 for ; Tue, 16 Aug 2022 15:29:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 758863858CDA for ; Tue, 16 Aug 2022 15:28:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 758863858CDA Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.93,241,1654588800"; d="diff'?scan'208";a="81392390" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 16 Aug 2022 07:28:46 -0800 IronPort-SDR: ihTbJSgl6u3noXpJL1jNKPziOe8S309xlgRX/sofJeRLl35YaqkHmna/i27+xUOSf/CdUQ09r0 cce0+qlB3JgnGtwdT60BguGLGOuqoVCCu766J6EQqC/7kqLYAcxIppE58wVBW0iW8bT7WJRj9i qwVhb618AG+K0rNmO+V6zHnN55B2JHaQAb/FAxaNICZUB7cO3IBckVIw2ZVYkmaYGgMgFUOLpE ot+5aYltRhbMTzSzQKf0/a/CA7NFAA8l4W5icdIsDA9hcfnYQr1xSZH5iotI45L1KPLIqa/x4s USM= Message-ID: <52902f75-33c1-49c3-8e21-e6c6d1808a15@codesourcery.com> Date: Tue, 16 Aug 2022 17:28:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Content-Language: en-US To: gcc-patches , Jakub Jelinek From: Tobias Burnus Subject: [Patch] OpenMP: Fix var replacement with 'simd' and linear-step vars [PR106548] X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-13.mgc.mentorg.com (139.181.222.13) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1741332161278610994?= X-GMAIL-MSGID: =?utf-8?q?1741332161278610994?= The testcase is just a copy of linear-1 with 'omp ... for' replaced by 'omp ... for simd', matching what the PR report referred to. The problem occurs for 'omp ... for simd linear( i : step)' when 'step' is a variable when a omp_fn... is generated - as in this case, the original variable is used (in the reduced example of the PR, the PARM_DECL of 'f') instead of the replacement. OK for mainline? Thoughts on backporting (and for which versions)? Tobias ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 OpenMP: Fix var replacement with 'simd' and linear-step vars [PR106548] gcc/ChangeLog: PR middle-end/106548 * omp-low.cc (lower_rec_input_clauses): Use build_outer_var_ref for 'simd' linear-step values that are variable. libgomp/ChangeLog: PR middle-end/106548 * testsuite/libgomp.c/linear-2.c: New test. diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc index 3c4b8593c8b..d6d6ff372a1 100644 --- a/gcc/omp-low.cc +++ b/gcc/omp-low.cc @@ -6188,6 +6188,10 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, && gimple_omp_for_combined_into_p (ctx->stmt)) { tree t = OMP_CLAUSE_LINEAR_STEP (c); + if (VAR_P (t) + || TREE_CODE (t) == PARM_DECL + || TREE_CODE (t) == RESULT_DECL) + t = build_outer_var_ref (t, ctx); tree stept = TREE_TYPE (t); tree ct = omp_find_clause (clauses, OMP_CLAUSE__LOOPTEMP_); diff --git a/libgomp/testsuite/libgomp.c/linear-2.c b/libgomp/testsuite/libgomp.c/linear-2.c new file mode 100644 index 00000000000..fee6fbc276d --- /dev/null +++ b/libgomp/testsuite/libgomp.c/linear-2.c @@ -0,0 +1,251 @@ +/* PR middle-end/106548. */ +int a[256]; + +__attribute__((noinline, noclone)) int +f1 (int i) +{ + #pragma omp parallel for simd linear (i: 4) + for (int j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) short int +f2 (short int i, char k) +{ + #pragma omp parallel for simd linear (i: k + 1) + for (long j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) long long int +f3 (long long int i, long long int k) +{ + #pragma omp parallel for simd linear (i: k) + for (short j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) int +f4 (int i) +{ + #pragma omp parallel for simd linear (i: 4) schedule(static, 3) + for (int j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) short int +f5 (short int i, char k) +{ + #pragma omp parallel for simd linear (i: k + 1) schedule(static, 5) + for (long j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) long long int +f6 (long long int i, long long int k) +{ + #pragma omp parallel for simd linear (i: k) schedule(static, 7) + for (short j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) int +f7 (int i) +{ + #pragma omp parallel for simd linear (i: 4) schedule(dynamic, 3) + for (int j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) short int +f8 (short int i, char k) +{ + #pragma omp parallel for simd linear (i: k + 1) schedule(dynamic, 5) + for (long j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) long long int +f9 (long long int i, long long int k) +{ + #pragma omp parallel for simd linear (i: k) schedule(dynamic, 7) + for (short j = 16; j < 64; j++) + { + a[i] = j; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) int +f10 (int i, long step) +{ + #pragma omp parallel for simd linear (i: 4) + for (int j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) short int +f11 (short int i, char k, char step) +{ + #pragma omp parallel for simd linear (i: k + 1) + for (long j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) long long int +f12 (long long int i, long long int k, int step) +{ + #pragma omp parallel for simd linear (i: k) + for (short j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) int +f13 (int i, long long int step) +{ + #pragma omp parallel for simd linear (i: 4) schedule(static, 3) + for (int j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) short int +f14 (short int i, char k, int step) +{ + #pragma omp parallel for simd linear (i: k + 1) schedule(static, 5) + for (long j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) long long int +f15 (long long int i, long long int k, long int step) +{ + #pragma omp parallel for simd linear (i: k) schedule(static, 7) + for (short j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) int +f16 (int i, long long int step) +{ + #pragma omp parallel for simd linear (i: 4) schedule(dynamic, 3) + for (int j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) short int +f17 (short int i, char k, int step) +{ + #pragma omp parallel for simd linear (i: k + 1) schedule(dynamic, 5) + for (long j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +__attribute__((noinline, noclone)) long long int +f18 (long long int i, long long int k, long int step) +{ + #pragma omp parallel for simd linear (i: k) schedule(dynamic, 7) + for (short j = 16; j < 112; j += step) + { + a[i] = j / 2 + 8; + i += 4; + } + return i; +} + +int +main () +{ +#define TEST(x) \ + if (x != 8 + 48 * 4) \ + __builtin_abort (); \ + for (int i = 0; i < 256; i++) \ + if (a[i] != (((i & 3) == 0 && i >= 8 \ + && i < 8 + 48 * 4) \ + ? ((i - 8) / 4) + 16 : 0)) \ + __builtin_abort (); \ + __builtin_memset (a, 0, sizeof (a)) + TEST (f1 (8)); + TEST (f2 (8, 3)); + TEST (f3 (8LL, 4LL)); + TEST (f4 (8)); + TEST (f5 (8, 3)); + TEST (f6 (8LL, 4LL)); + TEST (f7 (8)); + TEST (f8 (8, 3)); + TEST (f9 (8LL, 4LL)); + TEST (f10 (8, 2)); + TEST (f11 (8, 3, 2)); + TEST (f12 (8LL, 4LL, 2)); + TEST (f13 (8, 2)); + TEST (f14 (8, 3, 2)); + TEST (f15 (8LL, 4LL, 2)); + TEST (f16 (8, 2)); + TEST (f17 (8, 3, 2)); + TEST (f18 (8LL, 4LL, 2)); + return 0; +}