[PATCH] D59080: Merge of global constants does not happen when constants have common linkage

Ramakota Reddy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 03:42:21 PDT 2019


ramred01 updated this revision to Diff 192597.
ramred01 retitled this revision from "Merge of global constants not happenning" to "Merge of global constants does not happen when constants have common linkage".
ramred01 edited the summary of this revision.
ramred01 added a subscriber: llvm-commits.
ramred01 added a comment.
Herald added a subscriber: javed.absar.

Updated the summary.

Added a test case.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59080/new/

https://reviews.llvm.org/D59080

Files:
  include/llvm/IR/GlobalAlias.h
  lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  lib/CodeGen/GlobalMerge.cpp
  test/CodeGen/AArch64/global_merge_ac6_aarch64.ll


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"
+
+ at global0 = common dso_local local_unnamed_addr global i32 0, align 4
+ at 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"}
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<PointerType>(GV.getType());
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: 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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59080.192597.patch
Type: text/x-patch
Size: 3851 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190328/e21cf27b/attachment.bin>


More information about the llvm-commits mailing list