[Bug target/94789] Failure to take advantage of shift operand semantics to turn subtraction into negate

2024-02-27 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94789

Andrew Pinski  changed:

   What|Removed |Added

 Target|x86_64-*-* i?86-*-* aarch64 |x86_64-*-* i?86-*-*

--- Comment #5 from Andrew Pinski  ---
(In reply to Wilco from comment #4)
> AArch64 already generates:
> 
>   neg w1, w1
>   lsl w0, w0, w1
>   ret

aarch64 is because it has a pattern to optimize this explictly:
(insn 14 9 15 2 (set (reg/i:SI 0 x0)
(ashift:SI (reg:SI 108)
(minus:QI (const_int 32 [0x20])
(subreg:QI (reg:SI 109) 0 "/app/example.cpp":5:1 744
{*aarch64_ashl_reg_minussi3}
 (expr_list:REG_DEAD (reg:SI 108)
(expr_list:REG_DEAD (reg:SI 109)
(nil

Which was added in r8-3672-g59abe903987d61 .  Maybe the x86_64 backend do a
similar thing?

[Bug target/94789] Failure to take advantage of shift operand semantics to turn subtraction into negate

2021-09-04 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94789

Andrew Pinski  changed:

   What|Removed |Added

   Severity|normal  |enhancement

[Bug target/94789] Failure to take advantage of shift operand semantics to turn subtraction into negate

2020-04-29 Thread wilco at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94789

Wilco  changed:

   What|Removed |Added

 CC||wilco at gcc dot gnu.org

--- Comment #4 from Wilco  ---
(In reply to Gabriel Ravier from comment #0)
> int r(int x, unsigned b)
> {
> int const m = CHAR_BIT * sizeof(x) - b;
> return (x << m);
> }
> 
> `CHAR_BIT * sizeof(x) - b;` can be optimized to `-b`. LLVM does this
> transformation, not GCC.
> 
> Comparison here : https://godbolt.org/z/5byJ2E

AArch64 already generates:

  neg w1, w1
  lsl w0, w0, w1
  ret

[Bug target/94789] Failure to take advantage of shift operand semantics to turn subtraction into negate

2020-04-27 Thread gabravier at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94789

--- Comment #3 from Gabriel Ravier  ---
>From what I've seen, this optimisation could be useful on at least these
targets : 
- x86_64
- i686
- aarch64

On other architectures I've looked at, either the optimization can't be done
and/or it's useless because those architectures are capable of doing `32 - b`
in a single instruction

[Bug target/94789] Failure to take advantage of shift operand semantics to turn subtraction into negate

2020-04-27 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94789

--- Comment #2 from Andrew Pinski  ---
Maybe (-b)&31 instead? And then the &31 could optimized out later on?

[Bug target/94789] Failure to take advantage of shift operand semantics to turn subtraction into negate

2020-04-27 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94789

Richard Biener  changed:

   What|Removed |Added

   Last reconfirmed||2020-04-27
 Ever confirmed|0   |1
 Target||x86_64-*-* i?86-*-*
   Keywords||missed-optimization
 Status|UNCONFIRMED |NEW
  Component|tree-optimization   |target

--- Comment #1 from Richard Biener  ---
Hmm, that looks target dependent to me.  We'd take advanage of the targts
handling of out-of-bound shift operands?