[AMDGPU] Add True16 register classes.
[llvm-project.git] / llvm / test / Transforms / SafeStack / X86 / byval.ll
blob761265e279d4108cca10a9ad9ba2246aed488d1f
1 ; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
2 ; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-unknown-linux-gnu"
7 %struct.S = type { [100 x i32] }
9 ; Safe access to a byval argument.
10 define i32 @ByValSafe(ptr byval(%struct.S) nocapture readonly align 8 %zzz) norecurse nounwind readonly safestack uwtable {
11 entry:
12   ; CHECK-LABEL: @ByValSafe
13   ; CHECK-NOT: __safestack_unsafe_stack_ptr
14   ; CHECK: ret i32
15   %arrayidx = getelementptr inbounds %struct.S, ptr %zzz, i64 0, i32 0, i64 3
16   %0 = load i32, ptr %arrayidx, align 4
17   ret i32 %0
20 ; Unsafe access to a byval argument.
21 ; Argument is copied to the unsafe stack.
22 define i32 @ByValUnsafe(ptr byval(%struct.S) nocapture readonly align 8 %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable {
23 entry:
24   ; CHECK-LABEL: @ByValUnsafe
25   ; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr
26   ; CHECK: store {{.*}} @__safestack_unsafe_stack_ptr
27   ; CHECK: %[[B:.*]] = getelementptr i8, ptr %[[A]], i32 -400
28   ; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[B]], ptr align 8 %zzz, i64 400, i1 false)
29   ; CHECK: ret i32
30   %arrayidx = getelementptr inbounds %struct.S, ptr %zzz, i64 0, i32 0, i64 %idx
31   %0 = load i32, ptr %arrayidx, align 4
32   ret i32 %0
35 ; Unsafe access to a byval argument.
36 ; Argument is copied to the unsafe stack.
37 ; Check that dest align of memcpy is set according to datalayout prefered alignment
38 define i32 @ByValUnsafe2(ptr byval(%struct.S) nocapture readonly %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable {
39 entry:
40   ; CHECK-LABEL: @ByValUnsafe
41   ; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr
42   ; CHECK: store {{.*}} @__safestack_unsafe_stack_ptr
43   ; CHECK: %[[B:.*]] = getelementptr i8, ptr %[[A]], i32 -400
44   ; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[B]], ptr %zzz, i64 400, i1 false)
45   ; CHECK: ret i32
46   %arrayidx = getelementptr inbounds %struct.S, ptr %zzz, i64 0, i32 0, i64 %idx
47   %0 = load i32, ptr %arrayidx, align 4
48   ret i32 %0
51 ; Highly aligned byval argument.
52 define i32 @ByValUnsafeAligned(ptr byval(%struct.S) nocapture readonly align 64 %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable {
53 entry:
54   ; CHECK-LABEL: @ByValUnsafeAligned
55   ; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr
56   ; CHECK: %[[B:.*]] = ptrtoint ptr %[[A]] to i64
57   ; CHECK: and i64 %[[B]], -64
58   ; CHECK: ret i32
59   %0 = load i32, ptr %zzz, align 64
60   %arrayidx2 = getelementptr inbounds %struct.S, ptr %zzz, i64 0, i32 0, i64 %idx
61   %1 = load i32, ptr %arrayidx2, align 4
62   %add = add nsw i32 %1, %0
63   ret i32 %add