diff --git a/cbackend.cpp b/cbackend.cpp index 1c9626b5..51890d7f 100644 --- a/cbackend.cpp +++ b/cbackend.cpp @@ -69,6 +69,7 @@ #include "llvm/IR/CallSite.h" #include "llvm/IR/CFG.h" #include "llvm/IR/GetElementPtrTypeIterator.h" + #include "llvm/Support/FileSystem.h" #else #include "llvm/Analysis/Verifier.h" #include @@ -1770,7 +1771,7 @@ std::string CWriter::GetValueName(const llvm::Value *Operand) { // Resolve potential alias. if (const llvm::GlobalAlias *GA = llvm::dyn_cast(Operand)) { #if defined(LLVM_3_5) - if (const llvm::Value *V = GA->getAliasedGlobal()) + if (const llvm::Value *V = GA->getAliasee()) #else if (const llvm::Value *V = GA->resolveAliasedGlobal(false)) #endif diff --git a/llvmutil.cpp b/llvmutil.cpp index 5707bbc9..c9e156ce 100644 --- a/llvmutil.cpp +++ b/llvmutil.cpp @@ -1569,6 +1569,8 @@ lExtractFirstVectorElement(llvm::Value *v, phiMap); llvm::Value *v1 = lExtractFirstVectorElement(bop->getOperand(1), phiMap); + Assert(v0 != NULL); + Assert(v1 != NULL); // Note that the new binary operator is inserted immediately before // the previous vector one return llvm::BinaryOperator::Create(bop->getOpcode(), v0, v1, @@ -1615,10 +1617,22 @@ lExtractFirstVectorElement(llvm::Value *v, return scalarPhi; } + // We should consider "shuffle" case and "insertElement" case separately. + // For example we can have shuffle(mul, undef, zero) but function + // "LLVMFlattenInsertChain" can handle only case shuffle(insertElement, undef, zero). + // Also if we have insertElement under shuffle we will handle it the next call of + // "lExtractFirstVectorElement" function. + if (llvm::isa(v)) { + llvm::ShuffleVectorInst *shuf = llvm::dyn_cast(v); + llvm::Value *indices = shuf->getOperand(2); + if (llvm::isa(indices)) { + return lExtractFirstVectorElement(shuf->getOperand(0), phiMap); + } + } + // If we have a chain of insertelement instructions, then we can just // flatten them out and grab the value for the first one. - if (llvm::isa(v) || - llvm::isa(v)) { + if (llvm::isa(v)) { return LLVMFlattenInsertChain(v, vt->getNumElements(), false); }