1 ; RUN: llc -verify-machineinstrs -mtriple=i386-linux-gnu %s -o - | FileCheck %s 2 ; RUN: llc -verify-machineinstrs -mtriple=i386-linux-gnu -pre-RA-sched=fast %s -o - | FileCheck %s 3 ; RUN: llc -verify-machineinstrs -mtriple=x86_64-linux-gnu %s -o - | FileCheck %s 4 ; RUN: llc -verify-machineinstrs -mtriple=x86_64-linux-gnu -pre-RA-sched=fast %s -o - | FileCheck %s 5 6 declare i32 @bar() 7 8 define i64 @test_intervening_call(i64* %foo, i64 %bar, i64 %baz) { 9 ; CHECK-LABEL: test_intervening_call: 10 ; CHECK: cmpxchg 11 ; CHECK: pushf[[LQ:[lq]]] 12 ; CHECK-NEXT: pop[[LQ]] [[FLAGS:%.*]] 13 14 ; CHECK-NEXT: call[[LQ]] bar 15 16 ; CHECK-NEXT: push[[LQ]] [[FLAGS]] 17 ; CHECK-NEXT: popf[[LQ]] 18 ; CHECK-NEXT: jne 19 %cx = cmpxchg i64* %foo, i64 %bar, i64 %baz seq_cst seq_cst 20 %p = extractvalue { i64, i1 } %cx, 1 21 call i32 @bar() 22 br i1 %p, label %t, label %f 23 24 t: 25 ret i64 42 26 27 f: 28 ret i64 0 29 } 30 31 ; Interesting in producing a clobber without any function calls. 32 define i32 @test_control_flow(i32* %p, i32 %i, i32 %j) { 33 ; CHECK-LABEL: test_control_flow: 34 35 ; CHECK: cmpxchg 36 ; CHECK-NEXT: jne 37 entry: 38 %cmp = icmp sgt i32 %i, %j 39 br i1 %cmp, label %loop_start, label %cond.end 40 41 loop_start: 42 br label %while.condthread-pre-split.i 43 44 while.condthread-pre-split.i: 45 %.pr.i = load i32, i32* %p, align 4 46 br label %while.cond.i 47 48 while.cond.i: 49 %0 = phi i32 [ %.pr.i, %while.condthread-pre-split.i ], [ 0, %while.cond.i ] 50 %tobool.i = icmp eq i32 %0, 0 51 br i1 %tobool.i, label %while.cond.i, label %while.body.i 52 53 while.body.i: 54 %.lcssa = phi i32 [ %0, %while.cond.i ] 55 %1 = cmpxchg i32* %p, i32 %.lcssa, i32 %.lcssa seq_cst seq_cst 56 %2 = extractvalue { i32, i1 } %1, 1 57 br i1 %2, label %cond.end.loopexit, label %while.condthread-pre-split.i 58 59 cond.end.loopexit: 60 br label %cond.end 61 62 cond.end: 63 %cond = phi i32 [ %i, %entry ], [ 0, %cond.end.loopexit ] 64 ret i32 %cond 65 } 66 67 ; This one is an interesting case because CMOV doesn't have a chain 68 ; operand. Naive attempts to limit cmpxchg EFLAGS use are likely to fail here. 69 define i32 @test_feed_cmov(i32* %addr, i32 %desired, i32 %new) { 70 ; CHECK-LABEL: test_feed_cmov: 71 72 ; CHECK: cmpxchg 73 ; CHECK: pushf[[LQ:[lq]]] 74 ; CHECK-NEXT: pop[[LQ]] [[FLAGS:%.*]] 75 76 ; CHECK-NEXT: call[[LQ]] bar 77 78 ; CHECK-NEXT: push[[LQ]] [[FLAGS]] 79 ; CHECK-NEXT: popf[[LQ]] 80 %res = cmpxchg i32* %addr, i32 %desired, i32 %new seq_cst seq_cst 81 %success = extractvalue { i32, i1 } %res, 1 82 83 %rhs = call i32 @bar() 84 85 %ret = select i1 %success, i32 %new, i32 %rhs 86 ret i32 %ret 87 } 88