From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id 5C5453858CDB for ; Wed, 24 May 2023 09:14:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C5453858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f3b337e842so582631e87.3 for ; Wed, 24 May 2023 02:14:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684919669; x=1687511669; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=rY1ptLe7rxNQ9Ighv49J9uKHgA8SybnCdfxRTc4avs0=; b=UpPe+TsqU/ug1UxC0huxiPq2g0z2qyieUgzFIA+FYkC6rcvvJRLpvWO25FJh0KupW6 EzOqauM46NeDL5Pjli0AtGPKTJMufEsU7WYlh9IbLy8HxajkXHF8ANFPItbq1pq9PbYB Kt7k1M/nWnuT/ssgWX9xb1Rr/31CV8wszls19CxzddLwGp4HAQsrYUXl5GJqs5KgVL/S kTiI40bGIxxstidyCFoP7U1gvU34KfIahR+rPB69ydOve59kOMOR6LigdEY5hJYIfZsy KXygQeWsQN98qWOLPKzpD/XiL2ovkoG0UcqFHnOZoNGSoAImQZjZMVWJnpuAuSZ9csje gfZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684919669; x=1687511669; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rY1ptLe7rxNQ9Ighv49J9uKHgA8SybnCdfxRTc4avs0=; b=XFDm0qms5LaL1wq3BPF1n24uephAKWUvCYywnuCZw9JjOlbvCFgSiFrUl7vQoyWVqw OCyVFpTELj585fXooLNXoqp2rpt9AcyOXwBbw55d2HL1IPH8/3HWbR4LBHYkMcA7u53L ylDnmXxiTgfbSTQE6RNhT5MOSjwnuG9j3d94odI/msOmAn8ehIDExf4HgrRu32NWgg8B LUgFf78ZBmnhNmNyHKq5jg5NnBTZAKMHoF6WMNzMDFhYluwxmECw42db1tLX3C9XKr++ cBDd0+Z9DtR0X1j12jBA/K33ceo3W8of/loU5m3Obdh0SaAQHq5e1RC8Jl76pNzpA6Fc u77A== X-Gm-Message-State: AC+VfDxIo9QHMQPon5fSJbNvq22VERbJfeZOqFtfvJ6gYSXka1Vw+gU+ 3bgPBcz2TM7+xKEGv1GRJVj9ZB2Q7XoH3nTOx/M= X-Google-Smtp-Source: ACHHUZ5/jB0gRHc0ChCNuXw3xR3KfKPSsYqgJsNb3IIkD1cdMUfNSxXve/1gDoYzKGfJIBxBD5UycIVFVhHY6DX13Z4= X-Received: by 2002:a2e:a40d:0:b0:2a8:bd1f:a377 with SMTP id p13-20020a2ea40d000000b002a8bd1fa377mr5674415ljn.20.1684919668368; Wed, 24 May 2023 02:14:28 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Wed, 24 May 2023 11:12:22 +0200 Message-ID: Subject: Re: [PATCH] [x86] reenable dword MOVE_MAX for better memmove inlining To: Alexandre Oliva Cc: gcc-patches@gcc.gnu.org, "H.J. Lu" , Jan Hubicka , Uros Bizjak Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 List-Id: On Wed, May 24, 2023 at 7:47=E2=80=AFAM Alexandre Oliva via Gcc-patches wrote: > > > MOVE_MAX on x86* used to accept up to 16 bytes, even without SSE, > which enabled inlining of small memmove by loading and then storing > the entire range. After the "x86: Update piecewise move and store" > r12-2666 change, memmove of more than 4 bytes would not be inlined in > gimple_fold_bultin_memory_op, failing the expectations of a few tests. > > I can see how lowering it for MOVE_MAX_PIECES can get us better > codegen decisions overall, but surely inlining memmove with 2 32-bit > loads and stores is better than an outline call that requires setting > up 3 arguments. I suppose even 3 or 4 could do better. But maybe it > is gimple_fold_builtin_memory_op that needs tweaking? gimple_fold_builtin_memory_op tries to expand the call to a single load plus a single store so we can handle overlaps by first loading everything to registers and then storing: /* If we can perform the copy efficiently with first doing all loads and then all stores inline it that way. Currently efficiently means that we can load all the memory into a single integer register which is what MOVE_MAX gives us. */ using DImode on i?86 without SSE means we eventually perform two loads and two stores which means we need two registers available. That might not be an issue on x86_64 doing 16 bytes with two DImode ops (and -mno-sse) since there's plenty of regs available. So I think if we want to expand this further at the GIMPLE level we should still honor MOVE_MAX but eventually emit multiple loads/stores honoring the MOVE_MAX_PIECES set of constraints there and avoid expanding to sequences where we cannot interleave the loads/stores (aka for the memmove case). > Anyhow, this patch raises MOVE_MAX back a little for non-SSE targets, > while preserving the new value for MOVE_MAX_PIECES. > > Bootstrapped on x86_64-linux-gnu. Also tested on ppc- and x86-vx7r2 > with gcc-12. > > for gcc/ChangeLog > > * config/i386/i386.h (MOVE_MAX): Rename to... > (MOVE_MAX_VEC): ... this. Add NONVEC parameter, and use it as > the last resort, instead of UNITS_PER_WORD. > (MOVE_MAX): Reintroduce in terms of MOVE_MAX_VEC, with > 2*UNITS_PER_WORD. > (MOVE_MAX_PIECES): Likewise, but with UNITS_PER_WORD. > --- > gcc/config/i386/i386.h | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h > index c7439f89bdf92..5293a332a969a 100644 > --- a/gcc/config/i386/i386.h > +++ b/gcc/config/i386/i386.h > @@ -1801,7 +1801,9 @@ typedef struct ix86_args { > is the number of bytes at a time which we can move efficiently. > MOVE_MAX_PIECES defaults to MOVE_MAX. */ > > -#define MOVE_MAX \ > +#define MOVE_MAX MOVE_MAX_VEC (2 * UNITS_PER_WORD) > +#define MOVE_MAX_PIECES MOVE_MAX_VEC (UNITS_PER_WORD) > +#define MOVE_MAX_VEC(NONVEC) \ > ((TARGET_AVX512F \ > && (ix86_move_max =3D=3D PVW_AVX512 \ > || ix86_store_max =3D=3D PVW_AVX512)) \ > @@ -1813,7 +1815,7 @@ typedef struct ix86_args { > : ((TARGET_SSE2 \ > && TARGET_SSE_UNALIGNED_LOAD_OPTIMAL \ > && TARGET_SSE_UNALIGNED_STORE_OPTIMAL) \ > - ? 16 : UNITS_PER_WORD))) > + ? 16 : (NONVEC)))) > > /* STORE_MAX_PIECES is the number of bytes at a time that we can store > efficiently. Allow 16/32/64 bytes only if inter-unit move is enabled > > -- > Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ > Free Software Activist GNU Toolchain Engineer > Disinformation flourishes because many people care deeply about injustice > but very few check the facts. Ask me about