1 ; Test load-and-trap instructions (LLGFAT/LLGFTAT)
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=zEC12 | FileCheck %s
5 declare void @llvm.trap()
7 ; Check LLGFAT with no displacement.
8 define i64 @f1(i32 *%ptr) {
10 ; CHECK: llgfat %r2, 0(%r2)
13 %val = load i32, i32 *%ptr
14 %ext = zext i32 %val to i64
15 %cmp = icmp eq i64 %ext, 0
16 br i1 %cmp, label %if.then, label %if.end
18 if.then: ; preds = %entry
19 tail call void @llvm.trap()
22 if.end: ; preds = %entry
26 ; Check the high end of the LLGFAT range.
27 define i64 @f2(i32 *%src) {
29 ; CHECK: llgfat %r2, 524284(%r2)
31 %ptr = getelementptr i32, i32 *%src, i64 131071
32 %val = load i32, i32 *%ptr
33 %ext = zext i32 %val to i64
34 %cmp = icmp eq i64 %ext, 0
35 br i1 %cmp, label %if.then, label %if.end
37 if.then: ; preds = %entry
38 tail call void @llvm.trap()
41 if.end: ; preds = %entry
45 ; Check the next word up, which needs separate address logic.
46 ; Other sequences besides this one would be OK.
47 define i64 @f3(i32 *%src) {
49 ; CHECK: agfi %r2, 524288
50 ; CHECK: llgfat %r2, 0(%r2)
52 %ptr = getelementptr i32, i32 *%src, i64 131072
53 %val = load i32, i32 *%ptr
54 %ext = zext i32 %val to i64
55 %cmp = icmp eq i64 %ext, 0
56 br i1 %cmp, label %if.then, label %if.end
58 if.then: ; preds = %entry
59 tail call void @llvm.trap()
62 if.end: ; preds = %entry
66 ; Check that LLGFAT allows an index.
67 define i64 @f4(i64 %src, i64 %index) {
69 ; CHECK: llgfat %r2, 524287(%r3,%r2)
71 %add1 = add i64 %src, %index
72 %add2 = add i64 %add1, 524287
73 %ptr = inttoptr i64 %add2 to i32 *
74 %val = load i32, i32 *%ptr
75 %ext = zext i32 %val to i64
76 %cmp = icmp eq i64 %ext, 0
77 br i1 %cmp, label %if.then, label %if.end
79 if.then: ; preds = %entry
80 tail call void @llvm.trap()
83 if.end: ; preds = %entry
87 ; Check LLGTAT with no displacement.
88 define i64 @f5(i32 *%ptr) {
90 ; CHECK: llgtat %r2, 0(%r2)
93 %val = load i32, i32 *%ptr
94 %ext = zext i32 %val to i64
95 %and = and i64 %ext, 2147483647
96 %cmp = icmp eq i64 %and, 0
97 br i1 %cmp, label %if.then, label %if.end
99 if.then: ; preds = %entry
100 tail call void @llvm.trap()
103 if.end: ; preds = %entry
107 ; Check the high end of the LLGTAT range.
108 define i64 @f6(i32 *%src) {
110 ; CHECK: llgtat %r2, 524284(%r2)
112 %ptr = getelementptr i32, i32 *%src, i64 131071
113 %val = load i32, i32 *%ptr
114 %ext = zext i32 %val to i64
115 %and = and i64 %ext, 2147483647
116 %cmp = icmp eq i64 %and, 0
117 br i1 %cmp, label %if.then, label %if.end
119 if.then: ; preds = %entry
120 tail call void @llvm.trap()
123 if.end: ; preds = %entry
127 ; Check the next word up, which needs separate address logic.
128 ; Other sequences besides this one would be OK.
129 define i64 @f7(i32 *%src) {
131 ; CHECK: agfi %r2, 524288
132 ; CHECK: llgtat %r2, 0(%r2)
134 %ptr = getelementptr i32, i32 *%src, i64 131072
135 %val = load i32, i32 *%ptr
136 %ext = zext i32 %val to i64
137 %and = and i64 %ext, 2147483647
138 %cmp = icmp eq i64 %and, 0
139 br i1 %cmp, label %if.then, label %if.end
141 if.then: ; preds = %entry
142 tail call void @llvm.trap()
145 if.end: ; preds = %entry
149 ; Check that LLGTAT allows an index.
150 define i64 @f8(i64 %src, i64 %index) {
152 ; CHECK: llgtat %r2, 524287(%r3,%r2)
154 %add1 = add i64 %src, %index
155 %add2 = add i64 %add1, 524287
156 %ptr = inttoptr i64 %add2 to i32 *
157 %val = load i32, i32 *%ptr
158 %ext = zext i32 %val to i64
159 %and = and i64 %ext, 2147483647
160 %cmp = icmp eq i64 %and, 0
161 br i1 %cmp, label %if.then, label %if.end
163 if.then: ; preds = %entry
164 tail call void @llvm.trap()
167 if.end: ; preds = %entry