[PATCH] D37221: [AtomicExpand][X86] Let atomic expand generate inline sequence for unaligned load/store of atomic primitive integer types on x86_64

Wei Mi via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 30 14:00:30 PDT 2017


Turns out that the alignment difference of gcc and llvm is because
they use different libatomic. If they use the same libatomic from
gcc-4.9, both gcc and llvm will not align the atomic variable to 8
bytes, and both compiler will generate either plain load/store or
__atomic_load_8/__atomic_store_8, which is buggy.

The related bug entries are:
https://bugs.llvm.org/show_bug.cgi?id=23263
https://bugs.llvm.org/show_bug.cgi?id=34347

drop this patch and will propose another patch in clang to fix PR34347.

On Mon, Aug 28, 2017 at 1:16 PM, Wei Mi <wmi at google.com> wrote:
> You are right, so this is an incorrect fix.
>
> The correct fix is to increase the alignment of atomic variable. For
> the case in PR34347, GCC aligns the atomic variable to 8 bytes while
> Clang aligns the atomic variable to 4 bytes, and that leads to better
> code in GCC. I will try that.
>
>
> On Mon, Aug 28, 2017 at 11:05 AM, James Y Knight <jyknight at google.com> wrote:
>> I'm pretty sure the x86-64 manual said this was *not* guaranteed for
>> accesses that cross a cacheline. (On vacation, so am not going to lookup
>> quote)
>>
>> Do you read something that makes you think this is actually safe?
>>
>>
>> On Aug 28, 2017 1:36 PM, "Wei Mi via Phabricator" <reviews at reviews.llvm.org>
>> wrote:
>>
>> wmi created this revision.
>> Herald added a subscriber: sanjoy.
>>
>> The patch is to fix PR34347.
>>
>> Now llvm generates library calls of atomic_load/store for unaligned
>> load/store of atomic primitive integer type vars on x86_64. Since x86_64
>> support unaligned atomic load/store for primitive integers, this is not
>> efficient. The patch fixes that.
>>
>> To fix PR34347, change in clang is also needed. That will be included in
>> another patch.
>>
>>
>> Repository:
>>   rL LLVM
>>
>> https://reviews.llvm.org/D37221
>>
>> Files:
>>   include/llvm/Target/TargetLowering.h
>>   lib/CodeGen/AtomicExpandPass.cpp
>>   lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
>>   lib/Target/X86/X86ISelLowering.cpp
>>   lib/Target/X86/X86ISelLowering.h
>>   test/Transforms/AtomicExpand/X86/expand-unaligned-expansion.ll
>>
>>


More information about the llvm-commits mailing list