Skip to content

Commit

Permalink
[ConstantFold] Make areGlobalsPotentiallyEqual less aggressive.
Browse files Browse the repository at this point in the history
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

Differential Revision: https://reviews.llvm.org/D87123

(cherry picked from commit d751f86)
  • Loading branch information
efriedma-quic authored and tstellar committed Oct 31, 2020
1 parent b59b6b6 commit 38399ce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/IR/ConstantFold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ static FCmpInst::Predicate evaluateFCmpRelation(Constant *V1, Constant *V2) {
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();
Expand Down
6 changes: 6 additions & 0 deletions llvm/test/Assembler/ConstantExprNoFold.ll
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ target datalayout = "p:32:32"
@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 ([5 x i8]* @unnamed.1, [5 x i8]* @unnamed.2)
@unnamed.1 = unnamed_addr constant [5 x i8] c"asdf\00"
@unnamed.2 = unnamed_addr constant [5 x i8] c"asdf\00"
@unnamed.cmp = global i1 icmp eq ([5 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)
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Transforms/InstCombine/2010-03-03-ExtElim.ll
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ define i1 @PR6486() nounwind {
; CHECK: ret i1 true
}

@d = common global i32 0, align 4
@a = common global [1 x i32] zeroinitializer, align 4
@d = global i32 0, align 4
@a = global [1 x i32] zeroinitializer, align 4

define i1 @PR16462_1() nounwind {
; CHECK-LABEL: @PR16462_1(
Expand Down

0 comments on commit 38399ce

Please sign in to comment.