1; Test 32-bit comparisons in which the second operand is sign-extended 2; from a PC-relative i16. 3; 4; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s 5 6@g = global i16 1 7@h = global i16 1, align 1, section "foo" 8 9; Check signed comparison. 10define i32 @f1(i32 %src1) { 11; CHECK-LABEL: f1: 12; CHECK: chrl %r2, g 13; CHECK-NEXT: blr %r14 14; CHECK: br %r14 15entry: 16 %val = load i16, i16 *@g 17 %src2 = sext i16 %val to i32 18 %cond = icmp slt i32 %src1, %src2 19 br i1 %cond, label %exit, label %mulb 20mulb: 21 %mul = mul i32 %src1, %src1 22 br label %exit 23exit: 24 %res = phi i32 [ %src1, %entry ], [ %mul, %mulb ] 25 ret i32 %res 26} 27 28; Check unsigned comparison, which cannot use CHRL. 29define i32 @f2(i32 %src1) { 30; CHECK-LABEL: f2: 31; CHECK-NOT: chrl 32; CHECK: br %r14 33entry: 34 %val = load i16, i16 *@g 35 %src2 = sext i16 %val to i32 36 %cond = icmp ult i32 %src1, %src2 37 br i1 %cond, label %exit, label %mulb 38mulb: 39 %mul = mul i32 %src1, %src1 40 br label %exit 41exit: 42 %res = phi i32 [ %src1, %entry ], [ %mul, %mulb ] 43 ret i32 %res 44} 45 46; Check equality. 47define i32 @f3(i32 %src1) { 48; CHECK-LABEL: f3: 49; CHECK: chrl %r2, g 50; CHECK-NEXT: ber %r14 51; CHECK: br %r14 52entry: 53 %val = load i16, i16 *@g 54 %src2 = sext i16 %val to i32 55 %cond = icmp eq i32 %src1, %src2 56 br i1 %cond, label %exit, label %mulb 57mulb: 58 %mul = mul i32 %src1, %src1 59 br label %exit 60exit: 61 %res = phi i32 [ %src1, %entry ], [ %mul, %mulb ] 62 ret i32 %res 63} 64 65; Check inequality. 66define i32 @f4(i32 %src1) { 67; CHECK-LABEL: f4: 68; CHECK: chrl %r2, g 69; CHECK-NEXT: blhr %r14 70; CHECK: br %r14 71entry: 72 %val = load i16, i16 *@g 73 %src2 = sext i16 %val to i32 74 %cond = icmp ne i32 %src1, %src2 75 br i1 %cond, label %exit, label %mulb 76mulb: 77 %mul = mul i32 %src1, %src1 78 br label %exit 79exit: 80 %res = phi i32 [ %src1, %entry ], [ %mul, %mulb ] 81 ret i32 %res 82} 83 84; Repeat f1 with an unaligned address. 85define i32 @f5(i32 %src1) { 86; CHECK-LABEL: f5: 87; CHECK: lgrl [[REG:%r[0-5]]], h@GOT 88; CHECK: ch %r2, 0([[REG]]) 89; CHECK-NEXT: blr %r14 90; CHECK: br %r14 91entry: 92 %val = load i16, i16 *@h, align 1 93 %src2 = sext i16 %val to i32 94 %cond = icmp slt i32 %src1, %src2 95 br i1 %cond, label %exit, label %mulb 96mulb: 97 %mul = mul i32 %src1, %src1 98 br label %exit 99exit: 100 %res = phi i32 [ %src1, %entry ], [ %mul, %mulb ] 101 ret i32 %res 102} 103 104; Check the comparison can be reversed if that allows CHRL to be used. 105define i32 @f6(i32 %src2) { 106; CHECK-LABEL: f6: 107; CHECK: chrl %r2, g 108; CHECK-NEXT: bhr %r14 109; CHECK: br %r14 110entry: 111 %val = load i16, i16 *@g 112 %src1 = sext i16 %val to i32 113 %cond = icmp slt i32 %src1, %src2 114 br i1 %cond, label %exit, label %mulb 115mulb: 116 %mul = mul i32 %src2, %src2 117 br label %exit 118exit: 119 %res = phi i32 [ %src2, %entry ], [ %mul, %mulb ] 120 ret i32 %res 121} 122