From patchwork Mon Mar 4 13:55:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 209553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1433434dyc; Mon, 4 Mar 2024 05:56:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVa5EwtTkCCe6y7rV7VXiCCgFFjLYl45Ctvqqw+1oBuldgoWTzE/CroGe33hfxp2uVwZkwOjckM3gIa3sMeO52eRSmuLg== X-Google-Smtp-Source: AGHT+IGqV6ulBZTGOYd8NTcoFZweAd4GJ9utG0YCYdVNHoYPfgCjAjSrcYOEzD4LtqtatSkP5ly7 X-Received: by 2002:a05:6214:90b:b0:690:6b89:3872 with SMTP id dj11-20020a056214090b00b006906b893872mr4078810qvb.32.1709560568879; Mon, 04 Mar 2024 05:56:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709560568; cv=pass; d=google.com; s=arc-20160816; b=WapMcWjr+6Su/4RivVliWKmDmcRwqZ5Lmyfklt3Yl3vB8r59EFn/mfMc+qLrhgnynO Tvy/ux8th/usdmXk/2eQTBQoZojBe12oJKBnZ/3DkKNhX5MBsPTB0dKHZANXuvbYBhRA D12vE0XiPeIdcW5p39X88H8jXy9UVk+HYf26yGCuR/59Jezyi1MuELXiAaIAoOMkQEtF vzTNDicntPynTlhEAQ2pRTYwzoxeZx7j3WPmvHiMjyQ2017s/4LpuNrymMYySy6GBIWd Sb3w5QovwaYzBt3iZVYeCBWxCs9ucumyWddGq3Lzc/vwi06ql39IIoLp6BAFkT34Kkmd +jQg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:errors-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :subject:to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=u8oLLae1Iyt9VDU6B441L341AeCCIzOD77KQOPS9SCk=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=qQ93Wx0cF0LdlmfXoX85EHn6qqyauvqvmLFVbFGGsvgKZXFl/24yELdBZi2wU6nCDc TScWc7thfTnfdWJUgJvgCFKnUThzONCBMkQUEyKlc/2EEZn4cgmKnkNH9I6ytA8KGkNF qPoP+rrgYM36SDk6R93VL5B8nEFqZyJ70IYnCE+RnQchk6B2wPkgbDbbN8qU40WLC5Tk 4/pHoBB91XKNzudAulCp8BYa8Xi9JTG5b7iJxO1mqW6RSYmzTz4nzmFcR9kMLiQfKiuF vuz+OdKMKBTEbZjypDbKf8lIhj2XrLvTVxbV1iVDfVCJ97H6s8/H4+NI+NWstsiNRbw6 yCkw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=1LxH+kVI; dkim=neutral (no key) header.i=@suse.de header.b=WqRXa41B; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=1LxH+kVI; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1); 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=suse.de Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i15-20020ad45c6f000000b0068f74977034si9648988qvh.493.2024.03.04.05.56.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 05:56:08 -0800 (PST) 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=@suse.de header.s=susede2_rsa header.b=1LxH+kVI; dkim=neutral (no key) header.i=@suse.de header.b=WqRXa41B; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=1LxH+kVI; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1); 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=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 937FC385842E for ; Mon, 4 Mar 2024 13:56:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id AE6973858C41 for ; Mon, 4 Mar 2024 13:55:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE6973858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AE6973858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709560531; cv=none; b=s9HJ9qmYfCjnS+26AXD6tAQXnGd/jzn0CsRF8FrSTaqC/TBWDDKXr3aLdrY5WgX5TV4YWKnY8cGGNojHzvEdS/ce979psdIN+Q1ibj8LsiXdiz0Fx/IpLfVZ6BvdFB1WT8yHDsyI04rd5/b4p3H4TMb1MZ8/NC3tX2RRsH288Lg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709560531; c=relaxed/simple; bh=2Q2lW9sgb1cIY0PfCu8TKDRqF+D7B5MW5np1YsJUY9E=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=eLYIAmAUfq5TSkxwm/ZFo7l5YjB9c1pk7i5IBpUWNPRA40iyulaUWWEW3AIvtnQt5gVfihaEHBk7/2VkNSE2WE4RMiiIiKb1BbPBkCgN0AyWN432y/vG70afAZYDczOTbYisVNXOwy5MYDFMX6wJzuRzS0+9AVcRgHWZuVYvBQE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4CDCE4E81E for ; Mon, 4 Mar 2024 13:55:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709560528; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=u8oLLae1Iyt9VDU6B441L341AeCCIzOD77KQOPS9SCk=; b=1LxH+kVI7b/Gqav/qQf3qDPsVQLas80lLE7XBExyRyE0PFFMdmPv9hC6UUKJI2zjqSyutq l51AAGPJtP+wGEOorNlYBJobx8l4J9aTHCMyOpvR1CFbII6+lVI1jVq+jvTeY+LYmhHW75 iVMqWluXXyeK9OZLyCxlmr5QQgYOLq8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709560528; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=u8oLLae1Iyt9VDU6B441L341AeCCIzOD77KQOPS9SCk=; b=WqRXa41BpAgnvyeB4ojHltWUuwaPyv50YKi81qiJUfVtyQAAns4YO/42NSdsP5L7jT6Ov5 zf2vbmHXjzsV18Bw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709560528; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=u8oLLae1Iyt9VDU6B441L341AeCCIzOD77KQOPS9SCk=; b=1LxH+kVI7b/Gqav/qQf3qDPsVQLas80lLE7XBExyRyE0PFFMdmPv9hC6UUKJI2zjqSyutq l51AAGPJtP+wGEOorNlYBJobx8l4J9aTHCMyOpvR1CFbII6+lVI1jVq+jvTeY+LYmhHW75 iVMqWluXXyeK9OZLyCxlmr5QQgYOLq8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709560528; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=u8oLLae1Iyt9VDU6B441L341AeCCIzOD77KQOPS9SCk=; b=WqRXa41BpAgnvyeB4ojHltWUuwaPyv50YKi81qiJUfVtyQAAns4YO/42NSdsP5L7jT6Ov5 zf2vbmHXjzsV18Bw== Date: Mon, 4 Mar 2024 14:55:28 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/114197 - unexpected if-conversion for vectorization MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-0.60 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%] X-Spam-Level: X-Spam-Score: -0.60 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, 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.30 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 Message-Id: <20240304135608.937FC385842E@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792604183207946592 X-GMAIL-MSGID: 1792604183207946592 The following avoids lowering a volatile bitfiled access and in case the if-converted and original loops end up in different outer loops because of simplifcations enabled scrap the result since that is not how the vectorizer expects the loops to be laid out. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/114197 * tree-if-conv.cc (bitfields_to_lower_p): Do not lower if there are volatile bitfield accesses. (pass_if_conversion::execute): Throw away result if the if-converted and original loops are not nested as expected. * gcc.dg/torture/pr114197.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr114197.c | 15 +++++++++++++++ gcc/tree-if-conv.cc | 23 +++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr114197.c diff --git a/gcc/testsuite/gcc.dg/torture/pr114197.c b/gcc/testsuite/gcc.dg/torture/pr114197.c new file mode 100644 index 00000000000..fb7e2fb712c --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr114197.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ + +#pragma pack(push) +struct a { + volatile signed b : 8; +}; +#pragma pack(pop) +int c; +static struct a d = {5}; +void e() { +f: + for (c = 8; c < 55; ++c) + if (!d.b) + goto f; +} diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index db0d0f4a497..09d99fb9dda 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -3701,6 +3701,14 @@ bitfields_to_lower_p (class loop *loop, if (dump_file && (dump_flags & TDF_DETAILS)) print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); + if (TREE_THIS_VOLATILE (op)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "\t Bitfield NO OK to lower," + " the access is volatile.\n"); + return false; + } + if (!INTEGRAL_TYPE_P (TREE_TYPE (op))) { if (dump_file && (dump_flags & TDF_DETAILS)) @@ -4031,20 +4039,27 @@ pass_if_conversion::execute (function *fun) if (todo & TODO_update_ssa_any) update_ssa (todo & TODO_update_ssa_any); - /* If if-conversion elided the loop fall back to the original one. */ + /* If if-conversion elided the loop fall back to the original one. Likewise + if the loops are not nested in the same outer loop. */ for (unsigned i = 0; i < preds.length (); ++i) { gimple *g = preds[i]; if (!gimple_bb (g)) continue; - unsigned ifcvt_loop = tree_to_uhwi (gimple_call_arg (g, 0)); - unsigned orig_loop = tree_to_uhwi (gimple_call_arg (g, 1)); - if (!get_loop (fun, ifcvt_loop) || !get_loop (fun, orig_loop)) + auto ifcvt_loop = get_loop (fun, tree_to_uhwi (gimple_call_arg (g, 0))); + auto orig_loop = get_loop (fun, tree_to_uhwi (gimple_call_arg (g, 1))); + if (!ifcvt_loop || !orig_loop) { if (dump_file) fprintf (dump_file, "If-converted loop vanished\n"); fold_loop_internal_call (g, boolean_false_node); } + else if (loop_outer (ifcvt_loop) != loop_outer (orig_loop)) + { + if (dump_file) + fprintf (dump_file, "If-converted loop in different outer loop\n"); + fold_loop_internal_call (g, boolean_false_node); + } } return 0;