Index: lib/Analysis/LazyValueInfo.cpp =================================================================== --- lib/Analysis/LazyValueInfo.cpp +++ lib/Analysis/LazyValueInfo.cpp @@ -696,12 +696,10 @@ Value *Val, BasicBlock *BB) { ValueLatticeElement Result; // Start Undefined. - // If this is the entry block, we must be asking about an argument. The - // value is overdefined. + // If this is the entry block, try to figure out what it is. + // Before giving up, see if we can prove the pointer non-null local to + // this particular block. if (BB == &BB->getParent()->getEntryBlock()) { - assert(isa(Val) && "Unknown live-in to the entry block"); - // Before giving up, see if we can prove the pointer non-null local to - // this particular block. if (Val->getType()->isPointerTy() && (isKnownNonZero(Val, DL) || isObjectDereferencedInBlock(Val, BB))) { PointerType *PTy = cast(Val->getType()); Index: unittests/Analysis/CMakeLists.txt =================================================================== --- unittests/Analysis/CMakeLists.txt +++ unittests/Analysis/CMakeLists.txt @@ -16,6 +16,7 @@ GlobalsModRefTest.cpp ValueLatticeTest.cpp LazyCallGraphTest.cpp + LazyValueInfoTest.cpp LoopInfoTest.cpp MemoryBuiltinsTest.cpp MemorySSA.cpp Index: unittests/Analysis/LazyValueInfoTest.cpp =================================================================== --- /dev/null +++ unittests/Analysis/LazyValueInfoTest.cpp @@ -0,0 +1,97 @@ +//===- LazyValueInfoTest.cpp - Lazy Value Info tests ----------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Analysis/LazyValueInfo.h" +#include "llvm/Analysis/AssumptionCache.h" +#include "llvm/Analysis/TargetLibraryInfo.h" +#include "llvm/AsmParser/Parser.h" +#include "llvm/IR/Dominators.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/SourceMgr.h" +#include "gtest/gtest.h" + +namespace llvm { +namespace { + +std::unique_ptr parseAssembly(LLVMContext &Context, + const char *Assembly) { + SMDiagnostic Error; + std::unique_ptr M = parseAssemblyString(Assembly, Error, Context); + + std::string ErrMsg; + raw_string_ostream OS(ErrMsg); + Error.print("", OS); + + // A failure here means that the test itself is buggy. + if (!M) + report_fatal_error(OS.str().c_str()); + + return M; +} + +// We use this fixture to ensure that we clean up ScalarEvolution before +// deleting the PassManager. +class LazyValueInfoTest : public testing::Test { +protected: + std::unique_ptr AC; + std::unique_ptr DT; + TargetLibraryInfoImpl TLII; + TargetLibraryInfo TLI; + + LazyValueInfoTest() : TLI(TLII) {} + + LazyValueInfo buildSE(Function &F) { + AC.reset(new AssumptionCache(F)); + DT.reset(new DominatorTree(F)); + return LazyValueInfo(&*AC, &(F.getParent()->getDataLayout()), &TLI, &*DT); + } +}; + +TEST_F(LazyValueInfoTest, PhiValueTracking) { + LLVMContext Context; + SMDiagnostic Error; + auto M = parseAssemblyString( + "target datalayout = \"e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128\" " + "define void @caller(i1 %c) {" + "entry:" + " br i1 %c, label %lhs, label %rhs " + " " + "lhs: " + " br label %last " + " " + "rhs: " + " br label %last " + " " + "last: " + " %x = add i32 10, 10" + " ret void " + "}", + Error, Context); + assert(M && "Bad assembly?"); + auto *F = (*M).getFunction("caller"); + + // Create the lazy value info object. + LazyValueInfo LVI = buildSE(*F); + + // Get the add instruction. + pred_iterator i = pred_begin(last); + BasicBlock *LHS = *i++; + BasicBlock *last = &*(--F->end()); + Instruction *I = &*last->begin(); + + // Try to figure out the constants on the edges. + Constant *LHSV = LVI.getConstant(I, LHS); + assert(!LHSV && "Succeeded to derive a constant ?"); +} + +} // namespace +} // namespace llvm