[PATCH] D150316: [AArch64][InstCombine] Bail out for bitselet instructions

Pranav Kant via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 10 15:14:34 PDT 2023


pranavk created this revision.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
pranavk requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150316

Files:
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp


Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -56,6 +56,29 @@
 ///
 /// FIXME: It's possible to create more instructions than previously existed.
 static bool cheapToScalarize(Value *V, Value *EI) {
+  // Pattern: or(and(a, mask), and(b, ~mask)) can be efficiently folded to bitselect instructions
+  // where ~mask = xor mask, -1
+  if (isa<Instruction>(V)) {
+    Instruction *TI = cast<Instruction>(V);
+    if (TI->getOpcode() == Instruction::Or) {
+      Value *LHS = TI->getOperand(0);
+      Value *RHS = TI->getOperand(1);
+      Value *MaskValue = nullptr;
+      Value *MaskConst = nullptr;
+
+      if (match(LHS, m_And(m_Value(), m_Value(MaskValue))) &&
+          match(RHS, m_And(m_Value(), m_Xor(m_Specific(MaskValue), m_Value(MaskConst))))) {
+        if (auto *CI = dyn_cast<ConstantDataVector>(MaskConst)) {
+          Constant *C = CI->getSplatValue();
+          if (C->isAllOnesValue()) {
+            llvm::outs() << "return false from cheap\n";
+            return false;
+          }
+        }
+      }
+    }
+  }
+
   ConstantInt *CEI = dyn_cast<ConstantInt>(EI);
 
   // If we can pick a scalar constant value out of a vector, that is free.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150316.521118.patch
Type: text/x-patch
Size: 1380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230510/b0e5476b/attachment.bin>


More information about the llvm-commits mailing list