From 5c89080469d28442a375c76b9b14331cf841f6a8 Mon Sep 17 00:00:00 2001 From: Ilia Filippov Date: Fri, 14 Jun 2013 16:38:54 +0400 Subject: [PATCH] changes in function LLVMFlattenInsertChain --- llvmutil.cpp | 17 ++++++++++------- llvmutil.h | 7 +++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/llvmutil.cpp b/llvmutil.cpp index 1f157399..ebb60f40 100644 --- a/llvmutil.cpp +++ b/llvmutil.cpp @@ -600,9 +600,9 @@ lGetIntValue(llvm::Value *offset) { } -llvm::Value * +llvm::Value * LLVMFlattenInsertChain(llvm::Value *inst, int vectorWidth, - bool compare, bool undef) { + bool compare, bool undef) { llvm::Value ** elements = new llvm::Value*[vectorWidth]; for (int i = 0; i < vectorWidth; ++i) { elements[i] = NULL; @@ -631,7 +631,7 @@ LLVMFlattenInsertChain(llvm::Value *inst, int vectorWidth, if (llvm::isa(insertBase)) { break; } - + if (llvm::isa(insertBase) || llvm::isa(insertBase)) { llvm::Constant *cv = llvm::dyn_cast(insertBase); @@ -648,17 +648,20 @@ LLVMFlattenInsertChain(llvm::Value *inst, int vectorWidth, // They are not equal to each other so we should return NULL if compare // and first element if we have it. Assert(compare == true || elements[0] != NULL); - if (compare) + if (compare) { return NULL; - else + } + else { return elements[0]; + } } // TODO: Also, should we handle some other values like // ConstantDataVectors. } - if (compare == false) - //We simply want first element + if (compare == false) { + //We simply want first element return elements[0]; + } int null_number = 0; int NonNull = 0; diff --git a/llvmutil.h b/llvmutil.h index 95437c3f..d6c5ede0 100644 --- a/llvmutil.h +++ b/llvmutil.h @@ -270,10 +270,9 @@ extern bool LLVMExtractVectorInts(llvm::Value *v, int64_t ret[], int *nElts); %broadcast.1 = shufflevector <4 x i32> %smear.0, <4 x i32> undef, <4 x i32> zeroinitializer Function returns: - First element of array if compare is false, - NonNull element only if all elements are equal or NULL if compare is true, - NonNull element only if all elements are equal if compare is true and undef is false, - NULL if all elements are NULLs + Compare all elements and return one of them if all are equal, otherwise NULL. + If compare argument is false, don't do compare and return first element instead. + If undef argument is true, ignore undef elements (but all undef yields NULL anyway). */ extern llvm::Value * LLVMFlattenInsertChain (llvm::Value *inst, int vectorWidth, bool compare = true, bool undef = true);