[PATCH] D46814: [InstCombine] Fold unfolded masked merge pattern with variable mask!

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 23 07:08:42 PDT 2018


lebedev.ri added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:2434-2439
+/// The canonical unfolded masked merge pattern is
+///   (x &  m) | (y & ~m)
+/// But there is a second, equivalent variant:
+///   (x | ~m) & (y |  m)
+/// Only one of them is canonical, i would say, the or-of-and's variant.
+/// And if the mask is not a constant, we should fold it to:
----------------
spatel wrote:
> spatel wrote:
> > I'd reword this because I suspect nobody is going to understand/remember the distinction between 'unfolded', 'folded', and 'canonical':
> > 
> >   /// Bitwise masked merge (bitwise select) is typically coded as:
> >   /// (x & m) | (y & ~m)
> >   /// Another variant is:
> >   /// (x | ~m) | (y | m)
> >   /// Canonicalize those to a form with one less IR instruction:
> >   /// ((x ^ y) & m) ^ y
> > 
> Oops - typo'd the formula:
> 
> //// (x | ~m) & (y | m)
> 
(You obviously meant `/// (x | ~m) & (y | m)`)


Repository:
  rL LLVM

https://reviews.llvm.org/D46814





More information about the llvm-commits mailing list