From: Richard Diamond Date: Thu, 6 Aug 2015 16:55:03 +0000 (+0000) Subject: Fix an alignment error in `llvm::expandAtomicRMWToCmpXchg` without breaking the build... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=972533b0a146a8af51174bd06e1b706b74f816e8;p=oota-llvm.git 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244229 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/AtomicExpandPass.cpp b/lib/CodeGen/AtomicExpandPass.cpp index 03b0ff32f15..c10648c6e3b 100644 --- a/lib/CodeGen/AtomicExpandPass.cpp +++ b/lib/CodeGen/AtomicExpandPass.cpp @@ -550,7 +550,7 @@ bool llvm::expandAtomicRMWToCmpXchg(AtomicRMWInst *AI, 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. diff --git a/test/Transforms/AtomicExpand/X86/expand-atomic-rmw-initial-load.ll b/test/Transforms/AtomicExpand/X86/expand-atomic-rmw-initial-load.ll new file mode 100644 index 00000000000..029a0e7b3e9 --- /dev/null +++ b/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 diff --git a/test/Transforms/AtomicExpand/X86/lit.local.cfg b/test/Transforms/AtomicExpand/X86/lit.local.cfg new file mode 100644 index 00000000000..afde89be896 --- /dev/null +++ b/test/Transforms/AtomicExpand/X86/lit.local.cfg @@ -0,0 +1,2 @@ +if not 'X86' in config.root.targets: + config.unsupported = True