149 lines · plain
1; Test LOC.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 i32 @foo(ptr)10 11; Test the simple case.12define i32 @f1(i32 %easy, ptr %ptr, i32 %limit) {13; CHECK-LABEL: f1:14; CHECK: clfi %r4, 4215; CHECK: loche %r2, 0(%r3)16; CHECK: br %r1417 %cond = icmp ult i32 %limit, 4218 %other = load i32, ptr %ptr19 %res = select i1 %cond, i32 %easy, i32 %other20 ret i32 %res21}22 23; ...and again with the operands swapped.24define i32 @f2(i32 %easy, ptr %ptr, i32 %limit) {25; CHECK-LABEL: f2:26; CHECK: clfi %r4, 4227; CHECK: locl %r2, 0(%r3)28; CHECK: br %r1429 %cond = icmp ult i32 %limit, 4230 %other = load i32, ptr %ptr31 %res = select i1 %cond, i32 %other, i32 %easy32 ret i32 %res33}34 35; Check the high end of the aligned LOC range.36define i32 @f3(i32 %easy, ptr %base, i32 %limit) {37; CHECK-LABEL: f3:38; CHECK: clfi %r4, 4239; CHECK: loche %r2, 524284(%r3)40; CHECK: br %r1441 %ptr = getelementptr i32, ptr %base, i64 13107142 %cond = icmp ult i32 %limit, 4243 %other = load i32, ptr %ptr44 %res = select i1 %cond, i32 %easy, i32 %other45 ret i32 %res46}47 48; Check the next word up. Other sequences besides this one would be OK.49define i32 @f4(i32 %easy, ptr %base, i32 %limit) {50; CHECK-LABEL: f4:51; CHECK: agfi %r3, 52428852; CHECK: clfi %r4, 4253; CHECK: loche %r2, 0(%r3)54; CHECK: br %r1455 %ptr = getelementptr i32, ptr %base, i64 13107256 %cond = icmp ult i32 %limit, 4257 %other = load i32, ptr %ptr58 %res = select i1 %cond, i32 %easy, i32 %other59 ret i32 %res60}61 62; Check the low end of the LOC range.63define i32 @f5(i32 %easy, ptr %base, i32 %limit) {64; CHECK-LABEL: f5:65; CHECK: clfi %r4, 4266; CHECK: loche %r2, -524288(%r3)67; CHECK: br %r1468 %ptr = getelementptr i32, ptr %base, i64 -13107269 %cond = icmp ult i32 %limit, 4270 %other = load i32, ptr %ptr71 %res = select i1 %cond, i32 %easy, i32 %other72 ret i32 %res73}74 75; Check the next word down, with the same comments as f4.76define i32 @f6(i32 %easy, ptr %base, i32 %limit) {77; CHECK-LABEL: f6:78; CHECK: agfi %r3, -52429279; CHECK: clfi %r4, 4280; CHECK: loche %r2, 0(%r3)81; CHECK: br %r1482 %ptr = getelementptr i32, ptr %base, i64 -13107383 %cond = icmp ult i32 %limit, 4284 %other = load i32, ptr %ptr85 %res = select i1 %cond, i32 %easy, i32 %other86 ret i32 %res87}88 89; Try a frame index base.90define i32 @f7(i32 %alt, i32 %limit) {91; CHECK-LABEL: f7:92; CHECK: brasl %r14, foo@PLT93; CHECK: loche %r2, {{[0-9]+}}(%r15)94; CHECK: br %r1495 %ptr = alloca i3296 %easy = call i32 @foo(ptr %ptr)97 %cond = icmp ult i32 %limit, 4298 %other = load i32, ptr %ptr99 %res = select i1 %cond, i32 %easy, i32 %other100 ret i32 %res101}102 103; Try a case when an index is involved.104define i32 @f8(i32 %easy, i32 %limit, i64 %base, i64 %index) {105; CHECK-LABEL: f8:106; CHECK: clfi %r3, 42107; CHECK: loche %r2, 0({{%r[1-5]}})108; CHECK: br %r14109 %add = add i64 %base, %index110 %ptr = inttoptr i64 %add to ptr111 %cond = icmp ult i32 %limit, 42112 %other = load i32, ptr %ptr113 %res = select i1 %cond, i32 %easy, i32 %other114 ret i32 %res115}116 117; Test that conditionally-executed loads do not use LOC, since it is allowed118; to trap even when the condition is false.119define i32 @f9(i32 %easy, i32 %limit, ptr %ptr) {120; CHECK-LABEL: f9:121; CHECK-NOT: loc122; CHECK: br %r14123entry:124 %cmp = icmp ule i32 %easy, %limit125 br i1 %cmp, label %load, label %exit126 127load:128 %other = load i32, ptr %ptr129 br label %exit130 131exit:132 %res = phi i32 [ %easy, %entry ], [ %other, %load ]133 ret i32 %res134}135 136; Test that volatile loads do not use LOC, since if the condition is false,137; it is unspecified whether or not the load happens. LOCR is fine though.138define i32 @f10(i32 %easy, ptr %ptr, i32 %limit) {139; CHECK-LABEL: f10:140; CHECK: l {{%r[0-9]*}}, 0(%r3)141; CHECK: locr142; CHECK: br %r14143 %cond = icmp ult i32 %limit, 42144 %other = load volatile i32, ptr %ptr145 %res = select i1 %cond, i32 %easy, i32 %other146 ret i32 %res147}148 149