1; Test 8-bit compare and swap. 2; 3; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s -check-prefix=CHECK-MAIN 4; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s -check-prefix=CHECK-SHIFT 5 6; Check compare and swap with a variable. 7; - CHECK is for the main loop. 8; - CHECK-SHIFT makes sure that the negated shift count used by the second 9; RLL is set up correctly. The negation is independent of the NILL and L 10; tested in CHECK. CHECK-SHIFT also checks that %r3 is not modified before 11; being used in the RISBG (in contrast to things like atomic addition, 12; which shift %r3 left so that %b is at the high end of the word). 13define i8 @f1(i8 %dummy, i8 *%src, i8 %cmp, i8 %swap) { 14; CHECK-MAIN-LABEL: f1: 15; CHECK-MAIN: risbg [[RISBG:%r[1-9]+]], %r3, 0, 189, 0{{$}} 16; CHECK-MAIN-DAG: sll %r3, 3 17; CHECK-MAIN-DAG: l [[OLD:%r[0-9]+]], 0([[RISBG]]) 18; CHECK-MAIN: [[LOOP:\.[^ ]*]]: 19; CHECK-MAIN: rll %r2, [[OLD]], 8(%r3) 20; CHECK-MAIN: risbg %r4, %r2, 32, 55, 0 21; CHECK-MAIN: crjlh %r2, %r4, [[EXIT:\.[^ ]*]] 22; CHECK-MAIN: risbg %r5, %r2, 32, 55, 0 23; CHECK-MAIN: rll [[NEW:%r[0-9]+]], %r5, -8({{%r[1-9]+}}) 24; CHECK-MAIN: cs [[OLD]], [[NEW]], 0([[RISBG]]) 25; CHECK-MAIN: jl [[LOOP]] 26; CHECK-MAIN: [[EXIT]]: 27; CHECK-MAIN-NOT: %r2 28; CHECK-MAIN: br %r14 29; 30; CHECK-SHIFT-LABEL: f1: 31; CHECK-SHIFT: sll [[SHIFT:%r[1-9]+]], 3 32; CHECK-SHIFT: lcr [[NEGSHIFT:%r[1-9]+]], [[SHIFT]] 33; CHECK-SHIFT: rll 34; CHECK-SHIFT: rll {{%r[0-9]+}}, %r5, -8([[NEGSHIFT]]) 35 %pair = cmpxchg i8 *%src, i8 %cmp, i8 %swap seq_cst seq_cst 36 %res = extractvalue { i8, i1 } %pair, 0 37 ret i8 %res 38} 39 40; Check compare and swap with constants. We should force the constants into 41; registers and use the sequence above. 42define i8 @f2(i8 *%src) { 43; CHECK-LABEL: f2: 44; CHECK: lhi [[CMP:%r[0-9]+]], 42 45; CHECK: risbg [[CMP]], {{%r[0-9]+}}, 32, 55, 0 46; CHECK: risbg 47; CHECK: br %r14 48; 49; CHECK-SHIFT-LABEL: f2: 50; CHECK-SHIFT: lhi [[SWAP:%r[0-9]+]], 88 51; CHECK-SHIFT: risbg 52; CHECK-SHIFT: risbg [[SWAP]], {{%r[0-9]+}}, 32, 55, 0 53; CHECK-SHIFT: br %r14 54 %pair = cmpxchg i8 *%src, i8 42, i8 88 seq_cst seq_cst 55 %res = extractvalue { i8, i1 } %pair, 0 56 ret i8 %res 57} 58 59; Check generating the comparison result. 60define i32 @f3(i8 %dummy, i8 *%src, i8 %cmp, i8 %swap) { 61; CHECK-MAIN-LABEL: f3: 62; CHECK-MAIN: risbg [[RISBG:%r[1-9]+]], %r3, 0, 189, 0{{$}} 63; CHECK-MAIN-DAG: sll %r3, 3 64; CHECK-MAIN-DAG: l [[OLD:%r[0-9]+]], 0([[RISBG]]) 65; CHECK-MAIN: [[LOOP:\.[^ ]*]]: 66; CHECK-MAIN: rll [[TMP:%r[0-9]+]], [[OLD]], 8(%r3) 67; CHECK-MAIN: risbg %r4, [[TMP]], 32, 55, 0 68; CHECK-MAIN: cr [[TMP]], %r4 69; CHECK-MAIN: jlh [[EXIT:\.[^ ]*]] 70; CHECK-MAIN: risbg %r5, [[TMP]], 32, 55, 0 71; CHECK-MAIN: rll [[NEW:%r[0-9]+]], %r5, -8({{%r[1-9]+}}) 72; CHECK-MAIN: cs [[OLD]], [[NEW]], 0([[RISBG]]) 73; CHECK-MAIN: jl [[LOOP]] 74; CHECK-MAIN: [[EXIT]]: 75; CHECK-MAIN-NEXT: ipm %r2 76; CHECK-MAIN-NEXT: afi %r2, -268435456 77; CHECK-MAIN-NEXT: srl %r2, 31 78; CHECK-MAIN-NOT: %r2 79; CHECK-MAIN: br %r14 80; 81; CHECK-SHIFT-LABEL: f3: 82; CHECK-SHIFT: sll [[SHIFT:%r[1-9]+]], 3 83; CHECK-SHIFT: lcr [[NEGSHIFT:%r[1-9]+]], [[SHIFT]] 84; CHECK-SHIFT: rll 85; CHECK-SHIFT: rll {{%r[0-9]+}}, %r5, -8([[NEGSHIFT]]) 86 %pair = cmpxchg i8 *%src, i8 %cmp, i8 %swap seq_cst seq_cst 87 %val = extractvalue { i8, i1 } %pair, 1 88 %res = zext i1 %val to i32 89 ret i32 %res 90} 91 92 93declare void @g() 94 95; Check using the comparison result for a branch. 96; CHECK-LABEL: f4 97; CHECK-MAIN-LABEL: f4: 98; CHECK-MAIN: risbg [[RISBG:%r[1-9]+]], %r2, 0, 189, 0{{$}} 99; CHECK-MAIN-DAG: sll %r2, 3 100; CHECK-MAIN-DAG: l [[OLD:%r[0-9]+]], 0([[RISBG]]) 101; CHECK-MAIN: [[LOOP:\.[^ ]*]]: 102; CHECK-MAIN: rll [[TMP:%r[0-9]+]], [[OLD]], 8(%r2) 103; CHECK-MAIN: risbg %r3, [[TMP]], 32, 55, 0 104; CHECK-MAIN: cr [[TMP]], %r3 105; CHECK-MAIN: jlh [[EXIT:\.[^ ]*]] 106; CHECK-MAIN: risbg %r4, [[TMP]], 32, 55, 0 107; CHECK-MAIN: rll [[NEW:%r[0-9]+]], %r4, -8({{%r[1-9]+}}) 108; CHECK-MAIN: cs [[OLD]], [[NEW]], 0([[RISBG]]) 109; CHECK-MAIN: jl [[LOOP]] 110; CHECK-MAIN: [[EXIT]]: 111; CHECK-MAIN-NEXT: jlh [[LABEL:\.[^ ]*]] 112; CHECK-MAIN: jg g 113; CHECK-MAIN: [[LABEL]]: 114; CHECK-MAIN: br %r14 115; 116; CHECK-SHIFT-LABEL: f4: 117; CHECK-SHIFT: sll %r2, 3 118; CHECK-SHIFT: lcr [[NEGSHIFT:%r[1-9]+]], %r2 119; CHECK-SHIFT: rll 120; CHECK-SHIFT: rll {{%r[0-9]+}}, %r4, -8([[NEGSHIFT]]) 121define void @f4(i8 *%src, i8 %cmp, i8 %swap) { 122 %pair = cmpxchg i8 *%src, i8 %cmp, i8 %swap seq_cst seq_cst 123 %cond = extractvalue { i8, i1 } %pair, 1 124 br i1 %cond, label %call, label %exit 125 126call: 127 tail call void @g() 128 br label %exit 129 130exit: 131 ret void 132} 133 134; ... and the same with the inverted direction. 135; CHECK-MAIN-LABEL: f5: 136; CHECK-MAIN: risbg [[RISBG:%r[1-9]+]], %r2, 0, 189, 0{{$}} 137; CHECK-MAIN-DAG: sll %r2, 3 138; CHECK-MAIN-DAG: l [[OLD:%r[0-9]+]], 0([[RISBG]]) 139; CHECK-MAIN: [[LOOP:\.[^ ]*]]: 140; CHECK-MAIN: rll [[TMP:%r[0-9]+]], [[OLD]], 8(%r2) 141; CHECK-MAIN: risbg %r3, [[TMP]], 32, 55, 0 142; CHECK-MAIN: cr [[TMP]], %r3 143; CHECK-MAIN: jlh [[EXIT:\.[^ ]*]] 144; CHECK-MAIN: risbg %r4, [[TMP]], 32, 55, 0 145; CHECK-MAIN: rll [[NEW:%r[0-9]+]], %r4, -8({{%r[1-9]+}}) 146; CHECK-MAIN: cs [[OLD]], [[NEW]], 0([[RISBG]]) 147; CHECK-MAIN: jl [[LOOP]] 148; CHECK-MAIN: [[EXIT]]: 149; CHECK-MAIN-NEXT: jlh [[LABEL:\.[^ ]*]] 150; CHECK-MAIN: br %r14 151; CHECK-MAIN: [[LABEL]]: 152; CHECK-MAIN: jg g 153; 154; CHECK-SHIFT-LABEL: f5: 155; CHECK-SHIFT: sll %r2, 3 156; CHECK-SHIFT: lcr [[NEGSHIFT:%r[1-9]+]], %r2 157; CHECK-SHIFT: rll 158; CHECK-SHIFT: rll {{%r[0-9]+}}, %r4, -8([[NEGSHIFT]]) 159define void @f5(i8 *%src, i8 %cmp, i8 %swap) { 160 %pair = cmpxchg i8 *%src, i8 %cmp, i8 %swap seq_cst seq_cst 161 %cond = extractvalue { i8, i1 } %pair, 1 162 br i1 %cond, label %exit, label %call 163 164call: 165 tail call void @g() 166 br label %exit 167 168exit: 169 ret void 170} 171 172