1; RUN: llc < %s -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr9 -verify-machineinstrs | FileCheck %s
2; RUN: llc < %s -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr9 -verify-machineinstrs | FileCheck %s
3; RUN: llc < %s -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 -verify-machineinstrs | FileCheck %s
4; RUN: llc < %s -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr8 -verify-machineinstrs | FileCheck %s
5
6; Verify pre-inc preparation pass doesn't prepare pre-inc for i64 load/store
7; when the stride doesn't conform LDU/STDU DS-form requirement.
8
9@result = local_unnamed_addr global i64 0, align 8
10
11define i64 @test_preinc_i64_ld(i8* nocapture readonly, i64) local_unnamed_addr {
12  %3 = icmp eq i64 %1, 0
13  br i1 %3, label %4, label %6
14
15; <label>:4:                                      ; preds = %2
16  %5 = load i64, i64* @result, align 8
17  br label %13
18
19; <label>:6:                                      ; preds = %2
20  %7 = getelementptr inbounds i8, i8* %0, i64 -50000
21  %8 = getelementptr inbounds i8, i8* %0, i64 -61024
22  %9 = getelementptr inbounds i8, i8* %0, i64 -62048
23  %10 = getelementptr inbounds i8, i8* %0, i64 -64096
24  %11 = load i64, i64* @result, align 8
25  br label %15
26
27; <label>:12:                                     ; preds = %15
28  store i64 %33, i64* @result, align 8
29  br label %13
30
31; <label>:13:                                     ; preds = %12, %4
32  %14 = phi i64 [ %5, %4 ], [ %33, %12 ]
33  ret i64 %14
34
35; <label>:15:                                     ; preds = %15, %6
36  %16 = phi i64 [ %11, %6 ], [ %33, %15 ]
37  %17 = phi i64 [ 0, %6 ], [ %34, %15 ]
38  %18 = getelementptr inbounds i8, i8* %7, i64 %17
39  %19 = bitcast i8* %18 to i64*
40  %20 = load i64, i64* %19, align 8
41  %21 = getelementptr inbounds i8, i8* %8, i64 %17
42  %22 = bitcast i8* %21 to i64*
43  %23 = load i64, i64* %22, align 8
44  %24 = getelementptr inbounds i8, i8* %9, i64 %17
45  %25 = bitcast i8* %24 to i64*
46  %26 = load i64, i64* %25, align 8
47  %27 = getelementptr inbounds i8, i8* %10, i64 %17
48  %28 = bitcast i8* %27 to i64*
49  %29 = load i64, i64* %28, align 8
50  %30 = mul i64 %23, %20
51  %31 = mul i64 %30, %26
52  %32 = mul i64 %31, %29
53  %33 = mul i64 %32, %16
54  %34 = add nuw i64 %17, 1
55  %35 = icmp eq i64 %34, %1
56  br i1 %35, label %12, label %15
57}
58
59; CHECK-LABEL: test_preinc_i64_ld
60; CHECK-NOT: addi {{[0-9]+}}, {{[0-9]+}}, -11023
61; CHECK-NOT: addi {{[0-9]+}}, {{[0-9]+}}, -12047
62; CHECK-NOT: addi {{[0-9]+}}, {{[0-9]+}}, -14095
63; CHECK-DAG: ld {{[0-9]+}}, 14096([[REG1:[0-9]+]])
64; CHECK-DAG: ld {{[0-9]+}},  3072([[REG1]])
65; CHECK-DAG: ld {{[0-9]+}},  2048([[REG1]])
66; CHECK-DAG: ld {{[0-9]+}},  0([[REG1]])
67; CHECK: blr
68
69define i64 @test_preinc_i64_ldst(i8* nocapture, i64, i64) local_unnamed_addr {
70  %4 = icmp eq i64 %1, 0
71  br i1 %4, label %5, label %7
72
73; <label>:5:                                      ; preds = %3
74  %6 = load i64, i64* @result, align 8
75  br label %16
76
77; <label>:7:                                      ; preds = %3
78  %8 = add i64 %2, 1
79  %9 = getelementptr inbounds i8, i8* %0, i64 -1024
80  %10 = add i64 %2, 2
81  %11 = getelementptr inbounds i8, i8* %0, i64 -2048
82  %12 = getelementptr inbounds i8, i8* %0, i64 -3072
83  %13 = getelementptr inbounds i8, i8* %0, i64 -4096
84  %14 = load i64, i64* @result, align 8
85  br label %18
86
87; <label>:15:                                     ; preds = %18
88  store i64 %32, i64* @result, align 8
89  br label %16
90
91; <label>:16:                                     ; preds = %15, %5
92  %17 = phi i64 [ %6, %5 ], [ %32, %15 ]
93  ret i64 %17
94
95; <label>:18:                                     ; preds = %18, %7
96  %19 = phi i64 [ %14, %7 ], [ %32, %18 ]
97  %20 = phi i64 [ 0, %7 ], [ %33, %18 ]
98  %21 = getelementptr inbounds i8, i8* %9, i64 %20
99  %22 = bitcast i8* %21 to i64*
100  store i64 %8, i64* %22, align 8
101  %23 = getelementptr inbounds i8, i8* %11, i64 %20
102  %24 = bitcast i8* %23 to i64*
103  store i64 %10, i64* %24, align 8
104  %25 = getelementptr inbounds i8, i8* %12, i64 %20
105  %26 = bitcast i8* %25 to i64*
106  %27 = load i64, i64* %26, align 8
107  %28 = getelementptr inbounds i8, i8* %13, i64 %20
108  %29 = bitcast i8* %28 to i64*
109  %30 = load i64, i64* %29, align 8
110  %31 = mul i64 %30, %27
111  %32 = mul i64 %31, %19
112  %33 = add nuw i64 %20, 1
113  %34 = icmp eq i64 %33, %1
114  br i1 %34, label %15, label %18
115}
116
117; CHECK-LABEL: test_preinc_i64_ldst
118; CHECK-NOT: addi {{[0-9]+}}, {{[0-9]+}}, -3071
119; CHECK-NOT: addi {{[0-9]+}}, {{[0-9]+}}, -2047
120; CHECK-NOT: addi {{[0-9]+}}, {{[0-9]+}}, -1023
121; CHECK-DAG: ld  {{[0-9]+}}, -1024([[REG2:[0-9]+]])
122; CHECK-DAG: ld  {{[0-9]+}}, -2048([[REG2]])
123; CHECK-DAG: std {{[0-9]+}},  1024([[REG2]])
124; CHECK-DAG: std {{[0-9]+}},  0([[REG2]])
125