| OLD | NEW |
| 1 ; This tests the optimization of atomic cmpxchg w/ following cmp + branches. | 1 ; This tests the optimization of atomic cmpxchg w/ following cmp + branches. |
| 2 | 2 |
| 3 ; RUN: %p2i -i %s --args -O2 --verbose none \ | 3 ; RUN: %p2i -i %s --args -O2 --verbose none \ |
| 4 ; RUN: | llvm-mc -triple=i686-none-nacl -x86-asm-syntax=intel -filetype=obj \ | 4 ; RUN: | llvm-mc -triple=i686-none-nacl -x86-asm-syntax=intel -filetype=obj \ |
| 5 ; RUN: | llvm-objdump -d -symbolize -x86-asm-syntax=intel - \ | 5 ; RUN: | llvm-objdump -d -symbolize -x86-asm-syntax=intel - \ |
| 6 ; RUN: | FileCheck --check-prefix=O2 %s | 6 ; RUN: | FileCheck --check-prefix=O2 %s |
| 7 ; RUN: %p2i -i %s --args -Om1 --verbose none \ | 7 ; RUN: %p2i -i %s --args -Om1 --verbose none \ |
| 8 ; RUN: | llvm-mc -triple=i686-none-nacl -x86-asm-syntax=intel -filetype=obj \ | 8 ; RUN: | llvm-mc -triple=i686-none-nacl -x86-asm-syntax=intel -filetype=obj \ |
| 9 ; RUN: | llvm-objdump -d -symbolize -x86-asm-syntax=intel - \ | 9 ; RUN: | llvm-objdump -d -symbolize -x86-asm-syntax=intel - \ |
| 10 ; RUN: | FileCheck --check-prefix=OM1 %s | 10 ; RUN: | FileCheck --check-prefix=OM1 %s |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 %success = icmp eq i32 %expected_loop, %old | 32 %success = icmp eq i32 %expected_loop, %old |
| 33 br i1 %success, label %done, label %loop | 33 br i1 %success, label %done, label %loop |
| 34 | 34 |
| 35 done: | 35 done: |
| 36 call void @use_value(i32 %old) | 36 call void @use_value(i32 %old) |
| 37 ret i32 %succeeded_first_try | 37 ret i32 %succeeded_first_try |
| 38 } | 38 } |
| 39 ; O2-LABEL: test_atomic_cmpxchg_loop | 39 ; O2-LABEL: test_atomic_cmpxchg_loop |
| 40 ; O2: lock | 40 ; O2: lock |
| 41 ; O2-NEXT: cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}} | 41 ; O2-NEXT: cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}} |
| 42 ; O2-NOT: cmp | 42 ; O2-NEXT: j{{e|ne}} |
| 43 ; Make sure the phi assignment for succeeded_first_try is still there. | |
| 44 ; O2: mov {{.*}}, 2 | |
| 45 ; O2-NOT: cmp | |
| 46 ; O2: jne | |
| 47 ; Make sure the call isn't accidentally deleted. | 43 ; Make sure the call isn't accidentally deleted. |
| 48 ; O2: call | 44 ; O2: call |
| 49 ; | 45 ; |
| 50 ; Check that the unopt version does have a cmp | 46 ; Check that the unopt version does have a cmp |
| 51 ; OM1-LABEL: test_atomic_cmpxchg_loop | 47 ; OM1-LABEL: test_atomic_cmpxchg_loop |
| 52 ; OM1: lock | 48 ; OM1: lock |
| 53 ; OM1-NEXT: cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}} | 49 ; OM1-NEXT: cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}} |
| 54 ; OM1: cmp | 50 ; OM1: cmp |
| 55 ; OM1: je | 51 ; OM1: je |
| 56 ; OM1: call | 52 ; OM1: call |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 i32 %desired, i32 6, i32 6) | 86 i32 %desired, i32 6, i32 6) |
| 91 %success = icmp eq i32 %old, 0 | 87 %success = icmp eq i32 %old, 0 |
| 92 br i1 %success, label %done, label %loop | 88 br i1 %success, label %done, label %loop |
| 93 | 89 |
| 94 done: | 90 done: |
| 95 ret i32 %succeeded_first_try | 91 ret i32 %succeeded_first_try |
| 96 } | 92 } |
| 97 ; O2-LABEL: test_atomic_cmpxchg_loop_const | 93 ; O2-LABEL: test_atomic_cmpxchg_loop_const |
| 98 ; O2: lock | 94 ; O2: lock |
| 99 ; O2-NEXT: cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}} | 95 ; O2-NEXT: cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}} |
| 100 ; O2-NOT: cmp | 96 ; O2-NEXT: j{{e|ne}} |
| 101 ; O2: jne | |
| 102 | 97 |
| 103 ; This is a case where the flags cannot be reused (compare is for some | 98 ; This is a case where the flags cannot be reused (compare is for some |
| 104 ; other condition). | 99 ; other condition). |
| 105 define i32 @test_atomic_cmpxchg_no_opt(i32 %iptr, i32 %expected, i32 %desired) { | 100 define i32 @test_atomic_cmpxchg_no_opt(i32 %iptr, i32 %expected, i32 %desired) { |
| 106 entry: | 101 entry: |
| 107 br label %loop | 102 br label %loop |
| 108 | 103 |
| 109 loop: | 104 loop: |
| 110 %expected_loop = phi i32 [ %expected, %entry ], [ %old, %loop ] | 105 %expected_loop = phi i32 [ %expected, %entry ], [ %old, %loop ] |
| 111 %ptr = inttoptr i32 %iptr to i32* | 106 %ptr = inttoptr i32 %iptr to i32* |
| 112 %old = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %ptr, i32 %expected_loop, | 107 %old = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %ptr, i32 %expected_loop, |
| 113 i32 %desired, i32 6, i32 6) | 108 i32 %desired, i32 6, i32 6) |
| 114 %success = icmp sgt i32 %old, %expected | 109 %success = icmp sgt i32 %old, %expected |
| 115 br i1 %success, label %done, label %loop | 110 br i1 %success, label %done, label %loop |
| 116 | 111 |
| 117 done: | 112 done: |
| 118 ret i32 %old | 113 ret i32 %old |
| 119 } | 114 } |
| 120 ; O2-LABEL: test_atomic_cmpxchg_no_opt | 115 ; O2-LABEL: test_atomic_cmpxchg_no_opt |
| 121 ; O2: lock | 116 ; O2: lock |
| 122 ; O2-NEXT: cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}} | 117 ; O2-NEXT: cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}} |
| 123 ; O2: mov {{.*}} | |
| 124 ; O2: cmp | 118 ; O2: cmp |
| 125 ; O2: jle | 119 ; O2: jle |
| 126 | 120 |
| 127 ; Another case where the flags cannot be reused (the comparison result | 121 ; Another case where the flags cannot be reused (the comparison result |
| 128 ; is used somewhere else). | 122 ; is used somewhere else). |
| 129 define i32 @test_atomic_cmpxchg_no_opt2(i32 %iptr, i32 %expected, i32 %desired)
{ | 123 define i32 @test_atomic_cmpxchg_no_opt2(i32 %iptr, i32 %expected, i32 %desired)
{ |
| 130 entry: | 124 entry: |
| 131 br label %loop | 125 br label %loop |
| 132 | 126 |
| 133 loop: | 127 loop: |
| 134 %expected_loop = phi i32 [ %expected, %entry ], [ %old, %loop ] | 128 %expected_loop = phi i32 [ %expected, %entry ], [ %old, %loop ] |
| 135 %ptr = inttoptr i32 %iptr to i32* | 129 %ptr = inttoptr i32 %iptr to i32* |
| 136 %old = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %ptr, i32 %expected_loop, | 130 %old = call i32 @llvm.nacl.atomic.cmpxchg.i32(i32* %ptr, i32 %expected_loop, |
| 137 i32 %desired, i32 6, i32 6) | 131 i32 %desired, i32 6, i32 6) |
| 138 %success = icmp eq i32 %old, %expected | 132 %success = icmp eq i32 %old, %expected |
| 139 br i1 %success, label %done, label %loop | 133 br i1 %success, label %done, label %loop |
| 140 | 134 |
| 141 done: | 135 done: |
| 142 %r = zext i1 %success to i32 | 136 %r = zext i1 %success to i32 |
| 143 ret i32 %r | 137 ret i32 %r |
| 144 } | 138 } |
| 145 ; O2-LABEL: test_atomic_cmpxchg_no_opt2 | 139 ; O2-LABEL: test_atomic_cmpxchg_no_opt2 |
| 146 ; O2: lock | 140 ; O2: lock |
| 147 ; O2-NEXT: cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}} | 141 ; O2-NEXT: cmpxchg dword ptr [e{{[^a].}}], e{{[^a]}} |
| 148 ; O2: mov {{.*}} | 142 ; O2: mov {{.*}} |
| 149 ; O2: cmp | 143 ; O2: cmp |
| 150 ; O2: je | 144 ; O2: je |
| 151 | 145 |
| 152 ; ERRORS-NOT: ICE translation error | 146 ; ERRORS-NOT: ICE translation error |
| OLD | NEW |