Merge pull request #1393 from kinke/nullArray

Optimize array comparisons against null
This commit is contained in:
David Nadlinger 2016-04-09 23:22:53 +01:00
commit 209b6fc2b0
6 changed files with 67 additions and 42 deletions

View file

@ -1451,7 +1451,7 @@ void AppendFunctionToLLVMGlobalCtorsDtors(llvm::Function *func,
////////////////////////////////////////////////////////////////////////////////
void tokToIcmpPred(TOK op, bool isUnsigned, llvm::ICmpInst::Predicate *outPred,
void tokToICmpPred(TOK op, bool isUnsigned, llvm::ICmpInst::Predicate *outPred,
llvm::Value **outConst) {
switch (op) {
case TOKlt:
@ -1487,6 +1487,35 @@ void tokToIcmpPred(TOK op, bool isUnsigned, llvm::ICmpInst::Predicate *outPred,
}
}
////////////////////////////////////////////////////////////////////////////////
llvm::ICmpInst::Predicate eqTokToICmpPred(TOK op, bool invert) {
assert(op == TOKequal || op == TOKnotequal || op == TOKidentity ||
op == TOKnotidentity);
bool isEquality = (op == TOKequal || op == TOKidentity);
if (invert)
isEquality = !isEquality;
return (isEquality ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE);
}
////////////////////////////////////////////////////////////////////////////////
LLValue *createIPairCmp(TOK op, LLValue *lhs1, LLValue *lhs2, LLValue *rhs1,
LLValue *rhs2) {
const auto predicate = eqTokToICmpPred(op);
LLValue *r1 = gIR->ir->CreateICmp(predicate, lhs1, rhs1);
LLValue *r2 = gIR->ir->CreateICmp(predicate, lhs2, rhs2);
LLValue *r =
(predicate == llvm::ICmpInst::ICMP_EQ ? gIR->ir->CreateAnd(r1, r2)
: gIR->ir->CreateOr(r1, r2));
return r;
}
///////////////////////////////////////////////////////////////////////////////
DValue *DtoSymbolAddress(Loc &loc, Type *type, Declaration *decl) {
IF_LOG Logger::println("DtoSymbolAddress ('%s' of type '%s')",