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
}
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);
@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() {
%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
+}