From a48bc53cad55452f534f7b5dad06a0d4c4607cc6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 29 Sep 2005 06:17:27 +0000 Subject: [PATCH] Fold isascii into a simple comparison. This speeds up 197.parser by 7.4%, bringing the LLC time down to the CBE time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23521 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/SimplifyLibCalls.cpp | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/Transforms/IPO/SimplifyLibCalls.cpp b/lib/Transforms/IPO/SimplifyLibCalls.cpp index c3075f4eaa1..58aac20b70a 100644 --- a/lib/Transforms/IPO/SimplifyLibCalls.cpp +++ b/lib/Transforms/IPO/SimplifyLibCalls.cpp @@ -1745,6 +1745,32 @@ public: } } isdigitOptimizer; +struct isasciiOptimization : public LibCallOptimization { +public: + isasciiOptimization() + : LibCallOptimization("isascii", "Number of 'isascii' calls simplified") {} + + virtual bool ValidateCalledFunction(const Function *F, SimplifyLibCalls &SLC){ + return F->arg_size() == 1 && F->arg_begin()->getType()->isInteger() && + F->getReturnType()->isInteger(); + } + + /// @brief Perform the isascii optimization. + virtual bool OptimizeCall(CallInst *CI, SimplifyLibCalls &SLC) { + // isascii(c) -> (unsigned)c < 128 + Value *V = CI->getOperand(1); + if (V->getType()->isSigned()) + V = new CastInst(V, V->getType()->getUnsignedVersion(), V->getName(), CI); + Value *Cmp = BinaryOperator::createSetLT(V, ConstantUInt::get(V->getType(), + 128), + V->getName()+".isascii", CI); + if (Cmp->getType() != CI->getType()) + Cmp = new CastInst(Cmp, CI->getType(), Cmp->getName(), CI); + CI->replaceAllUsesWith(Cmp); + CI->eraseFromParent(); + return true; + } +} isasciiOptimizer; /// This LibCallOptimization will simplify calls to the "toascii" library