diff options
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp | 7 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/OverlappingInsertvalues.ll | 11 |
2 files changed, 14 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp index 80c20b70758..b072b4d422d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -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; diff --git a/llvm/test/Transforms/InstCombine/OverlappingInsertvalues.ll b/llvm/test/Transforms/InstCombine/OverlappingInsertvalues.ll index 3af684bf4b3..9248aecdf57 100644 --- a/llvm/test/Transforms/InstCombine/OverlappingInsertvalues.ll +++ b/llvm/test/Transforms/InstCombine/OverlappingInsertvalues.ll @@ -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 +} |

