[PATCH] D147266: [AArch64] Add IR intrinsics for vbsl* C intrinsics

Pranav Kant via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 10 15:05:16 PDT 2023


pranavk updated this revision to Diff 521114.
pranavk added a comment.

[AArch64][InstCombine] Bail out for bitselect instructions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147266

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: D147266.521114.patch
Type: text/x-patch
Size: 1380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230510/157297d8/attachment-0001.bin>


More information about the cfe-commits mailing list