Skip to content

Commit 38399ce

Browse files
efriedma-quictstellar
authored andcommitted
[ConstantFold] Make areGlobalsPotentiallyEqual less aggressive.
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)
1 parent b59b6b6 commit 38399ce

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

llvm/lib/IR/ConstantFold.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ static FCmpInst::Predicate evaluateFCmpRelation(Constant *V1, Constant *V2) {
15891589
static ICmpInst::Predicate areGlobalsPotentiallyEqual(const GlobalValue *GV1,
15901590
const GlobalValue *GV2) {
15911591
auto isGlobalUnsafeForEquality = [](const GlobalValue *GV) {
1592-
if (GV->hasExternalWeakLinkage() || GV->hasWeakAnyLinkage())
1592+
if (GV->isInterposable() || GV->hasGlobalUnnamedAddr())
15931593
return true;
15941594
if (const auto *GVar = dyn_cast<GlobalVariable>(GV)) {
15951595
Type *Ty = GVar->getValueType();

llvm/test/Assembler/ConstantExprNoFold.ll

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ target datalayout = "p:32:32"
4242
@empty.2 = external global [0 x i8], align 1
4343
@empty.cmp = global i1 icmp eq ([0 x i8]* @empty.1, [0 x i8]* @empty.2)
4444

45+
; Two unnamed_addr globals can share an address
46+
; CHECK: @unnamed.cmp = global i1 icmp eq ([5 x i8]* @unnamed.1, [5 x i8]* @unnamed.2)
47+
@unnamed.1 = unnamed_addr constant [5 x i8] c"asdf\00"
48+
@unnamed.2 = unnamed_addr constant [5 x i8] c"asdf\00"
49+
@unnamed.cmp = global i1 icmp eq ([5 x i8]* @unnamed.1, [5 x i8]* @unnamed.2)
50+
4551
@addrspace3 = internal addrspace(3) global i32 undef
4652

4753
; CHECK: @no.fold.addrspace.icmp.eq.gv.null = global i1 icmp eq (i32 addrspace(3)* @addrspace3, i32 addrspace(3)* null)

llvm/test/Transforms/InstCombine/2010-03-03-ExtElim.ll

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ define i1 @PR6486() nounwind {
1616
; CHECK: ret i1 true
1717
}
1818

19-
@d = common global i32 0, align 4
20-
@a = common global [1 x i32] zeroinitializer, align 4
19+
@d = global i32 0, align 4
20+
@a = global [1 x i32] zeroinitializer, align 4
2121

2222
define i1 @PR16462_1() nounwind {
2323
; CHECK-LABEL: @PR16462_1(

0 commit comments

Comments
 (0)