aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gimple-range-op.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc
index 527893f..2662319 100644
--- a/gcc/gimple-range-op.cc
+++ b/gcc/gimple-range-op.cc
@@ -342,6 +342,38 @@ public:
}
} op_cfn_signbit;
+// Implement range operator for CFN_BUILT_IN_COPYSIGN
+class cfn_copysign : public range_operator_float
+{
+public:
+ using range_operator_float::fold_range;
+ virtual bool fold_range (frange &r, tree type, const frange &lh,
+ const frange &rh, relation_kind) const override
+ {
+ frange neg;
+ range_op_handler abs_op (ABS_EXPR, type);
+ range_op_handler neg_op (NEGATE_EXPR, type);
+ if (!abs_op || !abs_op.fold_range (r, type, lh, frange (type)))
+ return false;
+ if (!neg_op || !neg_op.fold_range (neg, type, r, frange (type)))
+ return false;
+
+ bool signbit;
+ if (rh.signbit_p (signbit))
+ {
+ // If the sign is negative, flip the result from ABS,
+ // otherwise leave things positive.
+ if (signbit)
+ r = neg;
+ }
+ else
+ // If the sign is unknown, keep the positive and negative
+ // alternatives.
+ r.union_ (neg);
+ return true;
+ }
+} op_cfn_copysign;
+
// Implement range operator for CFN_BUILT_IN_TOUPPER and CFN_BUILT_IN_TOLOWER.
class cfn_toupper_tolower : public range_operator
{
@@ -762,6 +794,13 @@ gimple_range_op_handler::maybe_builtin_call ()
m_valid = true;
break;
+ CASE_CFN_COPYSIGN_ALL:
+ m_op1 = gimple_call_arg (call, 0);
+ m_op2 = gimple_call_arg (call, 1);
+ m_float = &op_cfn_copysign;
+ m_valid = true;
+ break;
+
case CFN_BUILT_IN_TOUPPER:
case CFN_BUILT_IN_TOLOWER:
// Only proceed If the argument is compatible with the LHS.