[PATCH] D11804: Fix an alignment error in `llvm::expandAtomicRMWToCmpXchg` without breaking the build where X86 isn't enabled.

Richard Diamond via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 6 08:56:40 PDT 2015


DiamondLovesYou created this revision.
DiamondLovesYou added reviewers: jfb, rengolin.
DiamondLovesYou added a subscriber: llvm-commits.
DiamondLovesYou set the repository for this revision to rL LLVM.

Divide the primitive size in bits by eight so the initial load's alignment is in bytes as expected. Tested with the included unit test.

Repository:
  rL LLVM

http://reviews.llvm.org/D11804

Files:
  lib/CodeGen/AtomicExpandPass.cpp
  test/Transforms/AtomicExpand/X86/expand-atomic-rmw-initial-load.ll
  test/Transforms/AtomicExpand/X86/lit.local.cfg

Index: test/Transforms/AtomicExpand/X86/lit.local.cfg
===================================================================
--- /dev/null
+++ test/Transforms/AtomicExpand/X86/lit.local.cfg
@@ -0,0 +1,2 @@
+if not 'X86' in config.root.targets:
+  config.unsupported = True
Index: test/Transforms/AtomicExpand/X86/expand-atomic-rmw-initial-load.ll
===================================================================
--- /dev/null
+++ test/Transforms/AtomicExpand/X86/expand-atomic-rmw-initial-load.ll
@@ -0,0 +1,11 @@
+; RUN: opt -S %s -atomic-expand -mtriple=i686-linux-gnu | FileCheck %s
+
+; This file tests the function `llvm::expandAtomicRMWToCmpXchg`.
+; It isn't technically target specific, but is exposed through a pass that is.
+
+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
Index: lib/CodeGen/AtomicExpandPass.cpp
===================================================================
--- lib/CodeGen/AtomicExpandPass.cpp
+++ lib/CodeGen/AtomicExpandPass.cpp
@@ -550,7 +550,7 @@
   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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11804.31450.patch
Type: text/x-patch
Size: 1535 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150806/cd2faa98/attachment.bin>


More information about the llvm-commits mailing list