[PATCH] D156026: [InstCombine] Contracting x^2 + 2*x*y + y^2 to (x + y)^2

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 22 08:22:22 PDT 2023


nikic added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp:1618
 
+  // (x * x) + ((x << 1) + y) * y -> (x * y)^2
+  // which is:
----------------
x -> A, y -> B to make it line up with the labels used in the implementation.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp:1621
+  // (x * x) + (2 * x * y) + (y * y) -> (x * y)^2
+  if (match(RHS, m_Mul(m_Value(A), m_Value(B))) && A == B) {
+    Value *C;
----------------



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp:1623-1626
+    if (match(LHS, m_Mul(m_Add(m_Shl(m_Specific(A), m_SpecificInt(1)),
+                                 m_Value(C)),
+                          m_Value(B))) &&
+        B == C) {
----------------



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp:1628
+      Value *AB = Builder.CreateAdd(A, B);
+      return BinaryOperator::CreateMul(AB, AB, I.getName());
+    }
----------------
I.getName() is unnecessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156026



More information about the llvm-commits mailing list