From patchwork Tue Oct 18 08:35:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Andre Vieira (lists)" X-Patchwork-Id: 4009 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1841722wrs; Tue, 18 Oct 2022 01:36:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5BF85TJAcRz6B7TqQXPaJpMhpLGRB1QD6zTqOQCBg6Jgz8Sn+o19QgH5a/0pQxzI4zjMWM X-Received: by 2002:a17:906:5a4b:b0:78d:8790:d4a1 with SMTP id my11-20020a1709065a4b00b0078d8790d4a1mr1451900ejc.329.1666082165811; Tue, 18 Oct 2022 01:36:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666082165; cv=none; d=google.com; s=arc-20160816; b=CsaZ6Gk9iXD5yW5p6qNvfIlAQk2oUuK6hmxcIMDoqdmTZ7WYzmvTOpL0GW8eEMFB5q /PS1JchS5e7kJk68ieQ/rzy+AtOVhCjf3o0NpiHZggP0E0Lnn/0c11gtv1oy0pWA1AxH 1YriguI3P3VA4LrEEVT4tFhyPh2wrcLJ1CwJexywlbvpWiwNX8VuHgFKZJRVgHrFFBXn mkByG0GFf5ZpfGlaRLNoPqEHv2CXbvmDspInzOFGtGM8tO6m57Kq/ncQN6h2En6Qj0Ro LuOKopfj8fU3eh1m5Lhsg3VQLLcbGS8ZQw93GWNzh0zn9TSzECFd9HcvuwCU6TQ7kNSI BxQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :to:content-language:user-agent:mime-version:date:message-id :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=vGNtSIkKqogNfw0JcuRJqhuti/soZkmVeNsghIhDM50=; b=fdWMvnxFEffXRarw6k0z9q7kQ9Va/0wkwcT6emzxZDEwbg5CKeFYQrzIoEZwR3ogFn l8mrThUtSzTg3iy9QozB/YtLEKKDWeMjU/umKGqi6qn0HlcXmqAwJlHRRCEK79Y5uQLV FaTlL/g1fv2oRMMYBcF1gS7vu0gb4P+bZiDoxBCiE1RE8efGIglfUQShF2g5W2YDjBWi ZpVusFKfcUucmH7vO/mfFX4W/A+72oex9D9kBkwkr1iBKD4dqzsImOdFS6XEKJDc/MYF h3KPhHYZA7uQx2nj7pMAvgkAdnVI5NQ23r3IsX++r23cPUXn/it9hPYEp9H5G10q3WgC +7wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uFRvVJSt; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id gn41-20020a1709070d2900b0077cfdda438csi11685700ejc.35.2022.10.18.01.36.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 01:36:05 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uFRvVJSt; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 D5566385841D for ; Tue, 18 Oct 2022 08:36:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D5566385841D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666082164; bh=vGNtSIkKqogNfw0JcuRJqhuti/soZkmVeNsghIhDM50=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=uFRvVJStNTkCbPC2z2fObROTIxLSmSLwSeBsV/ekpJDiw8pPc3l5B9L4kDsRqcWEe LWUHCAsLiILk6OfNhf1R1zuuSgzE79ifMxTzfYI+H/iozYzjx29eYr9sR+Ze3/Reej kRHm3uaIxtZWnS40s+EcseXoUyZPyg1brCwdwbfI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 903913858295 for ; Tue, 18 Oct 2022 08:35:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 903913858295 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6C708113E; Tue, 18 Oct 2022 01:35:27 -0700 (PDT) Received: from [10.57.5.230] (unknown [10.57.5.230]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 81B5E3F7D8; Tue, 18 Oct 2022 01:35:20 -0700 (PDT) Message-ID: <0888cc2d-2040-52c3-1201-16400567300b@arm.com> Date: Tue, 18 Oct 2022 09:35:15 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Content-Language: en-US To: "gcc-patches@gcc.gnu.org" Subject: [PATCH] ifcvt: Do not lower bitfields if we can't analyze dr's [PR107275] X-Spam-Status: No, score=-20.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, 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: "Andre Vieira \(lists\) via Gcc-patches" From: "Andre Vieira (lists)" Reply-To: "Andre Vieira \(lists\)" Cc: Richard Sandiford , Richard Biener , Jeff Law 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?1747013773074589855?= X-GMAIL-MSGID: =?utf-8?q?1747013773074589855?= The ifcvt dead code elimination code was not built to deal with inline assembly, as loops with such would never be if-converted in the past since we can't do data-reference analysis on them and vectorization would eventually fail. For this reason we now also do not lower bitfields if the data-reference analysis fails, as we would not end up vectorizing it.  As a consequence this also fixes this PR as the dead code elimination will not run for such cases and wrongfully eliminate inline assembly statements. Bootstrapped and regression tested on aarch64-none-linux-gnu and x86_64-pc-linux-gnu. gcc/ChangeLog:     PR tree-optimization/107275     * tree-if-conv.cc (if_convertible_loop_p_1): Move     find_data_references_in_loop call from here...     (if_convertible_loop_p): And move data-reference vector initialization     from here...     (tree_if_conversion):... to here. gcc/testsuite/ChangeLog:     * gcc.dg/vect/pr107275.c: New test. diff --git a/gcc/testsuite/gcc.dg/vect/pr107275.c b/gcc/testsuite/gcc.dg/vect/pr107275.c new file mode 100644 index 0000000000000000000000000000000000000000..16327c46add7f74dd36c1a636c0fb9c84d5232c8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr107275.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +struct st +{ + int a : 1; +}; + +void +foo (struct st *s, int n) +{ + for (int i = 0; i < n; ++i) + { + s[i].a = i; + __asm__ __volatile__ ("":::"memory"); + } +} diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index 01637c5da08d5a2a00a495522fc9a6436a804398..a83b013d2ad3d9066b1c2bc62282ec054483598f 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -1416,9 +1416,6 @@ if_convertible_loop_p_1 (class loop *loop, vec *refs) basic_block exit_bb = NULL; vec region; - if (find_data_references_in_loop (loop, refs) == chrec_dont_know) - return false; - calculate_dominance_info (CDI_DOMINATORS); for (i = 0; i < loop->num_nodes; i++) @@ -1541,12 +1538,11 @@ if_convertible_loop_p_1 (class loop *loop, vec *refs) - if its basic blocks and phi nodes are if convertible. */ static bool -if_convertible_loop_p (class loop *loop) +if_convertible_loop_p (class loop *loop, vec *refs) { edge e; edge_iterator ei; bool res = false; - vec refs; /* Handle only innermost loop. */ if (!loop || loop->inner) @@ -1578,15 +1574,7 @@ if_convertible_loop_p (class loop *loop) if (loop_exit_edge_p (loop, e)) return false; - refs.create (5); - res = if_convertible_loop_p_1 (loop, &refs); - - data_reference_p dr; - unsigned int i; - for (i = 0; refs.iterate (i, &dr); i++) - free (dr->aux); - - free_data_refs (refs); + res = if_convertible_loop_p_1 (loop, refs); delete innermost_DR_map; innermost_DR_map = NULL; @@ -3499,6 +3487,7 @@ tree_if_conversion (class loop *loop, vec *preds) auto_vec writes_to_lower; bitmap exit_bbs; edge pe; + vec refs; again: rloop = NULL; @@ -3508,6 +3497,7 @@ tree_if_conversion (class loop *loop, vec *preds) need_to_predicate = false; need_to_rewrite_undefined = false; any_complicated_phi = false; + refs.create (5); /* Apply more aggressive if-conversion when loop or its outer loop were marked with simd pragma. When that's the case, we try to if-convert @@ -3537,11 +3527,14 @@ tree_if_conversion (class loop *loop, vec *preds) goto cleanup; } + if (find_data_references_in_loop (loop, &refs) == chrec_dont_know) + goto cleanup; + if (loop->num_nodes > 2) { need_to_ifcvt = true; - if (!if_convertible_loop_p (loop) || !dbg_cnt (if_conversion_tree)) + if (!if_convertible_loop_p (loop, &refs) || !dbg_cnt (if_conversion_tree)) goto cleanup; if ((need_to_predicate || any_complicated_phi) @@ -3658,6 +3651,13 @@ tree_if_conversion (class loop *loop, vec *preds) todo |= TODO_cleanup_cfg; cleanup: + data_reference_p dr; + unsigned int i; + for (i = 0; refs.iterate (i, &dr); i++) + free (dr->aux); + + refs.truncate (0); + if (ifc_bbs) { unsigned int i;