[PATCH] D133362: [InstCombine] Fold x + (x | -x) to x & (x - 1)

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 6 12:12:53 PDT 2022


spatel added inline comments.


================
Comment at: llvm/test/Transforms/InstCombine/add_or_sub.ll:26
+  ret i8 %add
+}
----------------
marcauberer wrote:
> RKSimon wrote:
> > vector cases? multiuse cases? negative cases?
> I just added vector and multi-use cases. How do I do negative cases?
For each positive condition in the match statement(s), create a test that does not satisfy the requirement.

So for example, we're looking for a negate (sub) of a specific operand in the 'or', then create a test with a negate of a different value:
  %sub = sub i8 0, %y  <-- mismatch, so this should not transform
  %or = or i8 %sub, %x
  %add = add i8 %or, %x

Or maybe the 'sub' isn't a negate; it might be: (1 - x). Change the 'or' to an 'xor', etc.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133362



More information about the llvm-commits mailing list