summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp5
-rw-r--r--llvm/test/Assembler/ConstantExprNoFold.ll5
2 files changed, 9 insertions, 1 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index cdfb41f7dcc..719a3a4b4c8 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -1348,9 +1348,12 @@ static FCmpInst::Predicate evaluateFCmpRelation(Constant *V1, Constant *V2) {
static ICmpInst::Predicate areGlobalsPotentiallyEqual(const GlobalValue *GV1,
const GlobalValue *GV2) {
+ auto isLinkageUnsafeForEquality = [](const GlobalValue *GV) {
+ return GV->hasExternalWeakLinkage() || GV->hasWeakAnyLinkage();
+ };
// Don't try to decide equality of aliases.
if (!isa<GlobalAlias>(GV1) && !isa<GlobalAlias>(GV2))
- if (!GV1->hasExternalWeakLinkage() || !GV2->hasExternalWeakLinkage())
+ if (!isLinkageUnsafeForEquality(GV1) && !isLinkageUnsafeForEquality(GV2))
return ICmpInst::ICMP_NE;
return ICmpInst::BAD_ICMP_PREDICATE;
}
diff --git a/llvm/test/Assembler/ConstantExprNoFold.ll b/llvm/test/Assembler/ConstantExprNoFold.ll
index 8d03e7a320b..bed58c52ad9 100644
--- a/llvm/test/Assembler/ConstantExprNoFold.ll
+++ b/llvm/test/Assembler/ConstantExprNoFold.ll
@@ -31,6 +31,11 @@ target datalayout = "p:32:32"
@weak.gep = global i32* getelementptr (i32* @weak, i32 1)
@weak = extern_weak global i32
+; An object with weak linkage cannot have it's identity determined at compile time.
+; CHECK: @F = global i1 icmp eq (i32* @weakany, i32* @glob)
+@F = global i1 icmp eq (i32* @weakany, i32* @glob)
+@weakany = weak global i32 0
+
; Don't add an inbounds on @glob.a3, since it's not inbounds.
; CHECK: @glob.a3 = alias getelementptr (i32* @glob.a2, i32 1)
@glob = global i32 0
OpenPOWER on IntegriCloud