Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Failure to optimize followed xors into seperate xors to avoid mov #44744

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR45774
Status NEW
Importance P enhancement
Reported by Gabriel Ravier (gabravier@gmail.com)
Reported on 2020-05-01 15:51:17 -0700
Last modified on 2020-05-02 01:17:05 -0700
Version trunk
Hardware PC Linux
CC lebedev.ri@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
int f(int x, int y, int c)
{
    return (x - y - c) ^ x ^ y;
}

With -O3, GCC outputs this :

f:
  mov eax, edi
  xor edi, esi
  sub eax, esi
  sub eax, edx
  xor eax, edi
  ret

Clang outputs this :

f:
  mov eax, esi
  mov ecx, edi
  sub ecx, esi
  sub ecx, edx
  xor eax, edi
  xor eax, ecx
  ret
Quuxplusone commented 4 years ago
Won't comment on `mov`s, but we shouldn't even have two sub's there.
https://godbolt.org/z/oxMUx_

We're missing  (a-b)-c -> a-(b+c)  instcombine fold to recover from reassociate.