[llvm] [SandboxVec][Legality] Check opcodes and types (PR #113741)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 28 13:48:16 PDT 2024


================
@@ -26,7 +27,25 @@ void LegalityResult::dump() const {
 std::optional<ResultReason>
 LegalityAnalysis::notVectorizableBasedOnOpcodesAndTypes(
     ArrayRef<Value *> Bndl) {
-  // TODO: Unimplemented.
+  auto *I0 = cast<Instruction>(Bndl[0]);
+  auto Opcode = I0->getOpcode();
+  // If they have different opcodes, then we cannot form a vector (for now).
+  if (any_of(drop_begin(Bndl), [Opcode](Value *V) {
+        return cast<Instruction>(V)->getOpcode() != Opcode;
+      }))
+    return ResultReason::DiffOpcodes;
+
+  // If not the same scalar type, Pack. This will accept scalars and vectors as
+  // long as the element type is the same.
+  Type *ElmTy0 = VecUtils::getElementType(Utils::getExpectedType(I0));
+  for (auto *V : drop_begin(Bndl)) {
+    Type *ElmTy = VecUtils::getElementType(Utils::getExpectedType(V));
+    if (ElmTy != ElmTy0)
+      return ResultReason::DiffTypes;
+  }
----------------
vporpo wrote:

Done.

https://github.com/llvm/llvm-project/pull/113741


More information about the llvm-commits mailing list