Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-07 Thread Andrew Pinski
On Mon, Aug 7, 2017 at 1:36 PM, Michael Collison wrote: > This patch improves code generation for shifts with subtract instructions > where the first operand to the subtract is equal to the bit-size of the > operation. > > > long f1(long x, int i) > { > return x >> (64 - i); > } > > int f2(int

Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-07 Thread Richard Kenner
> This patch improves code generation for shifts with subtract > instructions where the first operand to the subtract is equal to the > bit-size of the operation. I would suspect that this will work on lots of targets. Is doing it in combine an option?

Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-07 Thread Richard Kenner
> That is simplify: > (SHIFT A (32 - B)) -> (SHIFT A (AND (NEG B) 31)) > etc. I think you need SHIFT_COUNT_TRUNCATED to be true for this to be valid, but this is exactly what I was getting at in my last message.

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-07 Thread Michael Collison
, 2017 2:02 PM To: pins...@gmail.com Cc: gcc-patches@gcc.gnu.org; Michael Collison ; nd Subject: Re: [PATCH] [Aarch64] Optimize subtract in shift counts > That is simplify: > (SHIFT A (32 - B)) -> (SHIFT A (AND (NEG B) 31)) etc. I think you need SHIFT_COUNT_TRUNCATED to be true for t

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-07 Thread Richard Kenner
> On Aarc64 SHIFT_COUNT_TRUNCATED is only true if SIMD code generation > is disabled. This is because the simd instructions can be used for > shifting but they do not truncate the shift count. In that case, the change isn't safe! Consider if the value was negative, for example. Yes, it's technic

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-07 Thread Michael Collison
-patches@gcc.gnu.org; nd ; pins...@gmail.com Subject: RE: [PATCH] [Aarch64] Optimize subtract in shift counts > On Aarc64 SHIFT_COUNT_TRUNCATED is only true if SIMD code generation > is disabled. This is because the simd instructions can be used for > shifting but they do not truncate the sh

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-08 Thread Wilco Dijkstra
Richard Kenner wrote: >Michael Collison wrote: > > On Aarc64 SHIFT_COUNT_TRUNCATED is only true if SIMD code generation > > is disabled. This is because the simd instructions can be used for > > shifting but they do not truncate the shift count. > > In that case, the change isn't safe! Consider if

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-08 Thread Richard Kenner
> The pattern will only be matched if the value is positive. More > specifically if the constant value is 32 (SImode) or 64 (DImode). I don't mean the constant, but the value subtracted from it. If that's negative, then we have a shift count larger than the wordsize.

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-08 Thread Michael Collison
pins...@gmail.com Subject: RE: [PATCH] [Aarch64] Optimize subtract in shift counts > The pattern will only be matched if the value is positive. More > specifically if the constant value is 32 (SImode) or 64 (DImode). I don't mean the constant, but the value subtracted from it. If that

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-08 Thread Richard Kenner
> This case is covered by Wilco's previous reply: > > https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00575.html Which I don't understand: > No it's perfectly safe - it becomes an integer-only shift after the > split since it keeps the masking as part of the pattern. Let say we have your first ex

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-08 Thread Michael Collison
.ultra.nyu.edu] Sent: Tuesday, August 8, 2017 12:52 PM To: Michael Collison Cc: gcc-patches@gcc.gnu.org; nd ; pins...@gmail.com Subject: RE: [PATCH] [Aarch64] Optimize subtract in shift counts > This case is covered by Wilco's previous reply: > > https://gcc.gnu.org/ml/gcc-patches/2017-08

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-08 Thread Richard Kenner
> Because for integer shift instructions the shift count is > truncated. We ensure that we only use integer shift instructions by > emitting a shift with a mask. This only matches integer shift > instructions in the md file. That's why I asked about SHIFT_COUNT_TRUNCATED. So it's truncated for so

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-08 Thread Michael Collison
: Michael Collison Cc: gcc-patches@gcc.gnu.org; nd ; pins...@gmail.com Subject: RE: [PATCH] [Aarch64] Optimize subtract in shift counts > Because for integer shift instructions the shift count is truncated. > We ensure that we only use integer shift instructions by emitting a > shift with a m

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-08 Thread Richard Kenner
> Correct. It is truncated for integer shift, but not simd shift > instructions. We generate a pattern in the split that only generates > the integer shift instructions. That's unfortunate, because it would be nice to do this in simplify_rtx, since it's machine-independent, but that has to be cond

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-08 Thread Michael Collison
Correct. -Original Message- From: Richard Kenner [mailto:ken...@vlsi1.ultra.nyu.edu] Sent: Tuesday, August 8, 2017 1:20 PM To: Michael Collison Cc: gcc-patches@gcc.gnu.org; nd ; pins...@gmail.com Subject: RE: [PATCH] [Aarch64] Optimize subtract in shift counts > Correct. It

Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-14 Thread Richard Biener
On Tue, Aug 8, 2017 at 10:20 PM, Richard Kenner wrote: >> Correct. It is truncated for integer shift, but not simd shift >> instructions. We generate a pattern in the split that only generates >> the integer shift instructions. > > That's unfortunate, because it would be nice to do this in simplif

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-14 Thread Michael Collison
, August 14, 2017 1:27 AM To: Richard Kenner Cc: Michael Collison ; GCC Patches ; nd ; Andrew Pinski Subject: Re: [PATCH] [Aarch64] Optimize subtract in shift counts On Tue, Aug 8, 2017 at 10:20 PM, Richard Kenner wrote: >> Correct. It is truncated for integer shift, but not simd

Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-21 Thread Richard Sandiford
Richard Biener writes: > On Tue, Aug 8, 2017 at 10:20 PM, Richard Kenner > wrote: >>> Correct. It is truncated for integer shift, but not simd shift >>> instructions. We generate a pattern in the split that only generates >>> the integer shift instructions. >> >> That's unfortunate, because it wo

Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-21 Thread Richard Biener
On August 21, 2017 7:46:09 PM GMT+02:00, Richard Sandiford wrote: >Richard Biener writes: >> On Tue, Aug 8, 2017 at 10:20 PM, Richard Kenner >> wrote: Correct. It is truncated for integer shift, but not simd shift instructions. We generate a pattern in the split that only >generates >

Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-22 Thread Richard Sandiford
Richard Biener writes: > On August 21, 2017 7:46:09 PM GMT+02:00, Richard Sandiford > wrote: >>Richard Biener writes: >>> On Tue, Aug 8, 2017 at 10:20 PM, Richard Kenner >>> wrote: > Correct. It is truncated for integer shift, but not simd shift > instructions. We generate a pattern in

Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-22 Thread Richard Biener
On Tue, Aug 22, 2017 at 9:29 AM, Richard Sandiford wrote: > Richard Biener writes: >> On August 21, 2017 7:46:09 PM GMT+02:00, Richard Sandiford >> wrote: >>>Richard Biener writes: On Tue, Aug 8, 2017 at 10:20 PM, Richard Kenner wrote: >> Correct. It is truncated for integer shif

Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-22 Thread Richard Sandiford
Richard Biener writes: > On Tue, Aug 22, 2017 at 9:29 AM, Richard Sandiford > wrote: >> Richard Biener writes: >>> On August 21, 2017 7:46:09 PM GMT+02:00, Richard Sandiford >>> wrote: Richard Biener writes: > On Tue, Aug 8, 2017 at 10:20 PM, Richard Kenner > wrote: >>> Correc

Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-08-22 Thread Wilco Dijkstra
Hi, The main reason we have this issue is that DImode can be treated as a vector of size 1. As a result we do not know whether the shift is an integer or SIMD instruction. One way around this is to never use the SIMD variant, another is to introduce V1DImode for vectors of size 1. Short term I be

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-09-06 Thread Michael Collison
chard Biener Cc: Richard Kenner ; Michael Collison ; GCC Patches ; nd ; Andrew Pinski Subject: Re: [PATCH] [Aarch64] Optimize subtract in shift counts Richard Biener writes: > On Tue, Aug 22, 2017 at 9:29 AM, Richard Sandiford > wrote: >> Richard Biener writes: >>> On Augu

Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-09-06 Thread Richard Sandiford
-Original Message- > From: Richard Sandiford [mailto:richard.sandif...@linaro.org] > Sent: Tuesday, August 22, 2017 9:11 AM > To: Richard Biener > Cc: Richard Kenner ; Michael Collison > ; GCC Patches ; nd > ; Andrew Pinski > Subject: Re: [PATCH] [Aarch64] Optimize subtr

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-09-06 Thread Michael Collison
, September 6, 2017 11:32 AM To: Michael Collison Cc: Richard Biener ; Richard Kenner ; GCC Patches ; nd ; Andrew Pinski Subject: Re: [PATCH] [Aarch64] Optimize subtract in shift counts Michael Collison writes: > Richard Sandiford do you have any objections to the patch as it stands? > It d

Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-09-06 Thread Richard Sandiford
Original Message- > From: Richard Sandiford [mailto:richard.sandif...@linaro.org] > Sent: Wednesday, September 6, 2017 11:32 AM > To: Michael Collison > Cc: Richard Biener ; Richard Kenner > ; GCC Patches ; nd > ; Andrew Pinski > Subject: Re: [PATCH] [Aarch64] Optimize sub

Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-09-06 Thread Richard Sandiford
gt; nicely-contained piece of work. >> >> Thanks, >> Richard >> >>> -Original Message- >>> From: Richard Sandiford [mailto:richard.sandif...@linaro.org] >>> Sent: Tuesday, August 22, 2017 9:11 AM >>> To: Richard Biener >>&

Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-09-06 Thread Richard Sandiford
Richard Sandiford writes: > Richard Sandiford writes: >> Michael Collison writes: >>> Richard, >>> >>> The problem with this approach for Aarch64 is that >>> TARGET_SHIFT_TRUNCATION_MASK is based on SHIFT_COUNT_TRUNCATED which is >>> normally 0 as it based on the TARGET_SIMD flag. >> >> Maybe I'

RE: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-09-15 Thread Michael Collison
. -Original Message- From: Richard Sandiford [mailto:richard.sandif...@linaro.org] Sent: Wednesday, September 6, 2017 10:22 AM To: Michael Collison Cc: Richard Biener ; Richard Kenner ; GCC Patches ; nd ; Andrew Pinski Subject: Re: [PATCH] [Aarch64] Optimize subtract in shift counts Richard

Re: [PATCH] [Aarch64] Optimize subtract in shift counts

2017-09-29 Thread James Greenhalgh
On Fri, Sep 15, 2017 at 09:15:17AM +0100, Michael Collison wrote: > Patch updated with comments to simplify pattern .from Richard Sandiford. Okay > for trunk? OK. Thanks, James > > 2017-09-14 Michael Collison > > * config/aarch64/aarch64.md (*aarch64_reg__minus3): > New pattern.