From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id 0D91C3858C53 for ; Fri, 1 Apr 2022 06:53:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0D91C3858C53 Received: by mail-ed1-x531.google.com with SMTP id x34so1815450ede.8 for ; Thu, 31 Mar 2022 23:53:54 -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=ZQ/kC1851riosBZO2HRlMo1dK6A7oRD1b29Bp57wrE8=; b=JdoEeTg4G9pY63IPCeOQWonC2HGn9GZaamXQXIBkP2Zghc8fv9X0SAek5PSUclvJv+ eW9ymDGcG7qlHMLAYiBHKheK8wDDEuBmWbIR6Rwpymu2w9e4hJhSnExETjQ1tr7V4Vwf AEkEunAAz8bvcdgxLoXh+TOqnTIRYzuOhPW6AAv9dTgDwLGbx+K4+dXRTCtKu3wgZgCU 6y3VX5VzNqXuVB9JQeEPl26tbX3SvsIm8KafjWul8zqNz43ZsriPy4UuN+gMaJpsp3y0 I+uZtUG+KKgM+TYtnnSaeoKytaxd39zS5jk9QZyHiWjdC4s/9xAYl584d+AKGLY4UUiq xCrw== X-Gm-Message-State: AOAM530toruANXiFGFtvhWt9NaTYm/9z1MCrzYogTiWjFZbCTipQRAwd hzgC1Lgr1qQyedgqy7liaVVSfEZqyQAdKV9AQU8= X-Google-Smtp-Source: ABdhPJwTylL5HvMhdvhlFURs1M2K247DDsIGqF4IPDJbJgJk+wABc71IBHRaPwYPONdQOtq+WrlBQZC6uIH1oXMA6jE= X-Received: by 2002:aa7:c1cd:0:b0:419:fdb:e17e with SMTP id d13-20020aa7c1cd000000b004190fdbe17emr19844626edp.364.1648796032491; Thu, 31 Mar 2022 23:53:52 -0700 (PDT) MIME-Version: 1.0 References: <20220401064634.16091-1-hongtao.liu@intel.com> In-Reply-To: <20220401064634.16091-1-hongtao.liu@intel.com> From: Richard Biener Date: Fri, 1 Apr 2022 08:53:41 +0200 Message-ID: Subject: Re: [PATCH] Split vector load from parm_del to elemental loads to avoid STLF stalls. To: liuhongt , Jan Hubicka Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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, 01 Apr 2022 06:53:56 -0000 On Fri, Apr 1, 2022 at 8:47 AM liuhongt via Gcc-patches wrote: > > Update in V2: > 1. Use get_insns instead of FOR_EACH_BB_CFUN and FOR_BB_INSNS. > 2. Return for any_uncondjump_p and ANY_RETURN_P. > 3. Add dump info for spliting instruction. > 4. Restrict ix86_split_stlf_stall_load under TARGET_SSE2. > > Since cfg is freed before machine_reorg, just do a rough calculation > of the window according to the layout. > Also according to an experiment on CLX, set window size to 64. > > Currently only handle V2DFmode load since it doesn't need any scratch > registers, and it's sufficient to recover cray performance for -O2 > compared to GCC11. > > gcc/ChangeLog: > > PR target/101908 > * config/i386/i386.cc (ix86_split_stlf_stall_load): New > function > (ix86_reorg): Call ix86_split_stlf_stall_load. > > gcc/testsuite/ChangeLog: > > * gcc.target/i386/pr101908-1.c: New test. > * gcc.target/i386/pr101908-2.c: New test. > --- > gcc/config/i386/i386.cc | 60 ++++++++++++++++++++++ > gcc/testsuite/gcc.target/i386/pr101908-1.c | 12 +++++ > gcc/testsuite/gcc.target/i386/pr101908-2.c | 12 +++++ > 3 files changed, 84 insertions(+) > create mode 100644 gcc/testsuite/gcc.target/i386/pr101908-1.c > create mode 100644 gcc/testsuite/gcc.target/i386/pr101908-2.c > > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc > index 5a561966eb4..c88a689f32b 100644 > --- a/gcc/config/i386/i386.cc > +++ b/gcc/config/i386/i386.cc > @@ -21933,6 +21933,64 @@ ix86_seh_fixup_eh_fallthru (void) > emit_insn_after (gen_nops (const1_rtx), insn); > } > } > +/* Split vector load from parm_decl to elemental loads to avoid STLF > + stalls. */ > +static void > +ix86_split_stlf_stall_load () > +{ > + rtx_insn* insn, *start = get_insns (); > + unsigned window = 0; > + > + for (insn = start; insn; insn = NEXT_INSN (insn)) > + { > + if (!NONDEBUG_INSN_P (insn)) > + continue; > + window++; > + /* Insert 64 vaddps %xmm18, %xmm19, %xmm20(no dependence between each > + other, just emulate for pipeline) before stalled load, stlf stall > + case is as fast as no stall cases on CLX. > + Since CFG is freed before machine_reorg, just do a rough > + calculation of the window according to the layout. */ > + if (window > 64) I think we want to turn the '64' into a --param at least. You can add -param=x86-stlf-window-ninsns= into i386.opt (see -param= examples in aarch64/ for example). > + return; > + > + if (any_uncondjump_p (insn) > + || ANY_RETURN_P (PATTERN (insn))) You made a point about calls - does any_uncondjump_p cover them? otherwise I think this is fine, Honza, do you agree? Thanks, Richard. > + return; > + > + rtx set = single_set (insn); > + if (!set) > + continue; > + rtx src = SET_SRC (set); > + if (!MEM_P (src) > + /* Only handle V2DFmode load since it doesn't need any scratch > + register. */ > + || GET_MODE (src) != E_V2DFmode > + || !MEM_EXPR (src) > + || TREE_CODE (get_base_address (MEM_EXPR (src))) != PARM_DECL > + continue; > + > + rtx zero = CONST0_RTX (V2DFmode); > + rtx dest = SET_DEST (set); > + rtx m = adjust_address (src, DFmode, 0); > + rtx loadlpd = gen_sse2_loadlpd (dest, zero, m); > + emit_insn_before (loadlpd, insn); > + m = adjust_address (src, DFmode, 8); > + rtx loadhpd = gen_sse2_loadhpd (dest, dest, m); > + if (dump_file && (dump_flags & TDF_DETAILS)) > + { > + fputs ("Due to potential STLF stall, split instruction:\n", > + dump_file); > + print_rtl_single (dump_file, insn); > + fputs ("To:\n", dump_file); > + print_rtl_single (dump_file, loadlpd); > + print_rtl_single (dump_file, loadhpd); > + } > + PATTERN (insn) = loadhpd; > + INSN_CODE (insn) = -1; > + gcc_assert (recog_memoized (insn) != -1); > + } > +} > > /* Implement machine specific optimizations. We implement padding of returns > for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window. */ > @@ -21948,6 +22006,8 @@ ix86_reorg (void) > > if (optimize && optimize_function_for_speed_p (cfun)) > { > + if (TARGET_SSE2) > + ix86_split_stlf_stall_load (); > if (TARGET_PAD_SHORT_FUNCTION) > ix86_pad_short_function (); > else if (TARGET_PAD_RETURNS) > diff --git a/gcc/testsuite/gcc.target/i386/pr101908-1.c b/gcc/testsuite/gcc.target/i386/pr101908-1.c > new file mode 100644 > index 00000000000..33d9684f0ad > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/pr101908-1.c > @@ -0,0 +1,12 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -msse2 -mno-avx" } */ > +/* { dg-final { scan-assembler-not {(?n)movhpd[ \t]} } } */ > + > +struct X { double x[2]; }; > +typedef double v2df __attribute__((vector_size(16))); > + > +v2df __attribute__((noipa)) > +foo (struct X* x, struct X* y) > +{ > + return (v2df) {x->x[1], x->x[0] } + (v2df) { y->x[1], y->x[0] }; > +} > diff --git a/gcc/testsuite/gcc.target/i386/pr101908-2.c b/gcc/testsuite/gcc.target/i386/pr101908-2.c > new file mode 100644 > index 00000000000..45060b73c06 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/pr101908-2.c > @@ -0,0 +1,12 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -msse2 -mno-avx" } */ > +/* { dg-final { scan-assembler-times {(?n)movhpd[ \t]+} "2" } } */ > + > +struct X { double x[4]; }; > +typedef double v2df __attribute__((vector_size(16))); > + > +v2df __attribute__((noipa)) > +foo (struct X x, struct X y) > +{ > + return (v2df) {x.x[1], x.x[0] } + (v2df) { y.x[1], y.x[0] }; > +} > -- > 2.18.1 >