Index: llvm/lib/IR/Value.cpp =================================================================== --- llvm/lib/IR/Value.cpp +++ llvm/lib/IR/Value.cpp @@ -904,9 +904,7 @@ CanBeFreed = false; } } else if (auto *GV = dyn_cast(this)) { - if (GV->getValueType()->isSized() && !GV->hasExternalWeakLinkage()) { - // TODO: Don't outright reject hasExternalWeakLinkage but set the - // CanBeNull flag. + if (GV->getValueType()->isSized() && GV->hasDefinitiveInitializer()) { DerefBytes = DL.getTypeStoreSize(GV->getValueType()).getFixedValue(); CanBeNull = false; CanBeFreed = false; Index: llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll =================================================================== --- llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll +++ llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll @@ -16,10 +16,12 @@ @globali32ptr = external global ptr %struct.A = type { [8 x i8], [5 x i8] } -@globalstruct = external global %struct.A +@globalstruct = global %struct.A poison -@globalptr.align1 = external global i8, align 1 -@globalptr.align16 = external global i8, align 16 +@globalptr.align1 = global i8 poison, align 1 +@globalptr.align16 = global i8 poison, align 16 + +@globalptr.extern = external global i8 ; Loads from sret arguments ; CHECK-LABEL: 'test_sret' @@ -182,11 +184,13 @@ ; CHECK: @globalptr.align1{{.*}}(unaligned) ; CHECK: @globalptr.align16{{.*}}(aligned) ; CHECK: @globalstr{{.*}}(aligned) +; CHECK-NOT: @globalptr.extern define void @global() { %load13 = load i8, ptr @globalptr.align1, align 16 %load14 = load i8, ptr @globalptr.align16, align 16 %load1 = load i8, ptr @globalstr + %load2 = load i8, ptr @globalptr.extern ret void } Index: llvm/test/Transforms/Attributor/ArgumentPromotion/naked_functions.ll =================================================================== --- llvm/test/Transforms/Attributor/ArgumentPromotion/naked_functions.ll +++ llvm/test/Transforms/Attributor/ArgumentPromotion/naked_functions.ll @@ -12,7 +12,7 @@ define i32 @bar() { ; CHECK-LABEL: define {{[^@]+}}@bar() { ; CHECK-NEXT: entry: -; CHECK-NEXT: [[CALL:%.*]] = call i32 @foo(ptr noundef nonnull align 4 dereferenceable(4) @g) +; CHECK-NEXT: [[CALL:%.*]] = call i32 @foo(ptr noundef align 4 @g) ; CHECK-NEXT: ret i32 [[CALL]] ; entry: Index: llvm/test/Transforms/Attributor/IPConstantProp/pthreads.ll =================================================================== --- llvm/test/Transforms/Attributor/IPConstantProp/pthreads.ll +++ llvm/test/Transforms/Attributor/IPConstantProp/pthreads.ll @@ -38,7 +38,7 @@ ; TUNIT-NEXT: [[ALLOC2:%.*]] = alloca i8, align 8 ; TUNIT-NEXT: [[THREAD:%.*]] = alloca i64, align 8 ; TUNIT-NEXT: [[CALL:%.*]] = call i32 @pthread_create(ptr noundef nonnull align 8 dereferenceable(8) [[THREAD]], ptr noalias nocapture noundef align 4294967296 null, ptr noundef nonnull @foo, ptr noalias nocapture nofree readnone align 4294967296 undef) -; TUNIT-NEXT: [[CALL1:%.*]] = call i32 @pthread_create(ptr noundef nonnull align 8 dereferenceable(8) [[THREAD]], ptr noalias nocapture noundef align 4294967296 null, ptr noundef nonnull @bar, ptr noalias nocapture nofree nonnull readnone align 8 dereferenceable(8) undef) +; TUNIT-NEXT: [[CALL1:%.*]] = call i32 @pthread_create(ptr noundef nonnull align 8 dereferenceable(8) [[THREAD]], ptr noalias nocapture noundef align 4294967296 null, ptr noundef nonnull @bar, ptr noalias nocapture nofree readnone align 8 undef) ; TUNIT-NEXT: [[CALL2:%.*]] = call i32 @pthread_create(ptr noundef nonnull align 8 dereferenceable(8) [[THREAD]], ptr noalias nocapture noundef align 4294967296 null, ptr noundef nonnull @baz, ptr noalias nocapture nofree noundef nonnull readnone align 8 dereferenceable(1) [[ALLOC1]]) ; TUNIT-NEXT: [[CALL3:%.*]] = call i32 @pthread_create(ptr noundef nonnull align 8 dereferenceable(8) [[THREAD]], ptr noalias nocapture noundef align 4294967296 null, ptr noundef nonnull @buz, ptr noalias nofree noundef nonnull readnone align 8 dereferenceable(1) "no-capture-maybe-returned" [[ALLOC2]]) ; TUNIT-NEXT: ret i32 0 @@ -49,7 +49,7 @@ ; CGSCC-NEXT: [[ALLOC2:%.*]] = alloca i8, align 8 ; CGSCC-NEXT: [[THREAD:%.*]] = alloca i64, align 8 ; CGSCC-NEXT: [[CALL:%.*]] = call i32 @pthread_create(ptr noundef nonnull align 8 dereferenceable(8) [[THREAD]], ptr noalias nocapture noundef align 4294967296 null, ptr noundef nonnull @foo, ptr noalias nocapture nofree noundef readnone align 4294967296 null) -; CGSCC-NEXT: [[CALL1:%.*]] = call i32 @pthread_create(ptr noundef nonnull align 8 dereferenceable(8) [[THREAD]], ptr noalias nocapture noundef align 4294967296 null, ptr noundef nonnull @bar, ptr noalias nofree noundef nonnull readnone align 8 dereferenceable(8) @GlobalVPtr) +; CGSCC-NEXT: [[CALL1:%.*]] = call i32 @pthread_create(ptr noundef nonnull align 8 dereferenceable(8) [[THREAD]], ptr noalias nocapture noundef align 4294967296 null, ptr noundef nonnull @bar, ptr noalias nofree noundef readnone align 8 @GlobalVPtr) ; CGSCC-NEXT: [[CALL2:%.*]] = call i32 @pthread_create(ptr noundef nonnull align 8 dereferenceable(8) [[THREAD]], ptr noalias nocapture noundef align 4294967296 null, ptr noundef nonnull @baz, ptr noalias nocapture nofree noundef nonnull readnone align 8 dereferenceable(1) [[ALLOC1]]) ; CGSCC-NEXT: [[CALL3:%.*]] = call i32 @pthread_create(ptr noundef nonnull align 8 dereferenceable(8) [[THREAD]], ptr noalias nocapture noundef align 4294967296 null, ptr noundef nonnull @buz, ptr noalias nofree noundef nonnull readnone align 8 dereferenceable(1) [[ALLOC2]]) ; CGSCC-NEXT: ret i32 0 @@ -81,7 +81,7 @@ define internal ptr @bar(ptr %arg) { ; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none) ; CHECK-LABEL: define {{[^@]+}}@bar -; CHECK-SAME: (ptr noalias nocapture nofree nonnull readnone align 8 dereferenceable(8) [[ARG:%.*]]) #[[ATTR0]] { +; CHECK-SAME: (ptr noalias nocapture nofree readnone align 8 [[ARG:%.*]]) #[[ATTR0]] { ; CHECK-NEXT: entry: ; CHECK-NEXT: ret ptr @GlobalVPtr ; Index: llvm/test/Transforms/Attributor/memory_locations.ll =================================================================== --- llvm/test/Transforms/Attributor/memory_locations.ll +++ llvm/test/Transforms/Attributor/memory_locations.ll @@ -449,7 +449,7 @@ ; TUNIT: Function Attrs: nofree norecurse nosync nounwind willreturn memory(write) ; TUNIT-LABEL: define {{[^@]+}}@writeonly_global_via_arg ; TUNIT-SAME: () #[[ATTR6]] { -; TUNIT-NEXT: call void @write_global_via_arg(ptr nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) @G) #[[ATTR10]] +; TUNIT-NEXT: call void @write_global_via_arg(ptr nocapture nofree noundef writeonly align 4 @G) #[[ATTR10]] ; TUNIT-NEXT: ret void ; ; CGSCC: Function Attrs: nofree nosync nounwind willreturn memory(write) Index: llvm/test/Transforms/Attributor/noalias.ll =================================================================== --- llvm/test/Transforms/Attributor/noalias.ll +++ llvm/test/Transforms/Attributor/noalias.ll @@ -175,7 +175,7 @@ ; CGSCC: Function Attrs: nofree nosync nounwind willreturn memory(none) ; CGSCC-LABEL: define {{[^@]+}}@calle1 ; CGSCC-SAME: () #[[ATTR2:[0-9]+]] { -; CGSCC-NEXT: [[TMP1:%.*]] = call noundef nonnull align 8 dereferenceable(8) ptr @getter() #[[ATTR11:[0-9]+]] +; CGSCC-NEXT: [[TMP1:%.*]] = call noundef align 8 ptr @getter() #[[ATTR11:[0-9]+]] ; CGSCC-NEXT: ret ptr [[TMP1]] ; %1 = call ptr @getter() Index: llvm/test/Transforms/Attributor/nosync.ll =================================================================== --- llvm/test/Transforms/Attributor/nosync.ll +++ llvm/test/Transforms/Attributor/nosync.ll @@ -411,7 +411,7 @@ ; CHECK: Function Attrs: nounwind ; CHECK-LABEL: define {{[^@]+}}@i_totally_sync ; CHECK-SAME: () #[[ATTR14:[0-9]+]] { -; CHECK-NEXT: tail call void @llvm.x86.sse2.clflush(i8* noundef nonnull align 4 dereferenceable(4) bitcast (i32* @a to i8*)) +; CHECK-NEXT: tail call void @llvm.x86.sse2.clflush(i8* noundef align 4 bitcast (i32* @a to i8*)) ; CHECK-NEXT: ret void ; tail call void @llvm.x86.sse2.clflush(i8* bitcast (i32* @a to i8*)) Index: llvm/test/Transforms/Attributor/returned.ll =================================================================== --- llvm/test/Transforms/Attributor/returned.ll +++ llvm/test/Transforms/Attributor/returned.ll @@ -1405,7 +1405,7 @@ ; CGSCC: Function Attrs: nofree noinline nosync nounwind willreturn memory(none) uwtable ; CGSCC-LABEL: define {{[^@]+}}@use_const ; CGSCC-SAME: () #[[ATTR3]] { -; CGSCC-NEXT: [[C:%.*]] = call noundef nonnull dereferenceable(1) ptr @ret_const() #[[ATTR9:[0-9]+]] +; CGSCC-NEXT: [[C:%.*]] = call noundef ptr @ret_const() #[[ATTR9:[0-9]+]] ; CGSCC-NEXT: ret ptr [[C]] ; %c = call ptr @ret_const() @@ -1420,7 +1420,7 @@ ; CGSCC: Function Attrs: nofree noinline nosync nounwind willreturn memory(none) uwtable ; CGSCC-LABEL: define {{[^@]+}}@dont_use_const ; CGSCC-SAME: () #[[ATTR3]] { -; CGSCC-NEXT: [[C:%.*]] = musttail call noundef nonnull dereferenceable(1) ptr @ret_const() #[[ATTR9]] +; CGSCC-NEXT: [[C:%.*]] = musttail call noundef ptr @ret_const() #[[ATTR9]] ; CGSCC-NEXT: ret ptr [[C]] ; %c = musttail call ptr @ret_const() Index: llvm/test/Transforms/InstCombine/atomic.ll =================================================================== --- llvm/test/Transforms/InstCombine/atomic.ll +++ llvm/test/Transforms/InstCombine/atomic.ll @@ -231,8 +231,8 @@ ret i32 0 } -@a = external global i32 -@b = external global i32 +@a = global i32 0 +@b = global i32 0 define i32 @test15(i1 %cnd) { ; CHECK-LABEL: @test15( Index: llvm/test/Transforms/LICM/2008-07-22-LoadGlobalConstant.ll =================================================================== --- llvm/test/Transforms/LICM/2008-07-22-LoadGlobalConstant.ll +++ llvm/test/Transforms/LICM/2008-07-22-LoadGlobalConstant.ll @@ -6,13 +6,13 @@ define void @test(i32 %count) { ; CHECK-LABEL: @test( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[TMP3:%.*]] = load ptr, ptr @a, align 8 ; CHECK-NEXT: br label [[FORCOND:%.*]] ; CHECK: forcond: ; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FORBODY:%.*]] ] ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[I_0]], [[COUNT:%.*]] ; CHECK-NEXT: br i1 [[CMP]], label [[FORBODY]], label [[AFTERFOR:%.*]] ; CHECK: forbody: +; CHECK-NEXT: [[TMP3:%.*]] = load ptr, ptr @a, align 8 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr float, ptr [[TMP3]], i32 [[I_0]] ; CHECK-NEXT: [[TMP7:%.*]] = uitofp i32 [[I_0]] to float ; CHECK-NEXT: store float [[TMP7]], ptr [[ARRAYIDX]], align 4 Index: llvm/test/Transforms/LICM/lcssa-ssa-promoter.ll =================================================================== --- llvm/test/Transforms/LICM/lcssa-ssa-promoter.ll +++ llvm/test/Transforms/LICM/lcssa-ssa-promoter.ll @@ -8,8 +8,8 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" -@x = common global i32 0, align 4 -@y = common global i32 0, align 4 +@x = global i32 0, align 4 +@y = global i32 0, align 4 define void @PR18688() { ; CHECK-LABEL: @PR18688( Index: llvm/test/Transforms/LICM/promote-single-thread.ll =================================================================== --- llvm/test/Transforms/LICM/promote-single-thread.ll +++ llvm/test/Transforms/LICM/promote-single-thread.ll @@ -2,7 +2,7 @@ ; RUN: opt -S -passes=licm < %s | FileCheck %s --check-prefixes=CHECK,MT ; RUN: opt -S -passes=licm -licm-force-thread-model-single < %s | FileCheck %s --check-prefixes=CHECK,ST -@g = external global i32 +@g = global i32 0 @c = external constant i32 declare void @capture(ptr) @@ -70,12 +70,12 @@ define void @promote_constant_global(i1 %c, i1 %c2) { ; CHECK-LABEL: @promote_constant_global( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[V:%.*]] = load i32, ptr @c, align 4 -; CHECK-NEXT: [[V_INC:%.*]] = add i32 [[V]], 1 ; CHECK-NEXT: br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[LATCH:%.*]] ; CHECK: if: +; CHECK-NEXT: [[V:%.*]] = load i32, ptr @c, align 4 +; CHECK-NEXT: [[V_INC:%.*]] = add i32 [[V]], 1 ; CHECK-NEXT: store i32 [[V_INC]], ptr @c, align 4 ; CHECK-NEXT: br label [[LATCH]] ; CHECK: latch: Index: llvm/test/Transforms/LICM/scalar-promote-memmodel.ll =================================================================== --- llvm/test/Transforms/LICM/scalar-promote-memmodel.ll +++ llvm/test/Transforms/LICM/scalar-promote-memmodel.ll @@ -5,7 +5,7 @@ ; Make sure we don't hoist a conditionally-executed store out of the loop; ; it would violate the concurrency memory model -@g = common global i32 0, align 4 +@g = global i32 0, align 4 define void @bar(i32 %n, i32 %b) nounwind uwtable ssp { ; CHECK-LABEL: @bar( Index: llvm/test/Transforms/LoopVectorize/single-value-blend-phis.ll =================================================================== --- llvm/test/Transforms/LoopVectorize/single-value-blend-phis.ll +++ llvm/test/Transforms/LoopVectorize/single-value-blend-phis.ll @@ -1,8 +1,8 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -passes=loop-vectorize -force-vector-width=2 -S %s | FileCheck %s -@src = external global [32 x i16], align 1 -@dst = external global [32 x i16], align 1 +@src = global [32 x i16] poison, align 1 +@dst = global [32 x i16] poison, align 1 ; The load in the loop does not need predication, because the accessed memory ; is de-referenceable for all loop iterations. @@ -57,7 +57,7 @@ ; CHECK-NEXT: store i16 [[RES]], ptr [[DST_PTR]], align 2 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1 ; CHECK-NEXT: [[CMP439:%.*]] = icmp ult i64 [[IV]], 31 -; CHECK-NEXT: br i1 [[CMP439]], label [[LOOP_HEADER]], label [[EXIT]], !llvm.loop [[LOOP2:![0-9]+]] +; CHECK-NEXT: br i1 [[CMP439]], label [[LOOP_HEADER]], label [[EXIT]], !llvm.loop [[LOOP3:![0-9]+]] ; CHECK: exit: ; CHECK-NEXT: ret void ; Index: llvm/test/Transforms/SROA/phi-with-duplicate-pred.ll =================================================================== --- llvm/test/Transforms/SROA/phi-with-duplicate-pred.ll +++ llvm/test/Transforms/SROA/phi-with-duplicate-pred.ll @@ -3,7 +3,7 @@ ; RUN: opt < %s -passes='sroa' -S | FileCheck %s --check-prefixes=CHECK,CHECK-MODIFY-CFG target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n8:16:32:64" -@a = external global i16, align 1 +@a = global i16 0, align 1 declare void @maybe_writes() Index: llvm/test/Transforms/SimplifyCFG/X86/PR29163.ll =================================================================== --- llvm/test/Transforms/SimplifyCFG/X86/PR29163.ll +++ llvm/test/Transforms/SimplifyCFG/X86/PR29163.ll @@ -2,7 +2,7 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" -@GV = external constant ptr +@GV = global ptr null define ptr @test1(i1 %cond, ptr %P) { entry: Index: llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll =================================================================== --- llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll +++ llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll @@ -4,7 +4,7 @@ declare void @helper(i32) ;. -; CHECK: @[[MAX_REGNO:[a-zA-Z0-9_$"\\.-]+]] = common global i32 0, align 4 +; CHECK: @[[MAX_REGNO:[a-zA-Z0-9_$"\\.-]+]] = global i32 0, align 4 ;. define void @test1(i1 %a, i1 %b) { ; CHECK-LABEL: @test1( @@ -522,7 +522,7 @@ ;; When folding branches to common destination, the updated branch weights ;; can exceed uint32 by more than factor of 2. We should keep halving the ;; weights until they can fit into uint32. -@max_regno = common global i32 0, align 4 +@max_regno = global i32 0, align 4 define void @test14(ptr %old, i32 %final) { ; CHECK-LABEL: @test14( ; CHECK-NEXT: for.cond: Index: llvm/test/Transforms/TailCallElim/reorder_load.ll =================================================================== --- llvm/test/Transforms/TailCallElim/reorder_load.ll +++ llvm/test/Transforms/TailCallElim/reorder_load.ll @@ -9,7 +9,7 @@ -@global = external global i32 ; [#uses=1] +@global = global i32 0 @extern_weak_global = extern_weak global i32 ; [#uses=1]