[PATCH] D85593: [InstCombine] ~(~X + Y) -> X - Y

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 9 07:23:42 PDT 2020


lebedev.ri added inline comments.


================
Comment at: llvm/test/Transforms/InstCombine/not-add.ll:94
+; CHECK-NEXT:    [[A:%.*]] = add i8 [[NOTX]], [[Y:%.*]]
+; CHECK-NEXT:    call void @use(i8 [[A]])
+; CHECK-NEXT:    [[NOTA:%.*]] = xor i8 [[A]], -1
----------------
nikic wrote:
> xbolva00 wrote:
> > spatel wrote:
> > > xbolva00 wrote:
> > > > @lebedev.ri
> > > > 
> > > > not seems better than sub x, y so oneuse check is ok (?)
> > > It's true that in some cases (for example, expensive FP ops), we have leaned toward a more restrictive one-use check.
> > > 
> > > In this case, however, I do not think that the relative analysis improvement of an xor vs. sub should limit the transform. 
> > > 
> > > Reducing the number of operand uses and dependency chain could allow follow-on improvements.
> > Ok, thanks. Will drop it.
> Is this transform even legal without the one-use restriction? It *increases* the number of uses, as such it's not obvious that it the transform without one-use restriction is undef-safe.
> Is this transform even legal without the one-use restriction? It *increases* the number of uses, as such it's not obvious that it the transform without one-use restriction is undef-safe.

Increased instruction count is only a legality issue
if it is increased for the computation of the value,
which isn't the case here.
Otherwise basically every instcombine fold would be invalid.
```
----------------------------------------
define i8 @src(i8 %x, i8 %y) {
%0:
  %notx = xor i8 %x, 255
  %a = add i8 %notx, %y
  %nota = xor i8 %a, 255
  call void @use(i8 %notx)
  call void @use(i8 %a)
  ret i8 %nota
}
=>
define i8 @tgt(i8 %x, i8 %y) {
%0:
  %notx = xor i8 %x, 255
  %a = add i8 %notx, %y
  %s = sub i8 %x, %y
  call void @use(i8 %notx)
  call void @use(i8 %a)
  ret i8 %s
}
Transformation seems to be correct!

```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85593/new/

https://reviews.llvm.org/D85593



More information about the llvm-commits mailing list