From d88f60ed32939ca49426972af523512fdb4ae929 Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Wed, 19 Sep 2007 10:10:31 +0000 Subject: [PATCH] A global variable with external weak linkage can be null, while an alias could alias such a global variable. llvm-svn: 42130 --- lib/Transforms/Scalar/InstructionCombining.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 55ef0a80985..07eb2528c45 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -8936,8 +8936,12 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI) { /// specified pointer, we do a quick local scan of the basic block containing /// ScanFrom, to determine if the address is already accessed. static bool isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom) { - // If it is an alloca or global variable, it is always safe to load from. - if (isa(V) || isa(V)) return true; + // If it is an alloca it is always safe to load from. + if (isa(V)) return true; + + // Don't try to evaluate aliases. External weak GV can be null. + if (const GlobalValue *GV = dyn_cast(V)) + return !isa(GV) && !GV->hasExternalWeakLinkage(); // Otherwise, be a little bit agressive by scanning the local block where we // want to check to see if the pointer is already being loaded or stored