1; RUN: opt < %s -instcombine -S | FileCheck %s
2target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3
4; Check that we can find and remove redundant insertvalues
5; CHECK-LABEL: foo_simple
6; CHECK-NOT: i8* %x, 0
7define { i8*, i64, i32 } @foo_simple(i8* %x, i8* %y) nounwind {
8entry:
9  %0 = insertvalue { i8*, i64, i32 } undef, i8* %x, 0
10  %1 = insertvalue { i8*, i64, i32 } %0, i8* %y, 0
11  ret { i8*, i64, i32 } %1
12}
13; Check that we can find and remove redundant nodes in insertvalues chain
14; CHECK-LABEL: foo_ovwrt_chain
15; CHECK-NOT: i64 %y, 1
16; CHECK-NOT: i32 555, 2
17define { i8*, i64, i32 } @foo_ovwrt_chain(i8* %x, i64 %y, i64 %z) nounwind {
18entry:
19  %0 = insertvalue { i8*, i64, i32 } undef, i8* %x, 0
20  %1 = insertvalue { i8*, i64, i32 } %0, i64 %y, 1
21  %2 = insertvalue { i8*, i64, i32 } %1, i32 555, 2
22  %3 = insertvalue { i8*, i64, i32 } %2, i64 %z, 1
23  %4 = insertvalue { i8*, i64, i32 } %3, i32 777, 2
24  ret { i8*, i64, i32 } %4
25}
26; Check that we propagate insertvalues only if they are use as the first
27; operand (as initial value of aggregate)
28; CHECK-LABEL: foo_use_as_second_operand
29; CHECK: i16 %x, 0
30; CHECK: %0, 1
31define { i8, {i16, i32} } @foo_use_as_second_operand(i16 %x) nounwind {
32entry:
33  %0 = insertvalue { i16, i32 } undef, i16 %x, 0
34  %1 = insertvalue { i8, {i16, i32} } undef, { i16, i32 } %0, 1
35  ret { i8, {i16, i32} } %1
36}
37