[PATCH] D27781: [X86] Fold (setcc (cmp (atomic_load_add x, -C) C), COND) to (setcc (LADD x, -C), COND) (PR31367)
Hans Wennborg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 14 15:34:18 PST 2016
hans created this revision.
hans added a reviewer: rnk.
hans added subscribers: llvm-commits, thakis.
This targets a pattern that occurrs frequently with reference counting pointers:
void decrement(long volatile *ptr) {
if (_InterlockedDecrement(ptr) == 0)
release();
}
Clang would previously compile it (for 32-bit at `-Os`) as:
00000000 <?decrement@@YAXPCJ at Z>:
0: 8b 44 24 04 mov 0x4(%esp),%eax
4: 31 c9 xor %ecx,%ecx
6: 49 dec %ecx
7: f0 0f c1 08 lock xadd %ecx,(%eax)
b: 83 f9 01 cmp $0x1,%ecx
e: 0f 84 00 00 00 00 je 14 <?decrement@@YAXPCJ at Z+0x14>
14: c3 ret
and with this patch it becomes:
00000000 <?decrement@@YAXPCJ at Z>:
0: 8b 44 24 04 mov 0x4(%esp),%eax
4: f0 ff 08 lock decl (%eax)
7: 0f 84 00 00 00 00 je d <?decrement@@YAXPCJ at Z+0xd>
d: c3 ret
(Equivalent variants with _InterlockedExchangeAdd, std::atomic<>'s fetch_add or pre-decrement operator generate the same code.)
https://reviews.llvm.org/D27781
Files:
lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/atomic-eflags-reuse.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27781.81486.patch
Type: text/x-patch
Size: 3833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161214/ff467a7c/attachment.bin>
More information about the llvm-commits
mailing list