[PATCH] D155218: [InstCombine] Optimize addition/subtraction operations of splats of vscale multiplied by a constant

Igor Kirillov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 7 05:37:00 PDT 2023


igor.kirillov marked 2 inline comments as done.
igor.kirillov added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:1599-1602
+  if (match(&Inst,
+            m_c_Add(m_c_Add(m_Value(A), m_SplatVscale), m_SplatVscale)) &&
+      match(&Inst, m_c_Add(m_c_Add(m_Specific(A), m_Instruction(SplatB)),
+                           m_Instruction(SplatC)))) {
----------------
paulwalker-arm wrote:
> This seems wasteful given the number of times you're matching `m_SplatVscale`.  Perhaps drop the first `match` from all the `if` blocks and then once you've figured out the add/sub combo you can have a single block that does:
> ```
> if (!match(SplatB, m_SplatVscale) || !match(SplatC, m_SplatVscale))
>   return nullptr;
> ```
> 
> Perhaps you don't even need `m_SplatVscale` because `getSplatValue` returns null on failure so the check could be:
> ```
> if (!B || !match(B, m_ConstMultipliedVscale) ||
>     !C || !match(C, m_ConstMultipliedVscale))
>   return nullptr;
> ```
What do you think about this version? My first version was using `getSplatValue`, but then I had to decide the exact order of A, B and C. Using the current approach, we can first match A, SpatB, SplatC and then match the exact add/sub operations without calling splat matcher several times.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155218



More information about the llvm-commits mailing list