From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id 8B65C3858C2D for ; Fri, 19 Jan 2024 11:03:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8B65C3858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8B65C3858C2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::134 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705662238; cv=none; b=YO17DTGNbRzgziuWmLIfBjWMAyIDXay9BrBUtQnnYVK8nIMYenfCgMrXqFAeLvzniWQW4OYM1T9imoNDSXLekeBdm0xq2Ac47zdJcoBB1XH+8b+n322r1m7BO+c9eGrkL062g0oxDwpYpuZalkOoISNugk0OTiyc3xX/zbTYaGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705662238; c=relaxed/simple; bh=A9b4ZBuwSDawEc5EB0yy/Soun9mfi6uSg4R368Gh2MY=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=UXsLgsxMa53I1sRRr0OIHxyI1LZ6XytrgxGnSGaB22S4EPKDBOjWdUCtsvUJUgOq72Z5Y3e0qlpiZs9ShMA4YEV7nFRdgcxy6YsmOZ4ncH87VV4e3ul01Tz/MnmicgcbBE5RHIin6UnasFAwll2ycgCZuYDcxsSJLRlQpzhVjZU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-50e4e3323a6so1887097e87.0 for ; Fri, 19 Jan 2024 03:03:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705662235; x=1706267035; darn=gcc.gnu.org; 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=e2Lt4/JkXi8BfKc9EElqoUs8PHyeVlbTAjhhnIXWHE8=; b=exblbVgbdGswAOUgepoVLzOzyILwIBJasmL08xjGUMjWIpjU/+lAh3Mpy6HZYY1hbw xVCtGRxUQVk57N9WnsXZLBrAOwpwOF0hbfuJVJ0F2nBTUEY/bZSyKAzTcVNbUIAH9YQR lUudN2nlD/jHyIt2K4mXhe0LQspeZlogjqyuKC1qLCADhOnN+kcqgb2RFjklslp836/q pPTIiC2pYQHjuEtE3BY9jSOS/TzRQssvfbY9uBGOzCBnvjhLhdQfx7SQieFoZ580DWRu aqgQ/5VC8HnO3ulGHW1nuuN80vhCrqOk3uEV8YoYfXOQ/B3SWjQLE/eKfKJl+piiRiX/ w02g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705662235; x=1706267035; 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=e2Lt4/JkXi8BfKc9EElqoUs8PHyeVlbTAjhhnIXWHE8=; b=MGrb0VB2Xp/wqrTEyoQpXzGjvj0bPTksNLrHzZpgb8U4lVdi6jVdPZbgD5b1u96kPN kLl1x/xPtn21t6hII4yau6EXd3HGfQb3yro1Uqr2cNHCiwc9GKI5ZvAX2Mlyfn1hyH+V HiOGyLPjlZQSP6DdLZ7IDHDMyFazjw+hj5fJYD7eqVrtkxeoiaaufceoj9UB1PPT3xIq syr+5KA0sSC5ffDikkBvQX1Jq7LEFo7B3oXMdve01hSHyjhMpHDsvIsdYDMQhmJCeaP2 kKRYPsnUjs5reztcnns4cXdUJa+wwQR6iKWQDOHeUSu1Cze/Ds/sEBX7arBrIOyPamsk y/3Q== X-Gm-Message-State: AOJu0YxbegWUpgzbpsWDOkrhb+uOvXcq8h7W1zBJ7oUYIs+reAcsn+lp 3Hg8aw17O+zkd2QEh1ItZZUJrxmIRuHOKSVvMgSedTaW77OJx8K+L1GKMgoDFw5hEwrXLAwRuO0 kdl3BWrtDdAB6BytJ7XHayA/yVEuffJxd4yQ= X-Google-Smtp-Source: AGHT+IHJu7ULje63hj0tUIsJMDldN1EZWqA95NvYb6CJLraKvjVxPpVm9QEdJf/ce6ZOg/2wo6g1mu2gD0++C08Eyck= X-Received: by 2002:a19:645a:0:b0:50e:7508:4242 with SMTP id b26-20020a19645a000000b0050e75084242mr506707lfj.0.1705662234583; Fri, 19 Jan 2024 03:03:54 -0800 (PST) MIME-Version: 1.0 References: <023501da4a48$320e7540$962b5fc0$@nextmovesoftware.com> In-Reply-To: <023501da4a48$320e7540$962b5fc0$@nextmovesoftware.com> From: Richard Biener Date: Fri, 19 Jan 2024 12:03:43 +0100 Message-ID: Subject: Re: [middle-end PATCH] Prefer PLUS over IOR in RTL expansion of multi-word shifts/rotates. To: Roger Sayle Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.5 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,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 Thu, Jan 18, 2024 at 8:55=E2=80=AFPM Roger Sayle wrote: > > > This patch tweaks RTL expansion of multi-word shifts and rotates to use > PLUS rather than IOR for disjunctive operations. During expansion of > these operations, the middle-end creates RTL like (X<>C2) > where the constants C1 and C2 guarantee that bits don't overlap. > Hence the IOR can be performed by any any_or_plus operation, such as > IOR, XOR or PLUS; for word-size operations where carry chains aren't > an issue these should all be equally fast (single-cycle) instructions. > The benefit of this change is that targets with shift-and-add insns, > like x86's lea, can benefit from the LSHIFT-ADD form. > > An example of a backend that benefits is ARC, which is demonstrated > by these two simple functions: > > unsigned long long foo(unsigned long long x) { return x<<2; } > > which with -O2 is currently compiled to: > > foo: lsr r2,r0,30 > asl_s r1,r1,2 > asl_s r0,r0,2 > j_s.d [blink] > or_s r1,r1,r2 > > with this patch becomes: > > foo: lsr r2,r0,30 > add2 r1,r2,r1 > j_s.d [blink] > asl_s r0,r0,2 > > unsigned long long bar(unsigned long long x) { return (x<<2)|(x>>62); } > > which with -O2 is currently compiled to 6 insns + return: > > bar: lsr r12,r0,30 > asl_s r3,r1,2 > asl_s r0,r0,2 > lsr_s r1,r1,30 > or_s r0,r0,r1 > j_s.d [blink] > or r1,r12,r3 > > with this patch becomes 4 insns + return: > > bar: lsr r3,r1,30 > lsr r2,r0,30 > add2 r1,r2,r1 > j_s.d [blink] > add2 r0,r3,r0 > > > This patch has been tested on x86_64-pc-linux-gnu with make bootstrap > and make -k check, both with and without --target_board=3Dunix{-m32} > with no new failures. Ok for mainline? For expand_shift_1 you add + where C is the bitsize of A. If N cannot be zero, + use PLUS instead of IOR. but I don't see a check ensuring this other than mabe CONST_INT_P (op1) suggesting that we enver end up with const0_rtx here. OTOH why is N zero a problem and why is it not in the optabs.cc case where I don't see any such check (at least not obvious)? Since this doesn't seem to fix a regression it probably has to wait for stage1 to re-open. Thanks, Richard. > > 2024-01-18 Roger Sayle > > gcc/ChangeLog > * expmed.cc (expand_shift_1): Use add_optab instead of ior_optab > to generate PLUS instead or IOR when unioning disjoint bitfields. > * optabs.cc (expand_subword_shift): Likewise. > (expand_binop): Likewise for double-word rotate. > > > Thanks in advance, > Roger > -- >