mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-28 16:28:58 +00:00
GlobalOpt: do not promote globals used atomically to constants.
Some atomic loads are implemented as cmpxchg (particularly if large or floating), and that usually requires write access to the memory involved or it will segfault. We can still propagate the constant value to users we understand though. llvm-svn: 360662
This commit is contained in:
parent
25eba33f86
commit
79973f8a9d
@ -1980,7 +1980,12 @@ static bool processInternalGlobal(
|
||||
}
|
||||
if (GS.StoredType <= GlobalStatus::InitializerStored) {
|
||||
LLVM_DEBUG(dbgs() << "MARKING CONSTANT: " << *GV << "\n");
|
||||
GV->setConstant(true);
|
||||
|
||||
// Don't actually mark a global constant if it's atomic because atomic loads
|
||||
// are implemented by a trivial cmpxchg in some edge-cases and that usually
|
||||
// requires write access to the variable even if it's not actually changed.
|
||||
if (GS.Ordering == AtomicOrdering::NotAtomic)
|
||||
GV->setConstant(true);
|
||||
|
||||
// Clean up any obviously simplifiable users now.
|
||||
CleanupConstantGlobalUsers(GV, GV->getInitializer(), DL, TLI);
|
||||
|
@ -3,7 +3,7 @@
|
||||
@GV1 = internal global i64 1
|
||||
@GV2 = internal global i32 0
|
||||
|
||||
; CHECK: @GV1 = internal unnamed_addr constant i64 1
|
||||
; CHECK: @GV1 = internal unnamed_addr global i64 1
|
||||
; CHECK: @GV2 = internal unnamed_addr global i32 0
|
||||
|
||||
define void @test1() {
|
||||
@ -23,3 +23,12 @@ entry:
|
||||
%atomic-load = load atomic i32, i32* @GV2 seq_cst, align 4
|
||||
ret i32 %atomic-load
|
||||
}
|
||||
|
||||
|
||||
define i64 @test3() {
|
||||
; CHECK-LABEL: @test3
|
||||
; CHECK: ret i64 1
|
||||
|
||||
%val = load atomic i64, i64* @GV1 acquire, align 8
|
||||
ret i64 %val
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user