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