Index: include/llvm/IR/GlobalAlias.h =================================================================== --- include/llvm/IR/GlobalAlias.h +++ include/llvm/IR/GlobalAlias.h @@ -83,7 +83,8 @@ static bool isValidLinkage(LinkageTypes L) { return isExternalLinkage(L) || isLocalLinkage(L) || - isWeakLinkage(L) || isLinkOnceLinkage(L); + isWeakLinkage(L) || isLinkOnceLinkage(L) || + isCommonLinkage(L); } // Methods for support type inquiry through isa, cast, and dyn_cast: Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1330,12 +1330,14 @@ const GlobalIndirectSymbol& GIS) { MCSymbol *Name = getSymbol(&GIS); - if (GIS.hasExternalLinkage() || !MAI->getWeakRefDirective()) + if (GIS.hasExternalLinkage() || GIS.hasCommonLinkage() || + !MAI->getWeakRefDirective()) OutStreamer->EmitSymbolAttribute(Name, MCSA_Global); else if (GIS.hasWeakLinkage() || GIS.hasLinkOnceLinkage()) OutStreamer->EmitSymbolAttribute(Name, MCSA_WeakReference); else - assert(GIS.hasLocalLinkage() && "Invalid alias or ifunc linkage"); + assert((GIS.hasLocalLinkage()) && + "Invalid alias or ifunc linkage"); // Set the symbol type to function if the alias has a function type. // This affects codegen when the aliasee is not a function. Index: lib/CodeGen/GlobalMerge.cpp =================================================================== --- lib/CodeGen/GlobalMerge.cpp +++ lib/CodeGen/GlobalMerge.cpp @@ -616,8 +616,8 @@ if (TM && !TM->shouldAssumeDSOLocal(M, &GV)) continue; - if (!(MergeExternalGlobals && GV.hasExternalLinkage()) && - !GV.hasInternalLinkage()) + if (!(MergeExternalGlobals && GV.hasExternalLinkage())&& + !GV.hasInternalLinkage() && !GV.hasCommonLinkage()) continue; PointerType *PT = dyn_cast(GV.getType()); Index: test/CodeGen/AArch64/global_merge_ac6_aarch64.ll =================================================================== --- /dev/null +++ test/CodeGen/AArch64/global_merge_ac6_aarch64.ll @@ -0,0 +1,33 @@ +;RUN: llc -O3 %s -o - -verify-machineinstrs | FileCheck %s + +target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" +target triple = "aarch64-arm-none-eabi" + +@global0 = common dso_local local_unnamed_addr global i32 0, align 4 +@global1 = common dso_local local_unnamed_addr global i32 0, align 4 + +; Function Attrs: norecurse nounwind readonly +;CHECK-LABEL: @func +;CHECK: adrp +;CHECK-NEXT: add +;CHECK-NEXT: ldp +;CHECK-NEXT: add +;CHECK-NEXT: ret +define dso_local i32 @func() local_unnamed_addr #0 { + %1 = load i32, i32* @global0, align 4, !tbaa !2 + %2 = load i32, i32* @global1, align 4, !tbaa !2 + %3 = add nsw i32 %2, %1 + ret i32 %3 +} + +attributes #0 = { norecurse nounwind readonly "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+neon" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.module.flags = !{!0} +!llvm.ident = !{!1} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{!"clang version 9.0.0 (https://git.llvm.org/git/clang.git/ 112a7a3c34df3dc506b52cd89e155287cdbcea55) (https://git.llvm.org/git/llvm.git/ feeb3cebe7a586a8e1b12735024389dd8d3bab53)"} +!2 = !{!3, !3, i64 0} +!3 = !{!"int", !4, i64 0} +!4 = !{!"omnipotent char", !5, i64 0} +!5 = !{!"Simple C/C++ TBAA"}