Re: [PATCH] expand: Convert cst - x into cst xor x.

2022-10-21 Thread Robin Dapp via Gcc-patches
> Do we have evidence that targets properly cost XOR vs SUB RTXen? > > It might actually be a reload optimization - when the constant is > available in a register use 'sub', when it needs to be reloaded > use 'xor'? > > That said, I wonder if the fallout of changing some SUB to XOR > is bigger

Re: [PATCH] expand: Convert cst - x into cst xor x.

2022-09-07 Thread Jeff Law via Gcc-patches
On 9/7/2022 6:45 AM, Richard Biener via Gcc-patches wrote: On Wed, Sep 7, 2022 at 2:20 PM Robin Dapp wrote: The question is really whether xor or sub is "better" statically. I can't think of any reasons. On s390, why does xor end up "better"? There is an xor with immediate (as opposed to

Re: [PATCH] expand: Convert cst - x into cst xor x.

2022-09-07 Thread Richard Biener via Gcc-patches
On Wed, Sep 7, 2022 at 2:20 PM Robin Dapp wrote: > > > The question is really whether xor or sub is "better" statically. I can't > > think of any reasons. On s390, why does xor end up "better"? > > There is an xor with immediate (as opposed to no "subtract from > immediate") which saves an

Re: [PATCH] expand: Convert cst - x into cst xor x.

2022-09-07 Thread Robin Dapp via Gcc-patches
> The question is really whether xor or sub is "better" statically. I can't > think of any reasons. On s390, why does xor end up "better"? There is an xor with immediate (as opposed to no "subtract from immediate") which saves an instruction, usually. On x86, I think the usual argument for xor

Re: [PATCH] expand: Convert cst - x into cst xor x.

2022-09-07 Thread Richard Biener via Gcc-patches
On Tue, Sep 6, 2022 at 4:01 PM Robin Dapp wrote: > > > cost might also depend on the context in case flag setting > > behavior differs for xor vs sub (on x86 sub looks strictly more > > powerful here). The same is probably true when looking for > > a combination with another bitwise operation. >

Re: [PATCH] expand: Convert cst - x into cst xor x.

2022-09-06 Thread Robin Dapp via Gcc-patches
> cost might also depend on the context in case flag setting > behavior differs for xor vs sub (on x86 sub looks strictly more > powerful here). The same is probably true when looking for > a combination with another bitwise operation. > > Btw, why not perform the optimization in expand_binop?

Re: [PATCH] expand: Convert cst - x into cst xor x.

2022-09-06 Thread Richard Biener via Gcc-patches
On Tue, Sep 6, 2022 at 11:42 AM Robin Dapp wrote: > > Hi, > > posting this separately from PR91213 now. I wrote an s390 test and most > likely it could also be done for x86 which will give it broader coverage. > > Depending on the backend it might be better to convert > cst - x > into > cst

[PATCH] expand: Convert cst - x into cst xor x.

2022-09-06 Thread Robin Dapp via Gcc-patches
Hi, posting this separately from PR91213 now. I wrote an s390 test and most likely it could also be done for x86 which will give it broader coverage. Depending on the backend it might be better to convert cst - x into cst xor x if cst + 1 is a power of two and 0 <= x <= cst. This patch