[llvm] r208355 - [InstCombine] Some cleanup in optimization of redundant insertvalue instructions.

Michael Zolotukhin mzolotukhin at apple.com
Thu May 8 12:50:25 PDT 2014


Author: mzolotukhin
Date: Thu May  8 14:50:24 2014
New Revision: 208355

URL: http://llvm.org/viewvc/llvm-project?rev=208355&view=rev
Log:
[InstCombine] Some cleanup in optimization of redundant insertvalue instructions.
And one more test added.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
    llvm/trunk/test/Transforms/InstCombine/OverlappingInsertvalues.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp?rev=208355&r1=208354&r2=208355&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp Thu May  8 14:50:24 2014
@@ -506,13 +506,12 @@ Instruction *InstCombiner::visitInsertVa
   // 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;

Modified: llvm/trunk/test/Transforms/InstCombine/OverlappingInsertvalues.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/OverlappingInsertvalues.ll?rev=208355&r1=208354&r2=208355&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/OverlappingInsertvalues.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/OverlappingInsertvalues.ll Thu May  8 14:50:24 2014
@@ -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
+}





More information about the llvm-commits mailing list