From f8bc3008214c8327ff987573a111fc0dcefb7d25 Mon Sep 17 00:00:00 2001 From: Dale Johannesen Date: Wed, 13 May 2009 18:25:07 +0000 Subject: [PATCH] Don't generate a select whose operand is load of a weak external. These may have address 0 and are not safe to execute unconditionally. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71688 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/SimplifyCFG.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 4435b13e00b..48345915736 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -18,6 +18,7 @@ #include "llvm/IntrinsicInst.h" #include "llvm/Type.h" #include "llvm/DerivedTypes.h" +#include "llvm/GlobalVariable.h" #include "llvm/Support/CFG.h" #include "llvm/Support/Debug.h" #include "llvm/Analysis/ConstantFolding.h" @@ -393,6 +394,11 @@ static bool DominatesMergePoint(Value *V, BasicBlock *BB, if (!isa(I->getOperand(0)) && !isa(I->getOperand(0))) return false; + // External weak globals may have address 0, so we can't load them. + if (GlobalVariable* GV= dyn_cast(I->getOperand(0))) { + if (GV->hasExternalWeakLinkage()) + return false; + } // Finally, we have to check to make sure there are no instructions // before the load in its basic block, as we are going to hoist the loop