[InstCombine] Some cleanup in optimization of redundant insertvalue instructions.
[oota-llvm.git] / lib / Transforms / InstCombine / InstCombineVectorOps.cpp
index 80c20b70758e5004f9df35735b7e7af8cd070313..b072b4d422dd75f5218d090aeb4de5287e19a0a6 100644 (file)
@@ -506,13 +506,12 @@ Instruction *InstCombiner::visitInsertValueInst(InsertValueInst &I) {
   // chain), check if any of the 'children' uses the same indices as the first
   // instruction. In this case, the first one is redundant.
   Value *V = &I;
-  unsigned int Depth = 0;
+  unsigned Depth = 0;
   while (V->hasOneUse() && Depth < 10) {
     User *U = V->user_back();
-    InsertValueInst *UserInsInst = dyn_cast<InsertValueInst>(U);
-    if (!UserInsInst || U->getType() != I.getType()) {
+    auto UserInsInst = dyn_cast<InsertValueInst>(U);
+    if (!UserInsInst || U->getOperand(0) != V)
       break;
-    }
     if (UserInsInst->getIndices() == FirstIndices) {
       IsRedundant = true;
       break;