Value *generateTwoRangeCond(CallInst *CI, const LibFunc &Func);
Value *generateCondForPow(CallInst *CI, const LibFunc &Func);
+ // Create an OR of two conditions with given Arg and Arg2.
+ Value *createOrCond(CallInst *CI, Value *Arg, CmpInst::Predicate Cmp,
+ float Val, Value *Arg2, CmpInst::Predicate Cmp2,
+ float Val2) {
+ IRBuilder<> BBBuilder(CI);
+ auto Cond2 = createCond(BBBuilder, Arg2, Cmp2, Val2);
+ auto Cond1 = createCond(BBBuilder, Arg, Cmp, Val);
+ return BBBuilder.CreateOr(Cond1, Cond2);
+ }
+
// Create an OR of two conditions.
Value *createOrCond(CallInst *CI, CmpInst::Predicate Cmp, float Val,
CmpInst::Predicate Cmp2, float Val2) {
- IRBuilder<> BBBuilder(CI);
Value *Arg = CI->getArgOperand(0);
- auto Cond2 = createCond(BBBuilder, Arg, Cmp2, Val2);
- auto Cond1 = createCond(BBBuilder, Arg, Cmp, Val);
- return BBBuilder.CreateOr(Cond1, Cond2);
+ return createOrCond(CI, Arg, Cmp, Val, Arg, Cmp2, Val2);
}
// Create a single condition using IRBuilder.
return BBBuilder.CreateFCmp(Cmp, Arg, V);
}
+ // Create a single condition with given Arg.
+ Value *createCond(CallInst *CI, Value *Arg, CmpInst::Predicate Cmp,
+ float Val) {
+ IRBuilder<> BBBuilder(CI);
+ return createCond(BBBuilder, Arg, Cmp, Val);
+ }
+
// Create a single condition.
Value *createCond(CallInst *CI, CmpInst::Predicate Cmp, float Val) {
- IRBuilder<> BBBuilder(CI);
Value *Arg = CI->getArgOperand(0);
- return createCond(BBBuilder, Arg, Cmp, Val);
+ return createCond(CI, Arg, Cmp, Val);
}
const TargetLibraryInfo &TLI;
Value *Base = CI->getArgOperand(0);
Value *Exp = CI->getArgOperand(1);
- IRBuilder<> BBBuilder(CI);
// Constant Base case.
if (ConstantFP *CF = dyn_cast<ConstantFP>(Base)) {
}
++NumWrappedOneCond;
- Constant *V = ConstantFP::get(CI->getContext(), APFloat(127.0f));
- if (!Exp->getType()->isFloatTy())
- V = ConstantExpr::getFPExtend(V, Exp->getType());
- return BBBuilder.CreateFCmp(CmpInst::FCMP_OGT, Exp, V);
+ return createCond(CI, Exp, CmpInst::FCMP_OGT, 127.0f);
}
// If the Base value coming from an integer type.
}
++NumWrappedTwoCond;
- Constant *V = ConstantFP::get(CI->getContext(), APFloat(UpperV));
- Constant *V0 = ConstantFP::get(CI->getContext(), APFloat(0.0f));
- if (!Exp->getType()->isFloatTy())
- V = ConstantExpr::getFPExtend(V, Exp->getType());
- if (!Base->getType()->isFloatTy())
- V0 = ConstantExpr::getFPExtend(V0, Exp->getType());
-
- Value *Cond = BBBuilder.CreateFCmp(CmpInst::FCMP_OGT, Exp, V);
- Value *Cond0 = BBBuilder.CreateFCmp(CmpInst::FCMP_OLE, Base, V0);
- return BBBuilder.CreateOr(Cond0, Cond);
+ return createOrCond(CI, Base, CmpInst::FCMP_OLE, 0.0f, Exp,
+ CmpInst::FCMP_OGT, UpperV);
}
LLVM_DEBUG(dbgs() << "Not handled pow(): base not from integer convert\n");
return nullptr;