[llvm] r244229 - 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 09:55:03 PDT 2015


Author: diamond
Date: Thu Aug  6 11:55:03 2015
New Revision: 244229

URL: http://llvm.org/viewvc/llvm-project?rev=244229&view=rev
Log:
Fix an alignment error in `llvm::expandAtomicRMWToCmpXchg` without breaking the build where X86 isn't enabled.

Summary: 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.

Reviewers: rengolin, jfb

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D11804

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

Modified: llvm/trunk/lib/CodeGen/AtomicExpandPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AtomicExpandPass.cpp?rev=244229&r1=244228&r2=244229&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AtomicExpandPass.cpp (original)
+++ llvm/trunk/lib/CodeGen/AtomicExpandPass.cpp Thu Aug  6 11:55:03 2015
@@ -550,7 +550,7 @@ bool llvm::expandAtomicRMWToCmpXchg(Atom
   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.

Added: llvm/trunk/test/Transforms/AtomicExpand/X86/expand-atomic-rmw-initial-load.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/AtomicExpand/X86/expand-atomic-rmw-initial-load.ll?rev=244229&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/AtomicExpand/X86/expand-atomic-rmw-initial-load.ll (added)
+++ llvm/trunk/test/Transforms/AtomicExpand/X86/expand-atomic-rmw-initial-load.ll Thu Aug  6 11:55:03 2015
@@ -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

Added: llvm/trunk/test/Transforms/AtomicExpand/X86/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/AtomicExpand/X86/lit.local.cfg?rev=244229&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/AtomicExpand/X86/lit.local.cfg (added)
+++ llvm/trunk/test/Transforms/AtomicExpand/X86/lit.local.cfg Thu Aug  6 11:55:03 2015
@@ -0,0 +1,2 @@
+if not 'X86' in config.root.targets:
+  config.unsupported = True




More information about the llvm-commits mailing list