• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt %s -argpromotion -sroa -S | FileCheck %s
2; RUN: opt %s -passes='argpromotion,function(sroa)' -S | FileCheck %s
3
4target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
5
6%struct.ss = type { i32, i32 }
7
8; Argpromote + sroa should change this to passing the two integers by value.
9define internal i32 @f(%struct.ss* inalloca  %s) {
10entry:
11  %f0 = getelementptr %struct.ss, %struct.ss* %s, i32 0, i32 0
12  %f1 = getelementptr %struct.ss, %struct.ss* %s, i32 0, i32 1
13  %a = load i32, i32* %f0, align 4
14  %b = load i32, i32* %f1, align 4
15  %r = add i32 %a, %b
16  ret i32 %r
17}
18; CHECK-LABEL: define internal i32 @f
19; CHECK-NOT: load
20; CHECK: ret
21
22define i32 @main() {
23entry:
24  %S = alloca inalloca %struct.ss
25  %f0 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 0
26  %f1 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 1
27  store i32 1, i32* %f0, align 4
28  store i32 2, i32* %f1, align 4
29  %r = call i32 @f(%struct.ss* inalloca %S)
30  ret i32 %r
31}
32; CHECK-LABEL: define i32 @main
33; CHECK-NOT: load
34; CHECK: ret
35
36; Argpromote can't promote %a because of the icmp use.
37define internal i1 @g(%struct.ss* %a, %struct.ss* inalloca %b) nounwind  {
38; CHECK: define internal i1 @g(%struct.ss* %a, %struct.ss* inalloca %b)
39entry:
40  %c = icmp eq %struct.ss* %a, %b
41  ret i1 %c
42}
43
44define i32 @test() {
45entry:
46  %S = alloca inalloca %struct.ss
47  %c = call i1 @g(%struct.ss* %S, %struct.ss* inalloca %S)
48; CHECK: call i1 @g(%struct.ss* %S, %struct.ss* inalloca %S)
49  ret i32 0
50}
51