[llvm] LV: Expand llvm.histogram intrinsic to support umax, umin, and uadd.sat operations (PR #127399)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 5 13:42:32 PDT 2026


================
@@ -2186,14 +2198,28 @@ class VPHistogramRecipe : public VPRecipeBase, public VPIRMetadata {
   InstructionCost computeCost(ElementCount VF,
                               VPCostContext &Ctx) const override;
 
-  unsigned getOpcode() const { return Opcode; }
+  HistogramUpdateKind getUpdateKind() const { return UpdateKind; }
+
+  /// Return the histogram intrinsic ID for this recipe's update kind.
+  Intrinsic::ID getHistogramIntrinsicID() const;
+
+  /// Return true if the increment should be negated before passing to the
+  /// histogram intrinsic (only for Sub).
+  bool shouldNegateIncrement() const {
+    return UpdateKind == HistogramUpdateKind::Sub;
+  }
 
   /// Return the mask operand if one was provided, or a null pointer if all
   /// lanes should be executed unconditionally.
   VPValue *getMask() const {
     return getNumOperands() == 3 ? getOperand(2) : nullptr;
   }
 
+  /// Return the HistogramUpdateKind for the given update instruction, or
+  /// std::nullopt if the instruction is not a supported histogram update.
+  static std::optional<HistogramUpdateKind>
+  getUpdateKindForInstruction(Instruction *I);
----------------
fhahn wrote:

this is only used for construction, better not add it to the recipe, but VPRecipeBuilder or make s static function?

Also can assert in the fucntion that we always return a valid kind, instead of returning optional?

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


More information about the llvm-commits mailing list