--- /dev/null
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; RUN: opt < %s -passes=argpromotion -S | FileCheck %s
+
+%ptr.struct = type { ptr, ptr, ptr }
+
+define internal void @child(ptr %this, ptr %y, ptr %x) {
+; CHECK-LABEL: define internal void @child
+; CHECK-SAME: (ptr [[Y:%.*]], half [[X_0_VAL:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: store half [[X_0_VAL]], ptr [[Y]], align 2
+; CHECK-NEXT: ret void
+;
+entry:
+ %0 = load half, ptr %x
+ store half %0, ptr %y
+ ret void
+}
+
+define internal void @parent(ptr %this, ptr %p1, ptr %p2) {
+; CHECK-LABEL: define internal void @parent
+; CHECK-SAME: (ptr [[THIS:%.*]], ptr [[P1:%.*]], ptr [[P2:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[SRC_ELEMENT_OP_0:%.*]] = getelementptr ptr, ptr [[THIS]], i64 0
+; CHECK-NEXT: [[LOAD0:%.*]] = load ptr, ptr [[SRC_ELEMENT_OP_0]], align 8
+; CHECK-NEXT: [[P2_VAL2:%.*]] = load half, ptr [[P2]], align 2
+; CHECK-NEXT: call void @child(ptr [[P1]], half [[P2_VAL2]])
+; CHECK-NEXT: [[SRC_ELEMENT_OP_1:%.*]] = getelementptr ptr, ptr [[THIS]], i64 1
+; CHECK-NEXT: [[LOAD1:%.*]] = load ptr, ptr [[SRC_ELEMENT_OP_1]], align 8
+; CHECK-NEXT: [[P2_VAL1:%.*]] = load half, ptr [[P2]], align 2
+; CHECK-NEXT: call void @child(ptr [[P1]], half [[P2_VAL1]])
+; CHECK-NEXT: [[SRC_ELEMENT_OP_2:%.*]] = getelementptr ptr, ptr [[THIS]], i64 2
+; CHECK-NEXT: [[LOAD2:%.*]] = load ptr, ptr [[SRC_ELEMENT_OP_2]], align 8
+; CHECK-NEXT: [[P2_VAL:%.*]] = load half, ptr [[P2]], align 2
+; CHECK-NEXT: call void @child(ptr [[P1]], half [[P2_VAL]])
+; CHECK-NEXT: ret void
+;
+entry:
+ %src_element_op_0 = getelementptr ptr, ptr %this, i64 0
+ %load0 = load ptr, ptr %src_element_op_0
+ call void @child(ptr %load0, ptr %p1, ptr %p2)
+ %src_element_op_1 = getelementptr ptr, ptr %this, i64 1
+ %load1 = load ptr, ptr %src_element_op_1
+ call void @child(ptr %load1, ptr %p1, ptr %p2)
+ %src_element_op_2 = getelementptr ptr, ptr %this, i64 2
+ %load2 = load ptr, ptr %src_element_op_2
+ call void @child(ptr %load2, ptr %p1, ptr %p2)
+ ret void
+}
+
+define void @grandparent() {
+; CHECK-LABEL: define void @grandparent() {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[F:%.*]] = alloca [[PTR_STRUCT:%.*]], align 8
+; CHECK-NEXT: [[XPTR:%.*]] = alloca i32, align 4
+; CHECK-NEXT: [[YPTR:%.*]] = alloca i32, align 4
+; CHECK-NEXT: call void @parent(ptr [[F]], ptr [[XPTR]], ptr [[YPTR]])
+; CHECK-NEXT: ret void
+;
+entry:
+ %f = alloca %ptr.struct
+ %xptr = alloca i32
+ %yptr = alloca i32
+ call void @parent(ptr %f, ptr %xptr, ptr %yptr)
+ ret void
+}
+
--- /dev/null
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature
+; RUN: opt -O3 -S < %s | FileCheck %s
+
+; Arg promotion eliminates the struct argument, and eliminates dead arguments, but introduces and leaves dead loads of the eliminated dead arg in callers
+
+%struct.ss = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
+
+define internal void @phantomLoad(ptr %p, ptr %y, ptr %x) {
+entry:
+ %0 = load i32, ptr %x
+ store i32 %0, ptr %y
+ ret void
+}
+
+define ptr @parent(ptr align 8 dereferenceable(72) %f, i16 %val1, i16 %val2, i32 %val3) align 2 {
+; CHECK-LABEL: define {{[^@]+}}@parent
+; CHECK-SAME: (ptr readonly returned align 8 dereferenceable(72) [[F:%.*]], i16 [[VAL1:%.*]], i16 [[VAL2:%.*]], i32 [[VAL3:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] align 2 {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP_NOT_NOT_I:%.*]] = icmp eq i32 [[VAL3]], 0
+; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds [[STRUCT_SS:%.*]], ptr [[F]], i64 0, i32 8
+; CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[TMP0]], align 8
+; CHECK-NEXT: br i1 [[CMP_NOT_NOT_I]], label [[IF_THEN_I:%.*]], label [[IF_ELSE_I:%.*]]
+; CHECK: if.then.i:
+; CHECK-NEXT: store i16 [[VAL1]], ptr [[TMP1]], align 2
+; CHECK-NEXT: [[ADD_PTR_I_I_I_I_I:%.*]] = getelementptr inbounds i8, ptr [[TMP1]], i64 16
+; CHECK-NEXT: br label [[BADCHILD_EXIT:%.*]]
+; CHECK: if.else.i:
+; CHECK-NEXT: [[ADD_PTR_I_I_I_I7_I:%.*]] = getelementptr inbounds i8, ptr [[TMP1]], i64 16
+; CHECK-NEXT: store i16 [[VAL1]], ptr [[ADD_PTR_I_I_I_I7_I]], align 2
+; CHECK-NEXT: br label [[BADCHILD_EXIT]]
+; CHECK: badChild.exit:
+; CHECK-NEXT: [[DOTSINK_I:%.*]] = phi ptr [ [[TMP1]], [[IF_ELSE_I]] ], [ [[ADD_PTR_I_I_I_I_I]], [[IF_THEN_I]] ]
+; CHECK-NEXT: store i16 [[VAL2]], ptr [[DOTSINK_I]], align 2
+; CHECK-NEXT: ret ptr [[F]]
+;
+entry:
+ call void @badChild(ptr align 8 dereferenceable(72) %f, i16 %val1, i16 %val2, i32 %val3) #4
+ ret ptr %f
+}
+
+define internal void @badChild(ptr align 8 dereferenceable(72) %this, i16 %val1, i16 %val2, i32 %val3) align 2 {
+entry:
+ %othergep = getelementptr inbounds %struct.ss, ptr %this, i64 0, i32 2
+ %load0 = load ptr, ptr %othergep, align 8
+ %load2 = load ptr, ptr %this
+ %x = alloca i32
+ %y = alloca i32
+ call void @phantomLoad(ptr %load0, ptr %x, ptr %y)
+ call void @phantomLoad(ptr %load2, ptr %x, ptr %y)
+ %cmp.not.not = icmp eq i32 %val3, 0
+ br i1 %cmp.not.not, label %if.then, label %if.else
+
+if.then: ; preds = %entry
+ %0 = getelementptr inbounds %struct.ss, ptr %this, i64 0, i32 8
+ %1 = load ptr, ptr %0, align 8
+ store i16 %val1, ptr %1, align 2
+ %add.ptr.i.i.i.i = getelementptr inbounds i8, ptr %1, i64 16
+ store i16 %val2, ptr %add.ptr.i.i.i.i, align 2
+ br label %if.end
+
+if.else: ; preds = %entry
+ %2 = getelementptr inbounds %struct.ss, ptr %this, i64 0, i32 8
+ %3 = load ptr, ptr %2, align 8
+ %add.ptr.i.i.i.i7 = getelementptr inbounds i8, ptr %3, i64 16
+ store i16 %val1, ptr %add.ptr.i.i.i.i7, align 2
+ store i16 %val2, ptr %3, align 2
+ br label %if.end
+
+if.end: ; preds = %if.else, %if.then
+ ret void
+}
+