1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=memcpyopt -S -verify-memoryssa | FileCheck %s
4 ; Make sure the call+copy isn't optimized in such a way that
5 ; %ret ends up with the wrong value.
7 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
8 target triple = "i386-apple-darwin10"
10 %struct1 = type { i32, i32 }
11 %struct2 = type { %struct1, ptr }
13 declare void @bar(ptr nocapture sret(%struct1) %agg.result) nounwind
15 define i32 @foo() nounwind {
17 ; CHECK-NEXT: [[X:%.*]] = alloca [[STRUCT1:%.*]], align 8
18 ; CHECK-NEXT: [[Y:%.*]] = alloca [[STRUCT2:%.*]], align 8
19 ; CHECK-NEXT: call void @bar(ptr sret(%struct1) [[X]]) [[ATTR0:#.*]]
20 ; CHECK-NEXT: store i32 0, ptr [[Y]], align 8
21 ; CHECK-NEXT: [[GEPN2:%.*]] = getelementptr inbounds [[STRUCT2]], ptr [[Y]], i32 0, i32 0, i32 1
22 ; CHECK-NEXT: store i32 0, ptr [[GEPN2]], align 4
23 ; CHECK-NEXT: [[LOAD:%.*]] = load i64, ptr [[X]], align 8
24 ; CHECK-NEXT: store i64 [[LOAD]], ptr [[Y]], align 8
25 ; CHECK-NEXT: [[RET:%.*]] = load i32, ptr [[Y]], align 4
26 ; CHECK-NEXT: ret i32 [[RET]]
28 %x = alloca %struct1, align 8
29 %y = alloca %struct2, align 8
30 call void @bar(ptr sret(%struct1) %x) nounwind
32 store i32 0, ptr %y, align 8
33 %gepn2 = getelementptr inbounds %struct2, ptr %y, i32 0, i32 0, i32 1
34 store i32 0, ptr %gepn2, align 4
36 %load = load i64, ptr %x, align 8
37 store i64 %load, ptr %y, align 8
40 %ret = load i32, ptr %y