[PATCH] D112754: X86: Fold masked merge pattern when and-not is not available

Matthias Braun via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 28 13:48:55 PDT 2021


MatzeB created this revision.
MatzeB added reviewers: lebedev.ri, spatel, RKSimon, nikic.
Herald added subscribers: modimo, wenlei, steven.zhang, pengfei, hiraditya, mcrosier.
MatzeB requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

There are two equivalent expressions to compute a "masked merge":
a)   (m & x) | (~m & y)
b)   ((x ^ y) & m) ^ y

Variant a) is preferable when an and-not instruction is available and we already optimize for that (see `DAGCombiner::unfoldMaskedMerge`). This adds the reverse operation `TargetLowering::foldMaskedMerge` and uses it in the X86 target when and-not is not available (it's part of the BMI extension so not present on older cores). This speed up cryptographic hash functions (I've seen it in md5 and sha256 implementations).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112754

Files:
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.h
  llvm/test/CodeGen/X86/fold-masked-merge.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112754.383152.patch
Type: text/x-patch
Size: 6970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211028/d1b539cc/attachment.bin>


More information about the llvm-commits mailing list