[llvm] [SLP] Make getSameOpcode support different instructions if they have same semantics. (PR #112181)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 14 13:46:25 PDT 2024
================
@@ -834,6 +834,105 @@ struct InstructionsState {
} // end anonymous namespace
+struct InterchangeableInstruction {
+ unsigned Opcode;
+ SmallVector<Value *> Ops;
+ template <class... ArgTypes>
+ InterchangeableInstruction(unsigned Opcode, ArgTypes &&...Args)
+ : Opcode(Opcode), Ops{std::forward<decltype(Args)>(Args)...} {}
+};
+
+bool operator<(const InterchangeableInstruction &LHS,
+ const InterchangeableInstruction &RHS) {
+ return LHS.Opcode < RHS.Opcode;
+}
+
+/// \returns a list of interchangeable instructions which \p I can be converted
+/// to.
+/// e.g.,
+/// x << y -> x * (2^y)
+/// x << 1 -> x * 2
+/// x << 0 -> x * 1 -> x - 0 -> x + 0 -> x & 11...1 -> x | 0
+/// x * 0 -> x & 0
+/// x * -1 -> 0 - x
+/// TODO: support more patterns
+static SmallVector<InterchangeableInstruction, 6>
----------------
alexey-bataev wrote:
Better to use `SmallVector<InterchangeableInstruction>`
https://github.com/llvm/llvm-project/pull/112181
More information about the llvm-commits
mailing list