[PATCH] D87123: [ConstantFold] Make areGlobalsPotentiallyEqual less aggressive.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 3 21:11:12 PDT 2020


efriedma created this revision.
efriedma added reviewers: RalfJung, fhahn, majnemer.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
efriedma requested review of this revision.

In particular, we shouldn't make assumptions about globals which are unnamed_addr: we can fold them together with other globals.

Also while I'm here, use isInterposable() instead of trying to explicitly name all the different kinds of weak linkage.

Fixes https://bugs.llvm.org/show_bug.cgi?id=47090


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87123

Files:
  llvm/lib/IR/ConstantFold.cpp
  llvm/test/Assembler/ConstantExprNoFold.ll
  llvm/test/Transforms/InstCombine/2010-03-03-ExtElim.ll


Index: llvm/test/Transforms/InstCombine/2010-03-03-ExtElim.ll
===================================================================
--- llvm/test/Transforms/InstCombine/2010-03-03-ExtElim.ll
+++ llvm/test/Transforms/InstCombine/2010-03-03-ExtElim.ll
@@ -16,8 +16,8 @@
 ; CHECK: ret i1 true
 }
 
- at d = common global i32 0, align 4
- at a = common global [1 x i32] zeroinitializer, align 4
+ at d = global i32 0, align 4
+ at a = global [1 x i32] zeroinitializer, align 4
 
 define i1 @PR16462_1() nounwind {
 ; CHECK-LABEL: @PR16462_1(
Index: llvm/test/Assembler/ConstantExprNoFold.ll
===================================================================
--- llvm/test/Assembler/ConstantExprNoFold.ll
+++ llvm/test/Assembler/ConstantExprNoFold.ll
@@ -42,6 +42,12 @@
 @empty.2 = external global [0 x i8], align 1
 @empty.cmp = global i1 icmp eq ([0 x i8]* @empty.1, [0 x i8]* @empty.2)
 
+; Two unnamed_addr globals can share an address
+; CHECK: @unnamed.cmp = global i1 icmp eq ([0 x i8]* @unnamed.1, [5 x i8]* @unnamed.2)
+ at unnamed.1 = unnamed_addr constant [5 x i8] "asdf\0"
+ at unnamed.2 = unnamed_addr constant [5 x i8] "asdf\0"
+ at unnamed.cmp = global i1 icmp eq ([0 x i8]* @unnamed.1, [5 x i8]* @unnamed.2)
+
 @addrspace3 = internal addrspace(3) global i32 undef
 
 ; CHECK: @no.fold.addrspace.icmp.eq.gv.null = global i1 icmp eq (i32 addrspace(3)* @addrspace3, i32 addrspace(3)* null)
Index: llvm/lib/IR/ConstantFold.cpp
===================================================================
--- llvm/lib/IR/ConstantFold.cpp
+++ llvm/lib/IR/ConstantFold.cpp
@@ -1619,7 +1619,7 @@
 static ICmpInst::Predicate areGlobalsPotentiallyEqual(const GlobalValue *GV1,
                                                       const GlobalValue *GV2) {
   auto isGlobalUnsafeForEquality = [](const GlobalValue *GV) {
-    if (GV->hasExternalWeakLinkage() || GV->hasWeakAnyLinkage())
+    if (GV->isInterposable() || GV->hasGlobalUnnamedAddr())
       return true;
     if (const auto *GVar = dyn_cast<GlobalVariable>(GV)) {
       Type *Ty = GVar->getValueType();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87123.289851.patch
Type: text/x-patch
Size: 2039 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200904/1c3d68f0/attachment.bin>


More information about the llvm-commits mailing list