[AArch64] Enhance the load/store optimizer with target-specific alias analysis.

Phabricator: http://reviews.llvm.org/D9863
llvm-svn: 237963
diff --git a/llvm/test/CodeGen/AArch64/arm64-ldp-aa.ll b/llvm/test/CodeGen/AArch64/arm64-ldp-aa.ll
new file mode 100644
index 0000000..ad5c01c
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/arm64-ldp-aa.ll
@@ -0,0 +1,60 @@
+; RUN: llc < %s -march=arm64 -enable-misched=false -verify-machineinstrs | FileCheck %s
+
+; The next set of tests makes sure we can combine the second instruction into
+; the first.
+
+; CHECK-LABEL: ldp_int_aa
+; CHECK: ldp w8, w9, [x1]
+; CHECK: str w0, [x1, #8]
+; CHECK: ret
+define i32 @ldp_int_aa(i32 %a, i32* %p) nounwind {
+  %tmp = load i32, i32* %p, align 4
+  %str.ptr = getelementptr inbounds i32, i32* %p, i64 2
+  store i32 %a, i32* %str.ptr, align 4
+  %add.ptr = getelementptr inbounds i32, i32* %p, i64 1
+  %tmp1 = load i32, i32* %add.ptr, align 4
+  %add = add nsw i32 %tmp1, %tmp
+  ret i32 %add
+}
+
+; CHECK-LABEL: ldp_long_aa
+; CHECK: ldp x8, x9, [x1]
+; CHECK: str x0, [x1, #16]
+; CHECK: ret
+define i64 @ldp_long_aa(i64 %a, i64* %p) nounwind {
+  %tmp = load i64, i64* %p, align 8
+  %str.ptr = getelementptr inbounds i64, i64* %p, i64 2
+  store i64 %a, i64* %str.ptr, align 4
+  %add.ptr = getelementptr inbounds i64, i64* %p, i64 1
+  %tmp1 = load i64, i64* %add.ptr, align 8
+  %add = add nsw i64 %tmp1, %tmp
+  ret i64 %add
+}
+
+; CHECK-LABEL: ldp_float_aa
+; CHECK: str s0, [x0, #8]
+; CHECK: ldp s1, s0, [x0]
+; CHECK: ret
+define float @ldp_float_aa(float %a, float* %p) nounwind {
+  %tmp = load float, float* %p, align 4
+  %str.ptr = getelementptr inbounds float, float* %p, i64 2
+  store float %a, float* %str.ptr, align 4
+  %add.ptr = getelementptr inbounds float, float* %p, i64 1
+  %tmp1 = load float, float* %add.ptr, align 4
+  %add = fadd float %tmp, %tmp1
+  ret float %add
+}
+
+; CHECK-LABEL: ldp_double_aa
+; CHECK: str d0, [x0, #16]
+; CHECK: ldp d1, d0, [x0]
+; CHECK: ret
+define double @ldp_double_aa(double %a, double* %p) nounwind {
+  %tmp = load double, double* %p, align 8
+  %str.ptr = getelementptr inbounds double, double* %p, i64 2
+  store double %a, double* %str.ptr, align 4
+  %add.ptr = getelementptr inbounds double, double* %p, i64 1
+  %tmp1 = load double, double* %add.ptr, align 8
+  %add = fadd double %tmp, %tmp1
+  ret double %add
+}
diff --git a/llvm/test/CodeGen/AArch64/arm64-stp-aa.ll b/llvm/test/CodeGen/AArch64/arm64-stp-aa.ll
new file mode 100644
index 0000000..82d343d
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/arm64-stp-aa.ll
@@ -0,0 +1,111 @@
+; RUN: llc < %s -march=arm64 -enable-misched=false -aarch64-stp-suppress=false -verify-machineinstrs | FileCheck %s
+
+; The next set of tests makes sure we can combine the second instruction into
+; the first.
+
+; CHECK-LABEL: stp_int_aa
+; CHECK: stp w0, w1, [x2]
+; CHECK: ldr w0, [x2, #8]
+; CHECK: ret
+define i32 @stp_int_aa(i32 %a, i32 %b, i32* nocapture %p) nounwind {
+  store i32 %a, i32* %p, align 4
+  %ld.ptr = getelementptr inbounds i32, i32* %p, i64 2
+  %tmp = load i32, i32* %ld.ptr, align 4
+  %add.ptr = getelementptr inbounds i32, i32* %p, i64 1
+  store i32 %b, i32* %add.ptr, align 4
+  ret i32 %tmp
+}
+
+; CHECK-LABEL: stp_long_aa
+; CHECK: stp x0, x1, [x2]
+; CHECK: ldr x0, [x2, #16]
+; CHECK: ret
+define i64 @stp_long_aa(i64 %a, i64 %b, i64* nocapture %p) nounwind {
+  store i64 %a, i64* %p, align 8
+  %ld.ptr = getelementptr inbounds i64, i64* %p, i64 2
+  %tmp = load i64, i64* %ld.ptr, align 4
+  %add.ptr = getelementptr inbounds i64, i64* %p, i64 1
+  store i64 %b, i64* %add.ptr, align 8
+  ret i64 %tmp
+}
+
+; CHECK-LABEL: stp_float_aa
+; CHECK: stp s0, s1, [x0]
+; CHECK: ldr s0, [x0, #8]
+; CHECK: ret
+define float @stp_float_aa(float %a, float %b, float* nocapture %p) nounwind {
+  store float %a, float* %p, align 4
+  %ld.ptr = getelementptr inbounds float, float* %p, i64 2
+  %tmp = load float, float* %ld.ptr, align 4
+  %add.ptr = getelementptr inbounds float, float* %p, i64 1
+  store float %b, float* %add.ptr, align 4
+  ret float %tmp
+}
+
+; CHECK-LABEL: stp_double_aa
+; CHECK: stp d0, d1, [x0]
+; CHECK: ldr d0, [x0, #16]
+; CHECK: ret
+define double @stp_double_aa(double %a, double %b, double* nocapture %p) nounwind {
+  store double %a, double* %p, align 8
+  %ld.ptr = getelementptr inbounds double, double* %p, i64 2
+  %tmp = load double, double* %ld.ptr, align 4
+  %add.ptr = getelementptr inbounds double, double* %p, i64 1
+  store double %b, double* %add.ptr, align 8
+  ret double %tmp
+}
+
+; The next set of tests makes sure we can combine the first instruction into
+; the second.
+
+; CHECK-LABEL: stp_int_aa_after
+; CHECK: ldr w0, [x3, #4]
+; CHECK: stp w1, w2, [x3]
+; CHECK: ret
+define i32 @stp_int_aa_after(i32 %w0, i32 %a, i32 %b, i32* nocapture %p) nounwind {
+  store i32 %a, i32* %p, align 4
+  %ld.ptr = getelementptr inbounds i32, i32* %p, i64 1
+  %tmp = load i32, i32* %ld.ptr, align 4
+  %add.ptr = getelementptr inbounds i32, i32* %p, i64 1
+  store i32 %b, i32* %add.ptr, align 4
+  ret i32 %tmp
+}
+
+; CHECK-LABEL: stp_long_aa_after
+; CHECK: ldr x0, [x3, #8]
+; CHECK: stp x1, x2, [x3]
+; CHECK: ret
+define i64 @stp_long_aa_after(i64 %x0, i64 %a, i64 %b, i64* nocapture %p) nounwind {
+  store i64 %a, i64* %p, align 8
+  %ld.ptr = getelementptr inbounds i64, i64* %p, i64 1
+  %tmp = load i64, i64* %ld.ptr, align 4
+  %add.ptr = getelementptr inbounds i64, i64* %p, i64 1
+  store i64 %b, i64* %add.ptr, align 8
+  ret i64 %tmp
+}
+
+; CHECK-LABEL: stp_float_aa_after
+; CHECK: ldr s0, [x0, #4]
+; CHECK: stp s1, s2, [x0]
+; CHECK: ret
+define float @stp_float_aa_after(float %s0, float %a, float %b, float* nocapture %p) nounwind {
+  store float %a, float* %p, align 4
+  %ld.ptr = getelementptr inbounds float, float* %p, i64 1
+  %tmp = load float, float* %ld.ptr, align 4
+  %add.ptr = getelementptr inbounds float, float* %p, i64 1
+  store float %b, float* %add.ptr, align 4
+  ret float %tmp
+}
+
+; CHECK-LABEL: stp_double_aa_after
+; CHECK: ldr d0, [x0, #8]
+; CHECK: stp d1, d2, [x0]
+; CHECK: ret
+define double @stp_double_aa_after(double %d0, double %a, double %b, double* nocapture %p) nounwind {
+  store double %a, double* %p, align 8
+  %ld.ptr = getelementptr inbounds double, double* %p, i64 1
+  %tmp = load double, double* %ld.ptr, align 4
+  %add.ptr = getelementptr inbounds double, double* %p, i64 1
+  store double %b, double* %add.ptr, align 8
+  ret double %tmp
+}