1; Test integer absolute. 2; 3; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s 4 5; Test i32->i32 absolute using slt. 6define i32 @f1(i32 %val) { 7; CHECK-LABEL: f1: 8; CHECK: lpr %r2, %r2 9; CHECK: br %r14 10 %cmp = icmp slt i32 %val, 0 11 %neg = sub i32 0, %val 12 %res = select i1 %cmp, i32 %neg, i32 %val 13 ret i32 %res 14} 15 16; Test i32->i32 absolute using sle. 17define i32 @f2(i32 %val) { 18; CHECK-LABEL: f2: 19; CHECK: lpr %r2, %r2 20; CHECK: br %r14 21 %cmp = icmp sle i32 %val, 0 22 %neg = sub i32 0, %val 23 %res = select i1 %cmp, i32 %neg, i32 %val 24 ret i32 %res 25} 26 27; Test i32->i32 absolute using sgt. 28define i32 @f3(i32 %val) { 29; CHECK-LABEL: f3: 30; CHECK: lpr %r2, %r2 31; CHECK: br %r14 32 %cmp = icmp sgt i32 %val, 0 33 %neg = sub i32 0, %val 34 %res = select i1 %cmp, i32 %val, i32 %neg 35 ret i32 %res 36} 37 38; Test i32->i32 absolute using sge. 39define i32 @f4(i32 %val) { 40; CHECK-LABEL: f4: 41; CHECK: lpr %r2, %r2 42; CHECK: br %r14 43 %cmp = icmp sge i32 %val, 0 44 %neg = sub i32 0, %val 45 %res = select i1 %cmp, i32 %val, i32 %neg 46 ret i32 %res 47} 48 49; Test i32->i64 absolute. 50define i64 @f5(i32 %val) { 51; CHECK-LABEL: f5: 52; CHECK: lpgfr %r2, %r2 53; CHECK: br %r14 54 %ext = sext i32 %val to i64 55 %cmp = icmp slt i64 %ext, 0 56 %neg = sub i64 0, %ext 57 %res = select i1 %cmp, i64 %neg, i64 %ext 58 ret i64 %res 59} 60 61; Test i32->i64 absolute that uses an "in-register" form of sign extension. 62define i64 @f6(i64 %val) { 63; CHECK-LABEL: f6: 64; CHECK: lpgfr %r2, %r2 65; CHECK: br %r14 66 %trunc = trunc i64 %val to i32 67 %ext = sext i32 %trunc to i64 68 %cmp = icmp slt i64 %ext, 0 69 %neg = sub i64 0, %ext 70 %res = select i1 %cmp, i64 %neg, i64 %ext 71 ret i64 %res 72} 73 74; Test i64 absolute. 75define i64 @f7(i64 %val) { 76; CHECK-LABEL: f7: 77; CHECK: lpgr %r2, %r2 78; CHECK: br %r14 79 %cmp = icmp slt i64 %val, 0 80 %neg = sub i64 0, %val 81 %res = select i1 %cmp, i64 %neg, i64 %val 82 ret i64 %res 83} 84 85; Test another form of f6, which is that produced by InstCombine. 86define i64 @f8(i64 %val) { 87; CHECK-LABEL: f8: 88; CHECK: lpgfr %r2, %r2 89; CHECK: br %r14 90 %shl = shl i64 %val, 32 91 %ashr = ashr i64 %shl, 32 92 %neg = sub i64 0, %ashr 93 %cmp = icmp slt i64 %shl, 0 94 %abs = select i1 %cmp, i64 %neg, i64 %ashr 95 ret i64 %abs 96} 97 98; Try again with sle rather than slt. 99define i64 @f9(i64 %val) { 100; CHECK-LABEL: f9: 101; CHECK: lpgfr %r2, %r2 102; CHECK: br %r14 103 %shl = shl i64 %val, 32 104 %ashr = ashr i64 %shl, 32 105 %neg = sub i64 0, %ashr 106 %cmp = icmp sle i64 %shl, 0 107 %abs = select i1 %cmp, i64 %neg, i64 %ashr 108 ret i64 %abs 109} 110 111; Repeat f8 with the operands reversed. 112define i64 @f10(i64 %val) { 113; CHECK-LABEL: f10: 114; CHECK: lpgfr %r2, %r2 115; CHECK: br %r14 116 %shl = shl i64 %val, 32 117 %ashr = ashr i64 %shl, 32 118 %neg = sub i64 0, %ashr 119 %cmp = icmp sgt i64 %shl, 0 120 %abs = select i1 %cmp, i64 %ashr, i64 %neg 121 ret i64 %abs 122} 123 124; Try again with sge rather than sgt. 125define i64 @f11(i64 %val) { 126; CHECK-LABEL: f11: 127; CHECK: lpgfr %r2, %r2 128; CHECK: br %r14 129 %shl = shl i64 %val, 32 130 %ashr = ashr i64 %shl, 32 131 %neg = sub i64 0, %ashr 132 %cmp = icmp sge i64 %shl, 0 133 %abs = select i1 %cmp, i64 %ashr, i64 %neg 134 ret i64 %abs 135} 136 137; Repeat f5 with the comparison on the unextended value. 138define i64 @f12(i32 %val) { 139; CHECK-LABEL: f12: 140; CHECK: lpgfr %r2, %r2 141; CHECK: br %r14 142 %ext = sext i32 %val to i64 143 %cmp = icmp slt i32 %val, 0 144 %neg = sub i64 0, %ext 145 %abs = select i1 %cmp, i64 %neg, i64 %ext 146 ret i64 %abs 147} 148