Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: tests_lit/llvm2ice_tests/nacl-atomic-cmpxchg-optimization.ll

Issue 413903002: Subzero: Add a peephole to fuse cmpxchg w/ later cmp+branch. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: blank Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceTargetLoweringX8632.cpp ('k') | tests_lit/llvm2ice_tests/nacl-atomic-intrinsics.ll » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 ; This tests the optimization of atomic cmpxchg w/ following cmp + branches.
2
3 ; RUN: %llvm2ice -O2 --verbose none %s | FileCheck %s --check-prefix=O2
4 ; RUN: %llvm2ice -Om1 --verbose none %s | FileCheck %s --check-prefix=OM1
5 ; RUN: %llvm2ice -O2 --verbose none %s \
6 ; RUN: | llvm-mc -arch=x86 -x86-asm-syntax=intel -filetype=obj
7 ; RUN: %llvm2ice -Om1 --verbose none %s \
8 ; RUN: | llvm-mc -arch=x86 -x86-asm-syntax=intel -filetype=obj
9 ; RUN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
10 ; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
11 ; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
12 ; RUN: | FileCheck --check-prefix=DUMP %s
13
14 declare i32 @llvm.nacl.atomic.cmpxchg.i32(i32*, i32, i32, i32, i32)
15
16
17 ; Test that a cmpxchg followed by icmp eq and branch can be optimized to
18 ; reuse the flags set by the cmpxchg instruction itself.
19 ; This is only expected to work w/ O2, based on lightweight liveness.
20 ; (Or if we had other means to detect the only use).
21 declare void @use_value(i32);
22
23 define i32 @test_atomic_cmpxchg_loop(i32 %iptr, i32 %expected, i32 %desired) {
24 entry:
25 br label %loop
26
27 loop:
28 %expected_loop = phi i32 [ %expected, %entry ], [ %old, %loop ]
29 %succeeded_first_try = phi i32 [ 1, %entry ], [ 2, %loop ]
30 %ptr = inttoptr i32 %iptr to i32*
31 %old = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %ptr, i32 %expected_loop,
32 i32 %desired, i32 6, i32 6)
33 %success = icmp eq i32 %expected_loop, %old
34 br i1 %success, label %done, label %loop
35
36 done:
37 call void @use_value(i32 %old)
38 ret i32 %succeeded_first_try
39 }
40 ; O2-LABEL: .Ltest_atomic_cmpxchg_loop{{.*}}loop
41 ; O2: lock cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}}
42 ; O2-NOT: cmp
43 ; Make sure the phi assignment for succeeded_first_try is still there.
44 ; O2: mov {{.*}}, 2
45 ; O2-NOT: cmp
46 ; O2: je
47 ; O2-LABEL: .Ltest_atomic_cmpxchg_loop{{.*}}done
48 ; Make sure the call isn't accidentally deleted.
49 ; O2: call
50 ;
51 ; Check that the unopt version does have a cmp
52 ; OM1-LABEL: .Ltest_atomic_cmpxchg_loop{{.*}}loop
53 ; OM1: lock cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}}
54 ; OM1: cmp
55 ; OM1: je
56 ; OM1-LABEL: .Ltest_atomic_cmpxchg_loop{{.*}}done
57 ; OM1: call
58
59 ; Still works if the compare operands are flipped.
60 define i32 @test_atomic_cmpxchg_loop2(i32 %iptr, i32 %expected, i32 %desired) {
61 entry:
62 br label %loop
63
64 loop:
65 %expected_loop = phi i32 [ %expected, %entry ], [ %old, %loop ]
66 %ptr = inttoptr i32 %iptr to i32*
67 %old = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %ptr, i32 %expected_loop,
68 i32 %desired, i32 6, i32 6)
69 %success = icmp eq i32 %old, %expected_loop
70 br i1 %success, label %done, label %loop
71
72 done:
73 ret i32 %old
74 }
75 ; O2-LABEL: .Ltest_atomic_cmpxchg_loop2{{.*}}loop
76 ; O2: lock cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}}
77 ; O2-NOT: cmp
78 ; O2: je
79
80
81 ; Still works if the compare operands are constants.
82 define i32 @test_atomic_cmpxchg_loop_const(i32 %iptr, i32 %desired) {
83 entry:
84 br label %loop
85
86 loop:
87 %succeeded_first_try = phi i32 [ 1, %entry ], [ 0, %loop ]
88 %ptr = inttoptr i32 %iptr to i32*
89 %old = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %ptr, i32 0,
90 i32 %desired, i32 6, i32 6)
91 %success = icmp eq i32 %old, 0
92 br i1 %success, label %done, label %loop
93
94 done:
95 ret i32 %succeeded_first_try
96 }
97 ; O2-LABEL: .Ltest_atomic_cmpxchg_loop_const{{.*}}loop
98 ; O2: lock cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}}
99 ; O2-NOT: cmp
100 ; O2: je
101
102 ; This is a case where the flags cannot be reused (compare is for some
103 ; other condition).
104 define i32 @test_atomic_cmpxchg_no_opt(i32 %iptr, i32 %expected, i32 %desired) {
105 entry:
106 br label %loop
107
108 loop:
109 %expected_loop = phi i32 [ %expected, %entry ], [ %old, %loop ]
110 %ptr = inttoptr i32 %iptr to i32*
111 %old = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %ptr, i32 %expected_loop,
112 i32 %desired, i32 6, i32 6)
113 %success = icmp sgt i32 %old, %expected
114 br i1 %success, label %done, label %loop
115
116 done:
117 ret i32 %old
118 }
119 ; O2-LABEL: .Ltest_atomic_cmpxchg_no_opt{{.*}}loop
120 ; O2: lock cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}}
121 ; O2: mov {{.*}}
122 ; O2: cmp
123 ; O2: jg
124
125 ; Another case where the flags cannot be reused (the comparison result
126 ; is used somewhere else).
127 define i32 @test_atomic_cmpxchg_no_opt2(i32 %iptr, i32 %expected, i32 %desired) {
128 entry:
129 br label %loop
130
131 loop:
132 %expected_loop = phi i32 [ %expected, %entry ], [ %old, %loop ]
133 %ptr = inttoptr i32 %iptr to i32*
134 %old = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %ptr, i32 %expected_loop,
135 i32 %desired, i32 6, i32 6)
136 %success = icmp eq i32 %old, %expected
137 br i1 %success, label %done, label %loop
138
139 done:
140 %r = zext i1 %success to i32
141 ret i32 %r
142 }
143 ; O2-LABEL: .Ltest_atomic_cmpxchg_no_opt2{{.*}}loop
144 ; O2: lock cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}}
145 ; O2: mov {{.*}}
146 ; O2: cmp
147 ; O2: je
148
149 ; ERRORS-NOT: ICE translation error
150 ; DUMP-NOT: SZ
OLDNEW
« no previous file with comments | « src/IceTargetLoweringX8632.cpp ('k') | tests_lit/llvm2ice_tests/nacl-atomic-intrinsics.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698