[PATCH] D158079: [InstCombine] Contracting x^2 + 2*x*y + y^2 to (x + y)^2 (float)
Christoph Stiller via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 16 13:51:26 PDT 2023
rainerzufalldererste added inline comments.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp:1059
+ m_FMul(m_Deferred(B), m_Deferred(B))))));
+ }
+
----------------
goldstein.w.n wrote:
> This match code is basically identical to `foldSquareSumInts`. The only difference other than `FMul` vs `Mul` is you do match `FMul(A, 2)` for floats and `m_Shl(A, 1)` for ints.
> Can you make the match code a helper that takes either fmul/2x matcher (or just lambda wrapping) so it can be used for SumFloat / SumInt?
Does that imply that `m_c_FAdd` can simply be replaced with `m_c_Add` and will continue to match properly for floating point values as well?
I presume that would entail partially matching another pattern and then deferring the actual check for the mul2 match, as `BinaryOp_match<RHS, LHS, OpCode>` would have different `OpCode`s for `FMul` and `Shl`, which sounds like a huge mess to me; or is there a cleaner way to do that?
Something like this sadly doesn't compile (as the lambda return type is ambiguous):
```
const auto FpMul2Matcher = [](auto &value) {
return m_FMul(value, m_SpecificFP(2.0));
};
const auto IntMul2Matcher = [](auto &value) {
return m_Shl(value, m_SpecificInt(1));
};
const auto Mul2Matcher = FP ? FpMul2Matcher : IntMul2Matcher;
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D158079/new/
https://reviews.llvm.org/D158079
More information about the llvm-commits
mailing list