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

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 23 07:06:00 PDT 2018


spatel accepted this revision.
spatel added a comment.
This revision is now accepted and ready to land.

LGTM - see inline for a possible improvement on the code comment.

Thanks for seeing this through!



================
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:
----------------
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



Repository:
  rL LLVM

https://reviews.llvm.org/D46814





More information about the llvm-commits mailing list