llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.36k stars 12.14k forks source link

Missed peephole: xor-inc-add to xor-sub #44992

Open LebedevRI opened 4 years ago

LebedevRI commented 4 years ago
Bugzilla Link 45647
Version trunk
OS Linux
CC @nikic,@rotateright

Extended Description

define i8 @square(i8 %x, i8 %y) {
    %t0 = xor i8 %x, -43
    %t1 = add i8 %t0, 1
    %r = add i8 %t1, %y
    ret i8 %r
}

https://godbolt.org/z/EpjvTY

Name: zz
  %t0 = xor i8 %x, -43
  %t1 = add i8 %t0, 1
  %r = add i8 %t1, %y
  ret i8 %r
=>
  %n0 = xor i8 %x, 42
  %r = sub i8 %y, %n0
  ret i8 %r
  %t0 = xor i8 %x, -43
  %t1 = add i8 %t0, 1

Done: 1
Transformation seems to be correct!
LebedevRI commented 4 years ago

I.e. we are missing an inverse-ish transform for https://reviews.llvm.org/D77459

dtcxzyw commented 5 months ago

https://alive2.llvm.org/ce/z/DazrgT