From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by sourceware.org (Postfix) with ESMTPS id 54185385802D for ; Fri, 15 Oct 2021 11:10:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 54185385802D Received: by mail-ed1-x52a.google.com with SMTP id a25so36618093edx.8 for ; Fri, 15 Oct 2021 04:10:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DtQ3k/wfVeiBxUvW7+RXL+4ds9mDywVPH6cUH5KPf1I=; b=v/HJ3w00+I1yrTOEA5ypAnEhWKjdRl4skd09+d1huIQqELmSTFwNian38doRMPW9J2 TRWjv6YUwbDeMALEdasOXKy5+t2zV4Bp7v8mHCfVrjeuK8YBv4llxLrJvM5eyogfCgSs TvFadbMhtqVzPXKsb+wJntP9wrrpgj/NGU2CKJ9V/8Mw5MTMPzhCODpfxAg0RUHDumWw jRay7McZH/9M6EHYGefC7KN5X74UH8OYZ++2QXJ27JbMRSv2qn52MATaCAyu260kvJXQ skmgCU496xuIQ+T+rd5vkKl0H3UvAr2nxn7Tpssyz/kw72XkVoJHeHeqrexSZHjX5o8Z skmw== X-Gm-Message-State: AOAM531u2RflBitBLxtY8Jmqv9u159ynz2qF5ZdCZAG6Pkrk4+QUqtrk fcQhRFMJMCK/S6prdQmvrtPrdSpbW5vcLIXCMZs= X-Google-Smtp-Source: ABdhPJxLdem65C1YkLYU7lnw7HzKToPiSufh+03z7C4U0saUeL8mlENLZ/AFcXzUYL6NwTNb8bNbMR7cZFCi4uPCLlg= X-Received: by 2002:a17:907:6d82:: with SMTP id sb2mr393524ejc.201.1634296252325; Fri, 15 Oct 2021 04:10:52 -0700 (PDT) MIME-Version: 1.0 References: <2796861.e9J7NaK4W3@fomalhaut> In-Reply-To: <2796861.e9J7NaK4W3@fomalhaut> From: Richard Biener Date: Fri, 15 Oct 2021 13:10:41 +0200 Message-ID: Subject: Re: [patch] Tame if-combining when loop unswitching is enabled To: Eric Botcazou , =?UTF-8?Q?Martin_Li=C5=A1ka?= Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Fri, 15 Oct 2021 11:10:57 -0000 On Fri, Oct 15, 2021 at 11:15 AM Eric Botcazou via Gcc-patches wrote: > > Hi, > > in order to make it possible to vectorize loops running over arrays in Ada, > which generally contain index checks, hence control-flow instructions, we rely > on loop unswitching to generate two copies of the loop, one guarded with a > global condition (no index check fails in the loop) and vectorizable and one > with the original index checks and non-vectorizable. This is achieved by the > simple trick of prepending the global_condition to the condition of the index > checks and letting the loop unswitching pass do its magic. > > But there is an enemy, namely if-combining, which can turn a simple boolean > conjunction into something else that loop unswitching cannot deal with, and a > testcase is attached with 3 slightly different versions of the same issue. > > Therefore the attached patch attempts to tame if-combining by reasoning on the > loop invariant status (really loop depths) of the conditions. > > Bootstrapped/regtested on x86-64/Linux, OK for the mainline? Hmm, I see the issue. This heuristic probably defeats associating the combined conditions to "good" order? That is, it looks to me that eventually teaching unswitching to unswitch on comparisons [feeding GIMPLE_CONDs] would solve the issue as well? Martin was working on generalizing the code to handle switches so eventually he can look into also handling condition parts. That said, reassoc does order the outermost loop invariant conditions in the leaf of the condition chain, no? So, for (i;;) { bool a = inv < 0; bool b = i > 3; bool c = a && b; if (c) ... } could be unswitched as if (inv < 0) for (i;;) { bool a = true; bool b = i > 3; bool c = a && b; if (c) ... } else for (i;;) { bool a = false; bool b = i > 3; bool c = a && b; if (c) ... } > > 2021-10-15 Eric Botcazou > > * tree-ssa-ifcombine.c: Include cfgloop.h. > (operand_loop_depth): New function. > (ifcombine_ifandif): When loop unswitching is enabled, do not merge > conditions whose loop invariant status is different. > > > 2021-10-15 Eric Botcazou > > * gnat.dg/vect19.ads, gnat.dg/vect19.adb: New test. > > -- > Eric Botcazou