Divide the primitive size in bits by eight so the initial load's alignment is in
authorRichard Diamond <wichard@vitalitystudios.com>
Wed, 5 Aug 2015 22:10:57 +0000 (22:10 +0000)
committerRichard Diamond <wichard@vitalitystudios.com>
Wed, 5 Aug 2015 22:10:57 +0000 (22:10 +0000)
bytes as expected. Tested with the included unit test.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244155 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AtomicExpandPass.cpp
test/Transforms/AtomicExpand/expand-atomic-rmw-initial-load.ll [new file with mode: 0644]

index 03b0ff32f15c3a9f61274a1e80bd631d400635ff..c10648c6e3bcf2cc4333701f7884f78867dabd8f 100644 (file)
@@ -550,7 +550,7 @@ bool llvm::expandAtomicRMWToCmpXchg(AtomicRMWInst *AI,
   Builder.SetInsertPoint(BB);
   LoadInst *InitLoaded = Builder.CreateLoad(Addr);
   // Atomics require at least natural alignment.
   Builder.SetInsertPoint(BB);
   LoadInst *InitLoaded = Builder.CreateLoad(Addr);
   // Atomics require at least natural alignment.
-  InitLoaded->setAlignment(AI->getType()->getPrimitiveSizeInBits());
+  InitLoaded->setAlignment(AI->getType()->getPrimitiveSizeInBits() / 8);
   Builder.CreateBr(LoopBB);
 
   // Start the main loop block now that we've taken care of the preliminaries.
   Builder.CreateBr(LoopBB);
 
   // Start the main loop block now that we've taken care of the preliminaries.
diff --git a/test/Transforms/AtomicExpand/expand-atomic-rmw-initial-load.ll b/test/Transforms/AtomicExpand/expand-atomic-rmw-initial-load.ll
new file mode 100644 (file)
index 0000000..197250e
--- /dev/null
@@ -0,0 +1,8 @@
+; RUN: opt -S %s -atomic-expand -mtriple=i686-linux-gnu | FileCheck %s
+
+define i8 @test_initial_load(i8* %ptr, i8 %value) {
+  %res = atomicrmw nand i8* %ptr, i8 %value seq_cst
+  ret i8 %res
+}
+; CHECK-LABEL: @test_initial_load
+; CHECK-NEXT:    %1 = load i8, i8* %ptr, align 1