[llvm] [DAG] Recognise AVGFLOOR (((A >> 1) + (B >> 1)) + (A & B & 1)) patterns (PR #169644)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 11 06:02:00 PST 2025


RKSimon wrote:

That can happen in cases where SmallVector<> screws up the CalculateSmallVectorDefaultInlinedElements calculation - please can you try with this local change:

```
diff --git a/llvm/include/llvm/CodeGen/SDPatternMatch.h b/llvm/include/llvm/CodeGen/SDPatternMatch.h
index dda3b3827c7a..4fe4fdcc023e 100644
--- a/llvm/include/llvm/CodeGen/SDPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/SDPatternMatch.h
@@ -1310,7 +1310,7 @@ template <typename... PatternTs> struct ReassociatableOpc_match {
   bool match(const MatchContext &Ctx, SDValue N) {
     constexpr size_t NumPatterns = std::tuple_size_v<std::tuple<PatternTs...>>;

-    SmallVector<SDValue> Leaves;
+    SmallVector<SDValue, 4> Leaves;
     collectLeaves(N, Leaves);
     if (Leaves.size() != NumPatterns)
       return false;
@@ -1323,7 +1323,7 @@ template <typename... PatternTs> struct ReassociatableOpc_match {
         Patterns);
   }

-  void collectLeaves(SDValue V, SmallVector<SDValue> &Leaves) {
+  void collectLeaves(SDValue V, SmallVectorImpl<SDValue> &Leaves) {
     if (V->getOpcode() == Opcode) {
       for (size_t I = 0, N = V->getNumOperands(); I < N; I++)
         collectLeaves(V->getOperand(I), Leaves);
```
(note @bermondd is working on removing the SmallVector entirely)

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


More information about the llvm-commits mailing list