From patchwork Fri Apr 5 12:26:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manolis Tsamis X-Patchwork-Id: 88085 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 88B933845BC1 for ; Fri, 5 Apr 2024 12:27:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id E45CF3858C24 for ; Fri, 5 Apr 2024 12:27:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E45CF3858C24 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E45CF3858C24 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712320047; cv=none; b=Zo2urDb9KUxUw1V+aGCW9g9+VVdBOxL5DKPY1p4uE3UBtBnPZ327Laeg0kuD+hZTCCZ41EX1jQ150Qntye5vJ2bZ5NDBYjUNQDviEjhX8pvMZEtL63RE4Z3lnsW6EEn3TRUCnzKkLC/GFUx6tqztb4PPU5H5JmfF11CwCZ4Idh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712320047; c=relaxed/simple; bh=SNumivpaAWADFtImFmFR8cwlBQKJgIV4LwIhUDGUFMo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=CR/evWQU0iLkwcOW1wA6eb+R/4KUTjRFulwLxKSAiajjSamAC606MzpJzu/z8zdpPU4bWAydp14jAN+144ltk9OaO+ZoE0FV6hMcqIjsrVTGN9Vki2hsBWaA+v1tVcJq76/rMd2mk1cbGdN07FTsQ5JoZNAFiiFiPZkQmJXlzrw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-516c5c39437so2815740e87.1 for ; Fri, 05 Apr 2024 05:27:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1712320043; x=1712924843; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=GCDLcI1EVwnI/svYO9Xq8AN4JXTvUmRzv0TQz96rrJQ=; b=GFLP2pX9EqKmTk3U/Ka7sT/srOYs6OF2bW1iafojsnmcbLaUzEIgU+zv4qTqx8FNam FQLCFAoNdWBZB7oZ68vNbauGQ0c12XTTyQoc1ec/REgWtFDaiirJpphyYMDUNaWQLHmF 5yxTdi6cNoy4BiaplJCya8PCleVHf4SnzJBIPVOP6pR/mQJ3cP6Be8/CyUGp/5jy6l3q nJLQH4UoZCNWd/UO9PFtfQGC0KgoNn8/Lne7oTtlW9UOMNO76roovg7FXD46fMmm0T1X +/iGNtdxkECmVApumJKE0Aa98dnEiXpfCaQQZXq4bA1rc/yXglfCApMEEfY5vftgITUE 0S6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712320043; x=1712924843; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GCDLcI1EVwnI/svYO9Xq8AN4JXTvUmRzv0TQz96rrJQ=; b=sSiMOl42I/xqHE1EIkEC+PVzaVIIq8vvmQ3Nkb7atoA5lWyEh5JNMZ8dba7dF/Tk0O i19+KGZICzmhSMl9AKoKRsgH7h5gD3OlRSlRou7tkS+EADhpIaLBpHY5pkes05mJ1jXp 7iz1wn1teNRecZRU9kJW+H9IWGjRRrd3WWDKmtT9K3d+LpGTN438P8D85X4xqeYACkal UrIZ1Wmtyj9DgMqB2ijnxRnwKPwmwpGvndVQD0oj46+xyLRRMcA20TnXZP/nqjPRHv5x RtW0C4y0tdYebwHBjGpmK8kpi126cBkrKcKs4lvH50WrQyzkyaKUG5uO5eXAPk/rLABO y5+Q== X-Gm-Message-State: AOJu0YzOM9Jb3tz8m5V2R1cp3ccmKz8iK+klhm8a3rkDfZ9d7DBXi+B+ 4X9MGBZJylwAaoIfUB05BccQGqUXE/MK2mvGAcKbdkGo6AEoJzF/WaZCh2HbuZvsmui4H+rZwIQ O X-Google-Smtp-Source: AGHT+IGYK5Ki+Y67fkXY+91d73cLSPFGcRJzGjKzbOGNfAdkzrewcc7A/PzJyO1kWKJb2ImrIMEdgw== X-Received: by 2002:ac2:5edb:0:b0:516:be1b:2a6a with SMTP id d27-20020ac25edb000000b00516be1b2a6amr753264lfq.68.1712320042658; Fri, 05 Apr 2024 05:27:22 -0700 (PDT) Received: from altra2.sec.univie.ac.at (altra2.sec.univie.ac.at. [131.130.126.102]) by smtp.gmail.com with ESMTPSA id dy26-20020a05640231fa00b0056dbd754811sm759313edb.40.2024.04.05.05.27.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 05:27:22 -0700 (PDT) From: Manolis Tsamis To: gcc-patches@gcc.gnu.org Cc: Andrew Pinski , Philipp Tomsich , Tamar Christina , Jiangning Liu , Manolis Tsamis Subject: [PATCH] Add extra copy of the ifcombine pass after pre [PR102793] Date: Fri, 5 Apr 2024 05:26:08 -0700 Message-ID: <20240405122625.847311-1-manolis.tsamis@vrull.eu> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org If we consider code like: if (bar1 == x) return foo(); if (bar2 != y) return foo(); return 0; We would like the ifcombine pass to convert this to: if (bar1 == x || bar2 != y) return foo(); return 0; The ifcombine pass can handle this transformation but it is ran very early and it misses the opportunity because there are two seperate blocks for foo(). The pre pass is good at removing duplicate code and blocks and due to that running ifcombine again after it can increase the number of successful conversions. PR 102793 gcc/ChangeLog: * common.opt: -ftree-ifcombine option, enabled by default. * doc/invoke.texi: Document. * passes.def: Re-run ssa-ifcombine after pre. * tree-ssa-ifcombine.cc: Make ifcombine cloneable. Add gate function. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/20030922-2.c: Change flag to -fno-tree-ifcombine. * gcc.dg/uninit-pred-6_c.c: Remove inconsistent check. * gcc.target/aarch64/pr102793.c: New test. Signed-off-by: Manolis Tsamis --- gcc/common.opt | 4 +++ gcc/doc/invoke.texi | 5 ++++ gcc/passes.def | 1 + gcc/testsuite/gcc.dg/tree-ssa/20030922-2.c | 2 +- gcc/testsuite/gcc.dg/uninit-pred-6_c.c | 4 --- gcc/testsuite/gcc.target/aarch64/pr102793.c | 30 +++++++++++++++++++++ gcc/tree-ssa-ifcombine.cc | 5 ++++ 7 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/pr102793.c diff --git a/gcc/common.opt b/gcc/common.opt index ad348844775..e943202bcf1 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -3163,6 +3163,10 @@ ftree-phiprop Common Var(flag_tree_phiprop) Init(1) Optimization Enable hoisting loads from conditional pointers. +ftree-ifcombine +Common Var(flag_tree_ifcombine) Init(1) Optimization +Merge some conditional branches to simplify control flow. + ftree-pre Common Var(flag_tree_pre) Optimization Enable SSA-PRE optimization on trees. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index e2edf7a6c13..8d2ff6b4512 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -13454,6 +13454,11 @@ This flag is enabled by default at @option{-O1} and higher. Perform hoisting of loads from conditional pointers on trees. This pass is enabled by default at @option{-O1} and higher. +@opindex ftree-ifcombine +@item -ftree-ifcombine +Merge some conditional branches to simplify control flow. This pass +is enabled by default at @option{-O1} and higher. + @opindex fhoist-adjacent-loads @item -fhoist-adjacent-loads Speculatively hoist loads from both branches of an if-then-else if the diff --git a/gcc/passes.def b/gcc/passes.def index 1cbbd413097..1765b476131 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -270,6 +270,7 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_lim); NEXT_PASS (pass_walloca, false); NEXT_PASS (pass_pre); + NEXT_PASS (pass_tree_ifcombine); NEXT_PASS (pass_sink_code, false /* unsplit edges */); NEXT_PASS (pass_sancov); NEXT_PASS (pass_asan); diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20030922-2.c b/gcc/testsuite/gcc.dg/tree-ssa/20030922-2.c index 16c79da9521..66c9f481a2f 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/20030922-2.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/20030922-2.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O1 -fdump-tree-dom2 -fdisable-tree-ifcombine" } */ +/* { dg-options "-O1 -fdump-tree-dom2 -fno-tree-ifcombine" } */ struct rtx_def; typedef struct rtx_def *rtx; diff --git a/gcc/testsuite/gcc.dg/uninit-pred-6_c.c b/gcc/testsuite/gcc.dg/uninit-pred-6_c.c index f60868dad23..2d8e6501a45 100644 --- a/gcc/testsuite/gcc.dg/uninit-pred-6_c.c +++ b/gcc/testsuite/gcc.dg/uninit-pred-6_c.c @@ -20,10 +20,6 @@ int foo (int n, int l, int m, int r) if ( (n > 10) && l) blah(v); /* { dg-bogus "uninitialized" "bogus warning" } */ - if (l) - if (n > 12) - blah(v); /* { dg-bogus "uninitialized" "bogus warning" } */ - return 0; } diff --git a/gcc/testsuite/gcc.target/aarch64/pr102793.c b/gcc/testsuite/gcc.target/aarch64/pr102793.c new file mode 100644 index 00000000000..78d48e01637 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr102793.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +typedef unsigned long uint64_t; + +int ccmp1(uint64_t* s1, uint64_t* s2, int(*foo)(void)) +{ + uint64_t d1, d2, bar; + d1 = *s1++; + d2 = *s2++; + bar = (d1 + d2) & 0xabcd; + if (bar == 0 || d1 != d2) + return foo(); + return 0; +} + +int ccmp2(uint64_t* s1, uint64_t* s2, int(*foo)(void)) +{ + uint64_t d1, d2, bar; + d1 = *s1++; + d2 = *s2++; + bar = (d1 + d2) & 0xabcd; + if (bar == 0) + return foo(); + if (d1 != d2) + return foo(); + return 0; +} + +/* { dg-final { scan-assembler-times "ccmp\t" 2 } } */ \ No newline at end of file diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc index 6a3bc99190d..0bf9fe8b692 100644 --- a/gcc/tree-ssa-ifcombine.cc +++ b/gcc/tree-ssa-ifcombine.cc @@ -838,6 +838,11 @@ public: {} /* opt_pass methods: */ + opt_pass * clone () final override + { + return new pass_tree_ifcombine (m_ctxt); + } + bool gate (function *) final override { return flag_tree_ifcombine; } unsigned int execute (function *) final override; }; // class pass_tree_ifcombine