From: Duncan P. N. Exon Smith Date: Fri, 25 Jul 2014 14:49:26 +0000 (+0000) Subject: IPO: Add use-list-order verifier X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=7bf73bd378b900db725820c17ff67460143f7024 IPO: Add use-list-order verifier Add a -verify-use-list-order pass, which shuffles use-list order, writes to bitcode, reads back, and verifies that the (shuffled) order matches. - The utility functions live in lib/IR/UseListOrder.cpp. - Moved (and renamed) the command-line option to enable writing use-lists, so that this pass can return early if the use-list orders aren't being serialized. It's not clear that this pass is the right direction long-term (perhaps a separate tool instead?), but short-term it's a great way to test the use-list order prototype. I've added an XFAIL-ed testcase that I'm hoping to get working pretty quickly. This is part of PR5680. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213945 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/UseListOrder.h b/include/llvm/IR/UseListOrder.h new file mode 100644 index 00000000000..aaf6b8882ad --- /dev/null +++ b/include/llvm/IR/UseListOrder.h @@ -0,0 +1,42 @@ +//===- llvm/IR/UseListOrder.h - LLVM Use List Order functions ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file has functions to modify the use-list order and to verify that it +// doesn't change after serialization. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_IR_USELISTORDER_H +#define LLVM_IR_USELISTORDER_H + +namespace llvm { + +class Module; + +/// \brief Whether to preserve use-list ordering. +bool shouldPreserveBitcodeUseListOrder(); + +/// \brief Shuffle all use-lists in a module. +/// +/// Adds \c SeedOffset to the default seed for the random number generator. +void shuffleUseLists(Module &M, unsigned SeedOffset = 0); + +/// \brief Verify use-list order after serializing to bitcode. +/// +/// \return \c true if there are no errors. +bool verifyBitcodeUseListOrder(const Module &M); + +/// \brief Verify use-list order after serializing to assembly. +/// +/// \return \c true if there are no errors. +bool verifyAssemblyUseListOrder(const Module &M); + +} // end namespace llvm + +#endif diff --git a/include/llvm/InitializePasses.h b/include/llvm/InitializePasses.h index 20074f0a5d5..ae036b462ab 100644 --- a/include/llvm/InitializePasses.h +++ b/include/llvm/InitializePasses.h @@ -268,6 +268,7 @@ void initializeUnifyFunctionExitNodesPass(PassRegistry&); void initializeUnreachableBlockElimPass(PassRegistry&); void initializeUnreachableMachineBlockElimPass(PassRegistry&); void initializeVerifierLegacyPassPass(PassRegistry&); +void initializeVerifyUseListOrderPass(PassRegistry&); void initializeVirtRegMapPass(PassRegistry&); void initializeVirtRegRewriterPass(PassRegistry&); void initializeInstSimplifierPass(PassRegistry&); diff --git a/include/llvm/LinkAllPasses.h b/include/llvm/LinkAllPasses.h index b7f832dcee9..ec695c8b79c 100644 --- a/include/llvm/LinkAllPasses.h +++ b/include/llvm/LinkAllPasses.h @@ -161,6 +161,7 @@ namespace { (void) llvm::createPartiallyInlineLibCallsPass(); (void) llvm::createScalarizerPass(); (void) llvm::createSeparateConstOffsetFromGEPPass(); + (void) llvm::createVerifyUseListOrderPass(); (void)new llvm::IntervalPartition(); (void)new llvm::FindUsedTypes(); diff --git a/include/llvm/Transforms/IPO.h b/include/llvm/Transforms/IPO.h index ce1a7d6a523..ca6d5144fc4 100644 --- a/include/llvm/Transforms/IPO.h +++ b/include/llvm/Transforms/IPO.h @@ -118,6 +118,11 @@ ModulePass *createInternalizePass(ArrayRef ExportList); /// createInternalizePass - Same as above, but with an empty exportList. ModulePass *createInternalizePass(); +/// \brief Verify that use-list order doesn't change after shuffling. +/// +/// \note This is a transformation, since the use-list order changes. +ModulePass *createVerifyUseListOrderPass(); + //===----------------------------------------------------------------------===// /// createDeadArgEliminationPass - This pass removes arguments from functions /// which are not used by the body of the function. diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index b2e49486d70..cb3f42b071c 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -22,6 +22,7 @@ #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" +#include "llvm/IR/UseListOrder.h" #include "llvm/IR/ValueSymbolTable.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" @@ -32,12 +33,6 @@ #include using namespace llvm; -static cl::opt -EnablePreserveUseListOrdering("enable-bc-uselist-preserve", - cl::desc("Turn on experimental support for " - "use-list order preservation."), - cl::init(false), cl::Hidden); - /// These are manifest constants used by the bitcode writer. They do not need to /// be kept in sync with the reader, but need to be consistent within this file. enum { @@ -1975,7 +1970,7 @@ static void WriteModule(const Module *M, BitstreamWriter &Stream) { WriteValueSymbolTable(M->getValueSymbolTable(), VE, Stream); // Emit use-lists. - if (EnablePreserveUseListOrdering) + if (shouldPreserveBitcodeUseListOrder()) WriteModuleUseLists(M, VE, Stream); // Emit function bodies. diff --git a/lib/IR/CMakeLists.txt b/lib/IR/CMakeLists.txt index 38a80b18bd5..b3889e6fdf6 100644 --- a/lib/IR/CMakeLists.txt +++ b/lib/IR/CMakeLists.txt @@ -39,6 +39,7 @@ add_llvm_library(LLVMCore Type.cpp TypeFinder.cpp Use.cpp + UseListOrder.cpp User.cpp Value.cpp ValueSymbolTable.cpp diff --git a/lib/IR/UseListOrder.cpp b/lib/IR/UseListOrder.cpp new file mode 100644 index 00000000000..42398baaa37 --- /dev/null +++ b/lib/IR/UseListOrder.cpp @@ -0,0 +1,423 @@ +//===- UseListOrder.cpp - Implement Use List Order functions --------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Implement use list order functions to modify use-list order and verify it +// doesn't change after serialization. +// +//===----------------------------------------------------------------------===// + +#include "llvm/IR/UseListOrder.h" + +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" +#include "llvm/AsmParser/Parser.h" +#include "llvm/Bitcode/ReaderWriter.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/FileUtilities.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/SourceMgr.h" + +#include +#include + +#define DEBUG_TYPE "use-list-order" + +using namespace llvm; + +static cl::opt PreserveBitcodeUseListOrder( + "preserve-bc-use-list-order", + cl::desc("Experimental support to preserve bitcode use-list order."), + cl::init(false), cl::Hidden); + +bool llvm::shouldPreserveBitcodeUseListOrder() { + return PreserveBitcodeUseListOrder; +} + +static void shuffleValueUseLists(Value *V, std::minstd_rand0 &Gen, + DenseSet &Seen) { + if (!Seen.insert(V).second) + return; + + if (auto *C = dyn_cast(V)) + if (!isa(C)) + for (Value *Op : C->operands()) + shuffleValueUseLists(Op, Gen, Seen); + + if (V->use_empty() || std::next(V->use_begin()) == V->use_end()) + // Nothing to shuffle for 0 or 1 users. + return; + + // Generate random numbers between 10 and 99, which will line up nicely in + // debug output. We're not worried about collisons here. + DEBUG(dbgs() << "V = "; V->dump()); + std::uniform_int_distribution Dist(10, 99); + SmallDenseMap Order; + for (const Use &U : V->uses()) { + auto I = Dist(Gen); + Order[&U] = I; + DEBUG(dbgs() << " - order: " << I << ", U = "; U.getUser()->dump()); + } + + DEBUG(dbgs() << " => shuffle\n"); + V->sortUseList( + [&Order](const Use &L, const Use &R) { return Order[&L] < Order[&R]; }); + + DEBUG({ + for (const Use &U : V->uses()) + DEBUG(dbgs() << " - order: " << Order.lookup(&U) << ", U = "; + U.getUser()->dump()); + }); +} + +void llvm::shuffleUseLists(Module &M, unsigned SeedOffset) { + DEBUG(dbgs() << "*** shuffle-use-lists ***\n"); + std::minstd_rand0 Gen(std::minstd_rand0::default_seed + SeedOffset); + DenseSet Seen; + + // Shuffle the use-list of each value that would be serialized to an IR file + // (bitcode or assembly). + auto shuffle = [&](Value *V) { shuffleValueUseLists(V, Gen, Seen); }; + + // Globals. + for (GlobalVariable &G : M.globals()) + shuffle(&G); + for (GlobalAlias &A : M.aliases()) + shuffle(&A); + for (Function &F : M) + shuffle(&F); + + // Constants used by globals. + for (GlobalVariable &G : M.globals()) + if (G.hasInitializer()) + shuffle(G.getInitializer()); + for (GlobalAlias &A : M.aliases()) + shuffle(A.getAliasee()); + for (Function &F : M) + if (F.hasPrefixData()) + shuffle(F.getPrefixData()); + + // Function bodies. + for (Function &F : M) { + for (Argument &A : F.args()) + shuffle(&A); + for (BasicBlock &BB : F) + shuffle(&BB); + for (BasicBlock &BB : F) + for (Instruction &I : BB) + shuffle(&I); + + // Constants used by instructions. + for (BasicBlock &BB : F) + for (Instruction &I : BB) + for (Value *Op : I.operands()) + if ((isa(Op) && !isa(*Op)) || + isa(Op)) + shuffle(Op); + } + + DEBUG(dbgs() << "\n"); +} + +namespace { + +struct TempFile { + std::string Filename; + FileRemover Remover; + bool init(const std::string &Ext); + bool writeBitcode(const Module &M) const; + bool writeAssembly(const Module &M) const; + std::unique_ptr readBitcode(LLVMContext &Context) const; + std::unique_ptr readAssembly(LLVMContext &Context) const; +}; + +struct ValueMapping { + DenseMap IDs; + std::vector Values; + + /// \brief Construct a value mapping for module. + /// + /// Creates mapping from every value in \c M to an ID. This mapping includes + /// un-referencable values. + /// + /// Every \a Value that gets serialized in some way should be represented + /// here. The order needs to be deterministic, but it's unnecessary to match + /// the value-ids in the bitcode writer. + /// + /// All constants that are referenced by other values are included in the + /// mapping, but others -- which wouldn't be serialized -- are not. + ValueMapping(const Module &M); + + /// \brief Map a value. + /// + /// Maps a value. If it's a constant, maps all of its operands first. + void map(const Value *V); + unsigned lookup(const Value *V) const { return IDs.lookup(V); } +}; + +} // end namespace + +bool TempFile::init(const std::string &Ext) { + SmallVector Vector; + DEBUG(dbgs() << " - create-temp-file\n"); + if (auto EC = sys::fs::createTemporaryFile("use-list-order", Ext, Vector)) { + DEBUG(dbgs() << "error: " << EC.message() << "\n"); + return true; + } + assert(!Vector.empty()); + + Filename.assign(Vector.data(), Vector.data() + Vector.size()); + Remover.setFile(Filename); + DEBUG(dbgs() << " - filename = " << Filename << "\n"); + return false; +} + +bool TempFile::writeBitcode(const Module &M) const { + DEBUG(dbgs() << " - write bitcode\n"); + std::string ErrorInfo; + raw_fd_ostream OS(Filename.c_str(), ErrorInfo, sys::fs::F_None); + if (!ErrorInfo.empty()) { + DEBUG(dbgs() << "error: " << ErrorInfo << "\n"); + return true; + } + + WriteBitcodeToFile(&M, OS); + return false; +} + +bool TempFile::writeAssembly(const Module &M) const { + DEBUG(dbgs() << " - write assembly\n"); + std::string ErrorInfo; + raw_fd_ostream OS(Filename.c_str(), ErrorInfo, sys::fs::F_Text); + if (!ErrorInfo.empty()) { + DEBUG(dbgs() << "error: " << ErrorInfo << "\n"); + return true; + } + + OS << M; + return false; +} + +std::unique_ptr TempFile::readBitcode(LLVMContext &Context) const { + DEBUG(dbgs() << " - read bitcode\n"); + ErrorOr> BufferOr = + MemoryBuffer::getFile(Filename); + if (!BufferOr) { + DEBUG(dbgs() << "error: " << BufferOr.getError().message() << "\n"); + return nullptr; + } + + std::unique_ptr Buffer = std::move(BufferOr.get()); + ErrorOr ModuleOr = parseBitcodeFile(Buffer.release(), Context); + if (!ModuleOr) { + DEBUG(dbgs() << "error: " << ModuleOr.getError().message() << "\n"); + return nullptr; + } + return std::unique_ptr(ModuleOr.get()); +} + +std::unique_ptr TempFile::readAssembly(LLVMContext &Context) const { + DEBUG(dbgs() << " - read assembly\n"); + SMDiagnostic Err; + std::unique_ptr M(ParseAssemblyFile(Filename, Err, Context)); + if (!M.get()) + DEBUG(dbgs() << "error: "; Err.print("verify-use-list-order", dbgs())); + return M; +} + +ValueMapping::ValueMapping(const Module &M) { + // Every value should be mapped, including things like void instructions and + // basic blocks that are kept out of the ValueEnumerator. + // + // The current mapping order makes it easier to debug the tables. It happens + // to be similar to the ID mapping when writing ValueEnumerator, but they + // aren't (and needn't be) in sync. + + // Globals. + for (const GlobalVariable &G : M.globals()) + map(&G); + for (const GlobalAlias &A : M.aliases()) + map(&A); + for (const Function &F : M) + map(&F); + + // Constants used by globals. + for (const GlobalVariable &G : M.globals()) + if (G.hasInitializer()) + map(G.getInitializer()); + for (const GlobalAlias &A : M.aliases()) + map(A.getAliasee()); + for (const Function &F : M) + if (F.hasPrefixData()) + map(F.getPrefixData()); + + // Function bodies. + for (const Function &F : M) { + for (const Argument &A : F.args()) + map(&A); + for (const BasicBlock &BB : F) + map(&BB); + for (const BasicBlock &BB : F) + for (const Instruction &I : BB) + map(&I); + + // Constants used by instructions. + for (const BasicBlock &BB : F) + for (const Instruction &I : BB) + for (const Value *Op : I.operands()) + if ((isa(Op) && !isa(*Op)) || + isa(Op)) + map(Op); + } +} + +void ValueMapping::map(const Value *V) { + if (IDs.lookup(V)) + return; + + if (auto *C = dyn_cast(V)) + if (!isa(C)) + for (const Value *Op : C->operands()) + map(Op); + + Values.push_back(V); + IDs[V] = Values.size(); +} + +#ifndef NDEBUG +static void dumpMapping(const ValueMapping &VM) { + dbgs() << "value-mapping (size = " << VM.Values.size() << "):\n"; + for (unsigned I = 0, E = VM.Values.size(); I != E; ++I) { + dbgs() << " - id = " << I << ", value = "; + VM.Values[I]->dump(); + } +} + +static void debugValue(const ValueMapping &M, unsigned I, StringRef Desc) { + const Value *V = M.Values[I]; + dbgs() << " - " << Desc << " value = "; + V->dump(); + for (const Use &U : V->uses()) { + dbgs() << " => use: op = " << U.getOperandNo() + << ", user-id = " << M.IDs.lookup(U.getUser()) << ", user = "; + U.getUser()->dump(); + } +} + +static void debugUserMismatch(const ValueMapping &L, const ValueMapping &R, + unsigned I) { + dbgs() << " - fail: user mismatch: ID = " << I << "\n"; + debugValue(L, I, "LHS"); + debugValue(R, I, "RHS"); + + dbgs() << "\nlhs-"; + dumpMapping(L); + dbgs() << "\nrhs-"; + dumpMapping(R); +} + +static void debugSizeMismatch(const ValueMapping &L, const ValueMapping &R) { + dbgs() << " - fail: map size: " << L.Values.size() + << " != " << R.Values.size() << "\n"; + dbgs() << "\nlhs-"; + dumpMapping(L); + dbgs() << "\nrhs-"; + dumpMapping(R); +} +#endif + +static bool matches(const ValueMapping &LM, const ValueMapping &RM) { + DEBUG(dbgs() << "compare value maps\n"); + if (LM.Values.size() != RM.Values.size()) { + DEBUG(debugSizeMismatch(LM, RM)); + return false; + } + + // This mapping doesn't include dangling constant users, since those don't + // get serialized. However, checking if users are constant and calling + // isConstantUsed() on every one is very expensive. Instead, just check if + // the user is mapped. + auto skipUnmappedUsers = + [&](Value::const_use_iterator &U, Value::const_use_iterator E, + const ValueMapping &M) { + while (U != E && !M.lookup(U->getUser())) + ++U; + }; + + // Iterate through all values, and check that both mappings have the same + // users. + for (unsigned I = 0, E = LM.Values.size(); I != E; ++I) { + const Value *L = LM.Values[I]; + const Value *R = RM.Values[I]; + auto LU = L->use_begin(), LE = L->use_end(); + auto RU = R->use_begin(), RE = R->use_end(); + skipUnmappedUsers(LU, LE, LM); + skipUnmappedUsers(RU, RE, RM); + + while (LU != LE) { + if (RU == RE) { + DEBUG(debugUserMismatch(LM, RM, I)); + return false; + } + if (LM.lookup(LU->getUser()) != RM.lookup(RU->getUser())) { + DEBUG(debugUserMismatch(LM, RM, I)); + return false; + } + if (LU->getOperandNo() != RU->getOperandNo()) { + DEBUG(debugUserMismatch(LM, RM, I)); + return false; + } + skipUnmappedUsers(++LU, LE, LM); + skipUnmappedUsers(++RU, RE, RM); + } + if (RU != RE) { + DEBUG(debugUserMismatch(LM, RM, I)); + return false; + } + } + + return true; +} + +bool llvm::verifyBitcodeUseListOrder(const Module &M) { + DEBUG(dbgs() << "*** verify-use-list-order: bitcode ***\n"); + TempFile F; + if (F.init("bc")) + return false; + + if (F.writeBitcode(M)) + return false; + + LLVMContext Context; + std::unique_ptr OtherM = F.readBitcode(Context); + if (!OtherM) + return false; + + return matches(ValueMapping(M), ValueMapping(*OtherM)); +} + +bool llvm::verifyAssemblyUseListOrder(const Module &M) { + DEBUG(dbgs() << "*** verify-use-list-order: assembly ***\n"); + TempFile F; + if (F.init("ll")) + return false; + + if (F.writeAssembly(M)) + return false; + + LLVMContext Context; + std::unique_ptr OtherM = F.readAssembly(Context); + if (!OtherM) + return false; + + return matches(ValueMapping(M), ValueMapping(*OtherM)); +} diff --git a/lib/Transforms/IPO/CMakeLists.txt b/lib/Transforms/IPO/CMakeLists.txt index 90c1c33e6dc..070ecfdc143 100644 --- a/lib/Transforms/IPO/CMakeLists.txt +++ b/lib/Transforms/IPO/CMakeLists.txt @@ -20,6 +20,7 @@ add_llvm_library(LLVMipo PruneEH.cpp StripDeadPrototypes.cpp StripSymbols.cpp + VerifyUseListOrder.cpp ) add_dependencies(LLVMipo intrinsics_gen) diff --git a/lib/Transforms/IPO/IPO.cpp b/lib/Transforms/IPO/IPO.cpp index b4d31d8d6fc..5dce2d6b407 100644 --- a/lib/Transforms/IPO/IPO.cpp +++ b/lib/Transforms/IPO/IPO.cpp @@ -44,6 +44,7 @@ void llvm::initializeIPO(PassRegistry &Registry) { initializeStripDebugDeclarePass(Registry); initializeStripDeadDebugInfoPass(Registry); initializeStripNonDebugSymbolsPass(Registry); + initializeVerifyUseListOrderPass(Registry); initializeBarrierNoopPass(Registry); } diff --git a/lib/Transforms/IPO/VerifyUseListOrder.cpp b/lib/Transforms/IPO/VerifyUseListOrder.cpp new file mode 100644 index 00000000000..a48f6c78202 --- /dev/null +++ b/lib/Transforms/IPO/VerifyUseListOrder.cpp @@ -0,0 +1,61 @@ +//===- VerifyUseListOrder.cpp - Use List Order Verifier ---------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Pass to verify use-list order doesn't change after serialization. +// +// Despite it being a verifier, this pass *does* transform the module, since it +// shuffles the use-list of every value. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Transforms/IPO.h" +#include "llvm/IR/UseListOrder.h" +#include "llvm/Pass.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/ErrorHandling.h" + +using namespace llvm; + +#define DEBUG_TYPE "use-list-order" + +namespace { +class VerifyUseListOrder : public ModulePass { +public: + static char ID; + VerifyUseListOrder(); + bool runOnModule(Module &M) override; +}; +} // end anonymous namespace + +char VerifyUseListOrder::ID = 0; +INITIALIZE_PASS(VerifyUseListOrder, "verify-use-list-order", + "Verify Use List Order", false, false) +VerifyUseListOrder::VerifyUseListOrder() : ModulePass(ID) { + initializeVerifyUseListOrderPass(*PassRegistry::getPassRegistry()); +} + +bool VerifyUseListOrder::runOnModule(Module &M) { + DEBUG(dbgs() << "*** verify-use-list-order ***\n"); + if (!shouldPreserveBitcodeUseListOrder()) { + // Can't verify if order isn't preserved. + DEBUG(dbgs() << "warning: cannot verify bitcode; " + "try -preserve-bc-use-list-order\n"); + return false; + } + + shuffleUseLists(M); + if (!verifyBitcodeUseListOrder(M)) + report_fatal_error("bitcode use-list order changed"); + + return true; +} + +ModulePass *llvm::createVerifyUseListOrderPass() { + return new VerifyUseListOrder; +} diff --git a/test/Bitcode/use-list-order.ll b/test/Bitcode/use-list-order.ll new file mode 100644 index 00000000000..6d87dedee51 --- /dev/null +++ b/test/Bitcode/use-list-order.ll @@ -0,0 +1,83 @@ +; RUN: opt -S < %s -preserve-bc-use-list-order -verify-use-list-order +; XFAIL: * + +@a = global [4 x i1] [i1 0, i1 1, i1 0, i1 1] +@b = alias i1* getelementptr ([4 x i1]* @a, i64 0, i64 2) + +define i64 @f(i64 %f) { +entry: + %sum = add i64 %f, 0 + ret i64 %sum +} + +define i64 @g(i64 %g) { +entry: + %sum = add i64 %g, 0 + ret i64 %sum +} + +define i64 @h(i64 %h) { +entry: + %sum = add i64 %h, 0 + ret i64 %sum +} + +define i64 @i(i64 %i) { +entry: + %sum = add i64 %i, 1 + ret i64 %sum +} + +define i64 @j(i64 %j) { +entry: + %sum = add i64 %j, 1 + ret i64 %sum +} + +define i64 @k(i64 %k) { +entry: + %sum = add i64 %k, 1 + ret i64 %sum +} + +define i64 @l(i64 %l) { +entry: + %sum = add i64 %l, 1 + ret i64 %sum +} + +define i1 @loadb() { +entry: + %b = load i1* @b + ret i1 %b +} + +define i1 @loada() { +entry: + %a = load i1* getelementptr ([4 x i1]* @a, i64 0, i64 2) + ret i1 %a +} + +define i32 @f32(i32 %a, i32 %b, i32 %c, i32 %d) { +entry: + br label %first + +second: + %eh = mul i32 %e, %h + %sum = add i32 %eh, %ef + br label %exit + +exit: + %product = phi i32 [%ef, %first], [%sum, %second] + ret i32 %product + +first: + %e = add i32 %a, 7 + %f = add i32 %b, 7 + %g = add i32 %c, 8 + %h = add i32 %d, 8 + %ef = mul i32 %e, %f + %gh = mul i32 %g, %h + %gotosecond = icmp slt i32 %gh, -9 + br i1 %gotosecond, label %second, label %exit +}