[llvm] [SLP]Model or-reduction of masked shifted lanes as a bitfield pack (PR #219731)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 11:09:29 PDT 2026


================
@@ -305,4 +305,69 @@ InstructionCost getBoolReduxBitcastCmpCost(const TargetTransformInfo &TTI,
                                 TTI.getOperandInfo(CmpRHS), CmpI);
 }
 
+InstructionCost getBitPackCost(const TargetTransformInfo &TTI,
+                               FixedVectorType *SrcTy, Type *ResultTy,
+                               const BitPackInfo &Info, bool FreeByteTrunc,
+                               TTI::TargetCostKind CostKind,
+                               const TargetLibraryInfo *TLI,
+                               const Instruction *CxtI, unsigned &ShiftWidth) {
+  unsigned BitWidth = SrcTy->getScalarSizeInBits();
+  unsigned NumElts = SrcTy->getNumElements();
+  uint64_t MaxAmt = *max_element(Info.LShrAmts);
+  // The shift amounts form a constant vector.
+  TTI::OperandValueInfo ShiftAmtInfo = {
+      all_of(Info.LShrAmts,
+             [&](uint64_t A) { return A == Info.LShrAmts.front(); })
+          ? TTI::OK_UniformConstantValue
+          : TTI::OK_NonUniformConstantValue,
+      all_of(Info.LShrAmts, isPowerOf2_64) ? TTI::OP_PowerOf2 : TTI::OP_None};
+  // After the shift the field content of each lane sits in the low bits of
+  // the lane, so the packing is a single byte shuffle of the shifted lanes.
+  // Pick the cheapest shift width: the narrowest type still holding the field
+  // content is not always the cheapest (e.g. missing narrow variable shifts).
+  Type *Int8Ty = IntegerType::get(SrcTy->getContext(), 8);
+  unsigned OutBytes = BitWidth / 8;
----------------
alexey-bataev wrote:

Will add assertion

https://github.com/llvm/llvm-project/pull/219731


More information about the llvm-commits mailing list