[SLP][NFC] Restructure getInsertIndex
authorskc7 <Krishna.Sankisa@amd.com>
Mon, 7 Nov 2022 15:58:03 +0000 (21:28 +0530)
committerskc7 <Krishna.Sankisa@amd.com>
Tue, 8 Nov 2022 12:37:50 +0000 (18:07 +0530)
Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D137567

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

index fe4c2c7..eb22d9f 100644 (file)
@@ -290,15 +290,17 @@ static Optional<unsigned> getInsertIndex(const Value *InsertInst,
                                          unsigned Offset = 0) {
   int Index = Offset;
   if (const auto *IE = dyn_cast<InsertElementInst>(InsertInst)) {
-    if (const auto *CI = dyn_cast<ConstantInt>(IE->getOperand(2))) {
-      auto *VT = cast<FixedVectorType>(IE->getType());
-      if (CI->getValue().uge(VT->getNumElements()))
-        return None;
-      Index *= VT->getNumElements();
-      Index += CI->getZExtValue();
-      return Index;
-    }
-    return None;
+    const auto *VT = dyn_cast<FixedVectorType>(IE->getType());
+    if (!VT)
+      return None;
+    const auto *CI = dyn_cast<ConstantInt>(IE->getOperand(2));
+    if (!CI)
+      return None;
+    if (CI->getValue().uge(VT->getNumElements()))
+      return None;
+    Index *= VT->getNumElements();
+    Index += CI->getZExtValue();
+    return Index;
   }
 
   const auto *IV = cast<InsertValueInst>(InsertInst);