[InstCombine] Some cleanup in optimization of redundant insertvalue instructions.
authorMichael Zolotukhin <mzolotukhin@apple.com>
Thu, 8 May 2014 19:50:24 +0000 (19:50 +0000)
committerMichael Zolotukhin <mzolotukhin@apple.com>
Thu, 8 May 2014 19:50:24 +0000 (19:50 +0000)
And one more test added.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208355 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineVectorOps.cpp
test/Transforms/InstCombine/OverlappingInsertvalues.ll

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;
index 3af684bf4b37365455ecef405801e5eb2bcdbbfe..9248aecdf5758fe29a081295706f15497bd43c20 100644 (file)
@@ -23,3 +23,14 @@ entry:
   %4 = insertvalue { i8*, i64, i32 } %3, i32 777, 2
   ret { i8*, i64, i32 } %4
 }
+; Check that we propagate insertvalues only if they are use as the first
+; operand (as initial value of aggregate)
+; CHECK-LABEL: foo_use_as_second_operand
+; CHECK: i16 %x, 0
+; CHECK: %0, 1
+define { i8, {i16, i32} } @foo_use_as_second_operand(i16 %x) nounwind {
+entry:
+  %0 = insertvalue { i16, i32 } undef, i16 %x, 0
+  %1 = insertvalue { i8, {i16, i32} } undef, { i16, i32 } %0, 1
+  ret { i8, {i16, i32} } %1
+}