From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id 0E8E8382E746 for ; Tue, 6 Dec 2022 01:31:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0E8E8382E746 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lj1-x22e.google.com with SMTP id x11so15569379ljh.7 for ; Mon, 05 Dec 2022 17:31:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=qbepcMCuKae4f7zD2Y5KQcLqyPcgavFzb+22sCn4IHw=; b=pO39Fy/aVneYWKOfdo3eX1/XAw5Kk33UVpV6g/7kvRrab2hVQcAunaP8Gr1gAH0Z/S lbkO70Co3B2XBt9Un/yOZfxNBATysxzzv59B3SqZukhwSxSwYLsZOmtCIqJofkusWsW8 WSwqA09k6o399dYxZ/JJLPO2erKe0B/D9yoh7X681IEonpX9H7vAPXzdk2Jp2R5NBZTb VmTQ4rzF05JfO5Yk9oliPim5aQ7a2mjQDds8KBGWdUhFm0Z6OmpWuIfBoNCD5ia0/Llr TnBVmksTjDSLzKa9adxOWAJro7tN52Opce3exnuGUfZFavgC3KYlbZ3J0xwV6m8KC6dM XV8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=qbepcMCuKae4f7zD2Y5KQcLqyPcgavFzb+22sCn4IHw=; b=Rj7SNBty64flAd8x6pcKambhAtOb/7Os2EiOfgxyKZfFAm+6xsQ/94EtBam+s6OQ+2 mpmQdnuCiojwTbf1IHtizYY/KJ0dm9tWV83h8SL+NielYVbsQJMKtiYuyJ03lHin2ya9 w2r68YLpTdGl5vXZWrQBaaX3fO+Z2VsBUd2DMo6sjgZGUAryvc0+zZzwsuy7IbHe1v8K h9O0Xfkw8p14o3wVEHs/6OSbyq7R7obcWBrslLR2cfpsYZCCp+TEgzZaRErJ3BeCYYWx YTq9GqpfDlniBxwd9RP8gNJ3qilenbJr+9eEFa7v6Wtf35dm3IofsuSBf19pe/bECa6/ uaVA== X-Gm-Message-State: ANoB5pkbwupgmwhPuYhaYBoPeKQ9ZQo/6w5Il1+EeXX+2PuG9yz2Sycp KJBh8Gs1STI/mPZuUss+UHrZYH0tOpa58+ZI6vbGLg== X-Google-Smtp-Source: AA0mqf6lGFPkSz5oLzE3d7bVOy9twIhWoDK4psyCo7X/QF7U9z3IrAf0YCDyA1myljrYH2XIZpcslEnksu0AyetDWo8= X-Received: by 2002:a2e:6e14:0:b0:279:e617:457 with SMTP id j20-20020a2e6e14000000b00279e6170457mr4160430ljc.259.1670290308291; Mon, 05 Dec 2022 17:31:48 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Prathamesh Kulkarni Date: Tue, 6 Dec 2022 07:01:11 +0530 Message-ID: Subject: Re: [aarch64] Use dup and zip1 for interleaving elements in initializing vector To: Prathamesh Kulkarni , gcc Patches , richard.sandiford@arm.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.9 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 List-Id: On Mon, 5 Dec 2022 at 16:50, Richard Sandiford wrote: > > Richard Sandiford via Gcc-patches writes: > > Prathamesh Kulkarni writes: > >> Hi, > >> For the following test-case: > >> > >> int16x8_t foo(int16_t x, int16_t y) > >> { > >> return (int16x8_t) { x, y, x, y, x, y, x, y }; > >> } > >> > >> Code gen at -O3: > >> foo: > >> dup v0.8h, w0 > >> ins v0.h[1], w1 > >> ins v0.h[3], w1 > >> ins v0.h[5], w1 > >> ins v0.h[7], w1 > >> ret > >> > >> For 16 elements, it results in 8 ins instructions which might not be > >> optimal perhaps. > >> I guess, the above code-gen would be equivalent to the following ? > >> dup v0.8h, w0 > >> dup v1.8h, w1 > >> zip1 v0.8h, v0.8h, v1.8h > >> > >> I have attached patch to do the same, if number of elements >= 8, > >> which should be possibly better compared to current code-gen ? > >> Patch passes bootstrap+test on aarch64-linux-gnu. > >> Does the patch look OK ? > >> > >> Thanks, > >> Prathamesh > >> > >> diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc > >> index c91df6f5006..e5dea70e363 100644 > >> --- a/gcc/config/aarch64/aarch64.cc > >> +++ b/gcc/config/aarch64/aarch64.cc > >> @@ -22028,6 +22028,39 @@ aarch64_expand_vector_init (rtx target, rtx vals) > >> return; > >> } > >> > >> + /* Check for interleaving case. > >> + For eg if initializer is (int16x8_t) {x, y, x, y, x, y, x, y}. > >> + Generate following code: > >> + dup v0.h, x > >> + dup v1.h, y > >> + zip1 v0.h, v0.h, v1.h > >> + for "large enough" initializer. */ > >> + > >> + if (n_elts >= 8) > >> + { > >> + int i; > >> + for (i = 2; i < n_elts; i++) > >> + if (!rtx_equal_p (XVECEXP (vals, 0, i), XVECEXP (vals, 0, i % 2))) > >> + break; > >> + > >> + if (i == n_elts) > >> + { > >> + machine_mode mode = GET_MODE (target); > >> + rtx dest[2]; > >> + > >> + for (int i = 0; i < 2; i++) > >> + { > >> + rtx x = copy_to_mode_reg (GET_MODE_INNER (mode), XVECEXP (vals, 0, i)); > > > > Formatting nit: long line. > > > >> + dest[i] = gen_reg_rtx (mode); > >> + aarch64_emit_move (dest[i], gen_vec_duplicate (mode, x)); > >> + } > > > > This could probably be written: > > > > for (int i = 0; i < 2; i++) > > { > > rtx x = expand_vector_broadcast (mode, XVECEXP (vals, 0, i)); > > dest[i] = force_reg (GET_MODE_INNER (mode), x); > > Oops, I meant "mode" rather than "GET_MODE_INNER (mode)", sorry. Thanks, I have pushed the change in 769370f3e2e04823c8a621d8ffa756dd83ebf21e after running bootstrap+test on aarch64-linux-gnu. Thanks, Prathamesh > > > } > > > > which avoids forcing constant elements into a register before the duplication. > > OK with that change if it works. > > > > Thanks, > > Richard > > > >> + > >> + rtvec v = gen_rtvec (2, dest[0], dest[1]); > >> + emit_set_insn (target, gen_rtx_UNSPEC (mode, v, UNSPEC_ZIP1)); > >> + return; > >> + } > >> + } > >> + > >> enum insn_code icode = optab_handler (vec_set_optab, mode); > >> gcc_assert (icode != CODE_FOR_nothing); > >> > >> diff --git a/gcc/testsuite/gcc.target/aarch64/interleave-init-1.c b/gcc/testsuite/gcc.target/aarch64/interleave-init-1.c > >> new file mode 100644 > >> index 00000000000..ee775048589 > >> --- /dev/null > >> +++ b/gcc/testsuite/gcc.target/aarch64/interleave-init-1.c > >> @@ -0,0 +1,37 @@ > >> +/* { dg-do compile } */ > >> +/* { dg-options "-O3" } */ > >> +/* { dg-final { check-function-bodies "**" "" "" } } */ > >> + > >> +#include > >> + > >> +/* > >> +** foo: > >> +** ... > >> +** dup v[0-9]+\.8h, w[0-9]+ > >> +** dup v[0-9]+\.8h, w[0-9]+ > >> +** zip1 v[0-9]+\.8h, v[0-9]+\.8h, v[0-9]+\.8h > >> +** ... > >> +** ret > >> +*/ > >> + > >> +int16x8_t foo(int16_t x, int y) > >> +{ > >> + int16x8_t v = (int16x8_t) {x, y, x, y, x, y, x, y}; > >> + return v; > >> +} > >> + > >> +/* > >> +** foo2: > >> +** ... > >> +** dup v[0-9]+\.8h, w[0-9]+ > >> +** movi v[0-9]+\.8h, 0x1 > >> +** zip1 v[0-9]+\.8h, v[0-9]+\.8h, v[0-9]+\.8h > >> +** ... > >> +** ret > >> +*/ > >> + > >> +int16x8_t foo2(int16_t x) > >> +{ > >> + int16x8_t v = (int16x8_t) {x, 1, x, 1, x, 1, x, 1}; > >> + return v; > >> +}