191 lines · plain
1; Test STOCs that are presented as selects.2;3; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z196 | FileCheck %s4 5; Run the test again to make sure it still works the same even6; in the presence of the load-store-on-condition-2 facility.7; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z13 | FileCheck %s8 9declare void @foo(ptr)10 11; Test the simple case, with the loaded value first.12define void @f1(ptr %ptr, i32 %alt, i32 %limit) {13; CHECK-LABEL: f1:14; CHECK: clfi %r4, 4215; CHECK: stoche %r3, 0(%r2)16; CHECK: br %r1417 %cond = icmp ult i32 %limit, 4218 %orig = load i32, ptr %ptr19 %res = select i1 %cond, i32 %orig, i32 %alt20 store i32 %res, ptr %ptr21 ret void22}23 24; ...and with the loaded value second25define void @f2(ptr %ptr, i32 %alt, i32 %limit) {26; CHECK-LABEL: f2:27; CHECK: clfi %r4, 4228; CHECK: stocl %r3, 0(%r2)29; CHECK: br %r1430 %cond = icmp ult i32 %limit, 4231 %orig = load i32, ptr %ptr32 %res = select i1 %cond, i32 %alt, i32 %orig33 store i32 %res, ptr %ptr34 ret void35}36 37; Test cases where the value is explicitly sign-extended to 64 bits, with the38; loaded value first.39define void @f3(ptr %ptr, i64 %alt, i32 %limit) {40; CHECK-LABEL: f3:41; CHECK: clfi %r4, 4242; CHECK: stoche %r3, 0(%r2)43; CHECK: br %r1444 %cond = icmp ult i32 %limit, 4245 %orig = load i32, ptr %ptr46 %ext = sext i32 %orig to i6447 %res = select i1 %cond, i64 %ext, i64 %alt48 %trunc = trunc i64 %res to i3249 store i32 %trunc, ptr %ptr50 ret void51}52 53; ...and with the loaded value second54define void @f4(ptr %ptr, i64 %alt, i32 %limit) {55; CHECK-LABEL: f4:56; CHECK: clfi %r4, 4257; CHECK: stocl %r3, 0(%r2)58; CHECK: br %r1459 %cond = icmp ult i32 %limit, 4260 %orig = load i32, ptr %ptr61 %ext = sext i32 %orig to i6462 %res = select i1 %cond, i64 %alt, i64 %ext63 %trunc = trunc i64 %res to i3264 store i32 %trunc, ptr %ptr65 ret void66}67 68; Test cases where the value is explicitly zero-extended to 32 bits, with the69; loaded value first.70define void @f5(ptr %ptr, i64 %alt, i32 %limit) {71; CHECK-LABEL: f5:72; CHECK: clfi %r4, 4273; CHECK: stoche %r3, 0(%r2)74; CHECK: br %r1475 %cond = icmp ult i32 %limit, 4276 %orig = load i32, ptr %ptr77 %ext = zext i32 %orig to i6478 %res = select i1 %cond, i64 %ext, i64 %alt79 %trunc = trunc i64 %res to i3280 store i32 %trunc, ptr %ptr81 ret void82}83 84; ...and with the loaded value second85define void @f6(ptr %ptr, i64 %alt, i32 %limit) {86; CHECK-LABEL: f6:87; CHECK: clfi %r4, 4288; CHECK: stocl %r3, 0(%r2)89; CHECK: br %r1490 %cond = icmp ult i32 %limit, 4291 %orig = load i32, ptr %ptr92 %ext = zext i32 %orig to i6493 %res = select i1 %cond, i64 %alt, i64 %ext94 %trunc = trunc i64 %res to i3295 store i32 %trunc, ptr %ptr96 ret void97}98 99; Check the high end of the aligned STOC range.100define void @f7(ptr %base, i32 %alt, i32 %limit) {101; CHECK-LABEL: f7:102; CHECK: clfi %r4, 42103; CHECK: stoche %r3, 524284(%r2)104; CHECK: br %r14105 %ptr = getelementptr i32, ptr %base, i64 131071106 %cond = icmp ult i32 %limit, 42107 %orig = load i32, ptr %ptr108 %res = select i1 %cond, i32 %orig, i32 %alt109 store i32 %res, ptr %ptr110 ret void111}112 113; Check the next word up. Other sequences besides this one would be OK.114define void @f8(ptr %base, i32 %alt, i32 %limit) {115; CHECK-LABEL: f8:116; CHECK: agfi %r2, 524288117; CHECK: clfi %r4, 42118; CHECK: stoche %r3, 0(%r2)119; CHECK: br %r14120 %ptr = getelementptr i32, ptr %base, i64 131072121 %cond = icmp ult i32 %limit, 42122 %orig = load i32, ptr %ptr123 %res = select i1 %cond, i32 %orig, i32 %alt124 store i32 %res, ptr %ptr125 ret void126}127 128; Check the low end of the STOC range.129define void @f9(ptr %base, i32 %alt, i32 %limit) {130; CHECK-LABEL: f9:131; CHECK: clfi %r4, 42132; CHECK: stoche %r3, -524288(%r2)133; CHECK: br %r14134 %ptr = getelementptr i32, ptr %base, i64 -131072135 %cond = icmp ult i32 %limit, 42136 %orig = load i32, ptr %ptr137 %res = select i1 %cond, i32 %orig, i32 %alt138 store i32 %res, ptr %ptr139 ret void140}141 142; Check the next word down, with the same comments as f8.143define void @f10(ptr %base, i32 %alt, i32 %limit) {144; CHECK-LABEL: f10:145; CHECK: agfi %r2, -524292146; CHECK: clfi %r4, 42147; CHECK: stoche %r3, 0(%r2)148; CHECK: br %r14149 %ptr = getelementptr i32, ptr %base, i64 -131073150 %cond = icmp ult i32 %limit, 42151 %orig = load i32, ptr %ptr152 %res = select i1 %cond, i32 %orig, i32 %alt153 store i32 %res, ptr %ptr154 ret void155}156 157; Try a frame index base.158define void @f11(i32 %alt, i32 %limit) {159; CHECK-LABEL: f11:160; CHECK: brasl %r14, foo@PLT161; CHECK: stoche {{%r[0-9]+}}, {{[0-9]+}}(%r15)162; CHECK: brasl %r14, foo@PLT163; CHECK: br %r14164 %ptr = alloca i32165 call void @foo(ptr %ptr)166 %cond = icmp ult i32 %limit, 42167 %orig = load i32, ptr %ptr168 %res = select i1 %cond, i32 %orig, i32 %alt169 store i32 %res, ptr %ptr170 call void @foo(ptr %ptr)171 ret void172}173 174; Test that conditionally-executed stores do not use STOC, since STOC175; is allowed to trap even when the condition is false.176define void @f12(i32 %a, i32 %b, ptr %dest) {177; CHECK-LABEL: f12:178; CHECK-NOT: stoc179; CHECK: br %r14180entry:181 %cmp = icmp ule i32 %a, %b182 br i1 %cmp, label %store, label %exit183 184store:185 store i32 %b, ptr %dest186 br label %exit187 188exit:189 ret void190}191