[PATCH] D133695: [InstCombine] Optimize multiplication where both operands are negated

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 06:15:34 PDT 2022


spatel added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp:1834
+    // Optimize multiplication where both operators are negated
+    // ~A * ~ B = A * B
+    Value *Op0 = II->getArgOperand(0);
----------------
I read "~" as "bitwise not". I expect this comment to be something like this:
 // -[A] * -[B] --> [A] * [B]


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp:1838-1839
+    if (match(Op0, m_FNeg(m_Value())) && match(Op1, m_FNeg(m_Value()))) {
+      Value *Op0NotNeg = cast<Instruction>(Op0)->getOperand(0);
+      Value *Op1NotNeg = cast<Instruction>(Op1)->getOperand(0);
+      replaceOperand(*II, 0, Op0NotNeg);
----------------
The casting is unnecessary, and the code doesn't match the code comment. Capture the source values as "A" and "B" inside the match() statement (the same way it is done in the existing variants of this transform).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133695



More information about the llvm-commits mailing list