mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-25 16:24:23 +00:00
minor code cleanups, allow constant folding sinf/cosf.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48961 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -569,7 +569,8 @@ llvm::canConstantFoldCallTo(const Function *F) {
|
|||||||
if (Len == 3)
|
if (Len == 3)
|
||||||
return !strcmp(Str, "sin");
|
return !strcmp(Str, "sin");
|
||||||
if (Len == 4)
|
if (Len == 4)
|
||||||
return !strcmp(Str, "sinh") || !strcmp(Str, "sqrt");
|
return !strcmp(Str, "sinh") || !strcmp(Str, "sqrt") ||
|
||||||
|
!strcmp(Str, "sinf");
|
||||||
if (Len == 5)
|
if (Len == 5)
|
||||||
return !strcmp(Str, "sqrtf");
|
return !strcmp(Str, "sqrtf");
|
||||||
return false;
|
return false;
|
||||||
@ -586,16 +587,17 @@ static Constant *ConstantFoldFP(double (*NativeFP)(double), double V,
|
|||||||
const Type *Ty) {
|
const Type *Ty) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
V = NativeFP(V);
|
V = NativeFP(V);
|
||||||
if (errno == 0) {
|
if (errno != 0) {
|
||||||
if (Ty==Type::FloatTy)
|
errno = 0;
|
||||||
return ConstantFP::get(Ty, APFloat((float)V));
|
return 0;
|
||||||
else if (Ty==Type::DoubleTy)
|
|
||||||
return ConstantFP::get(Ty, APFloat(V));
|
|
||||||
else
|
|
||||||
assert(0);
|
|
||||||
}
|
}
|
||||||
errno = 0;
|
|
||||||
return 0;
|
if (Ty == Type::FloatTy)
|
||||||
|
return ConstantFP::get(Ty, APFloat((float)V));
|
||||||
|
|
||||||
|
if (Ty == Type::DoubleTy)
|
||||||
|
return ConstantFP::get(Ty, APFloat(V));
|
||||||
|
assert(0 && "Can only constant fold float/double");
|
||||||
}
|
}
|
||||||
|
|
||||||
static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double),
|
static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double),
|
||||||
@ -603,16 +605,16 @@ static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double),
|
|||||||
const Type *Ty) {
|
const Type *Ty) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
V = NativeFP(V, W);
|
V = NativeFP(V, W);
|
||||||
if (errno == 0) {
|
if (errno != 0) {
|
||||||
if (Ty==Type::FloatTy)
|
errno = 0;
|
||||||
return ConstantFP::get(Ty, APFloat((float)V));
|
return 0;
|
||||||
else if (Ty==Type::DoubleTy)
|
|
||||||
return ConstantFP::get(Ty, APFloat(V));
|
|
||||||
else
|
|
||||||
assert(0);
|
|
||||||
}
|
}
|
||||||
errno = 0;
|
|
||||||
return 0;
|
if (Ty == Type::FloatTy)
|
||||||
|
return ConstantFP::get(Ty, APFloat((float)V));
|
||||||
|
if (Ty == Type::DoubleTy)
|
||||||
|
return ConstantFP::get(Ty, APFloat(V));
|
||||||
|
assert(0 && "Can only constant fold float/double");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ConstantFoldCall - Attempt to constant fold a call to the specified function
|
/// ConstantFoldCall - Attempt to constant fold a call to the specified function
|
||||||
@ -653,6 +655,8 @@ llvm::ConstantFoldCall(Function *F,
|
|||||||
return ConstantFoldFP(cos, V, Ty);
|
return ConstantFoldFP(cos, V, Ty);
|
||||||
else if (Len == 4 && !strcmp(Str, "cosh"))
|
else if (Len == 4 && !strcmp(Str, "cosh"))
|
||||||
return ConstantFoldFP(cosh, V, Ty);
|
return ConstantFoldFP(cosh, V, Ty);
|
||||||
|
else if (Len == 4 && !strcmp(Str, "cosf"))
|
||||||
|
return ConstantFoldFP(cos, V, Ty);
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
if (Len == 3 && !strcmp(Str, "exp"))
|
if (Len == 3 && !strcmp(Str, "exp"))
|
||||||
@ -675,7 +679,7 @@ llvm::ConstantFoldCall(Function *F,
|
|||||||
return ConstantFoldFP(sqrt, V, Ty);
|
return ConstantFoldFP(sqrt, V, Ty);
|
||||||
else // Undefined
|
else // Undefined
|
||||||
return ConstantFP::get(Ty, Ty==Type::FloatTy ? APFloat(0.0f) :
|
return ConstantFP::get(Ty, Ty==Type::FloatTy ? APFloat(0.0f) :
|
||||||
APFloat(0.0));
|
APFloat(0.0));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
@ -687,6 +691,8 @@ llvm::ConstantFoldCall(Function *F,
|
|||||||
return ConstantFoldFP(sqrt, V, Ty);
|
return ConstantFoldFP(sqrt, V, Ty);
|
||||||
else if (Len == 5 && !strcmp(Str, "sqrtf") && V >= 0)
|
else if (Len == 5 && !strcmp(Str, "sqrtf") && V >= 0)
|
||||||
return ConstantFoldFP(sqrt, V, Ty);
|
return ConstantFoldFP(sqrt, V, Ty);
|
||||||
|
else if (Len == 4 && !strcmp(Str, "sinf"))
|
||||||
|
return ConstantFoldFP(sin, V, Ty);
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
if (Len == 3 && !strcmp(Str, "tan"))
|
if (Len == 3 && !strcmp(Str, "tan"))
|
||||||
|
Reference in New Issue
Block a user