Skip to content

Commit c6bb413

Browse files
Use range_compatible_p in check_operands_p.
Instead of directly checking type precision, check_operands_p should invoke range_compatible_p to keep the range checking centralized. * gimple-range-fold.h (range_compatible_p): Relocate. * value-range.h (range_compatible_p): Here. * range-op-mixed.h (operand_equal::operand_check_p): Call range_compatible_p rather than comparing precision. (operand_not_equal::operand_check_p): Ditto. (operand_not_lt::operand_check_p): Ditto. (operand_not_le::operand_check_p): Ditto. (operand_not_gt::operand_check_p): Ditto. (operand_not_ge::operand_check_p): Ditto. (operand_plus::operand_check_p): Ditto. (operand_abs::operand_check_p): Ditto. (operand_minus::operand_check_p): Ditto. (operand_negate::operand_check_p): Ditto. (operand_mult::operand_check_p): Ditto. (operand_bitwise_not::operand_check_p): Ditto. (operand_bitwise_xor::operand_check_p): Ditto. (operand_bitwise_and::operand_check_p): Ditto. (operand_bitwise_or::operand_check_p): Ditto. (operand_min::operand_check_p): Ditto. (operand_max::operand_check_p): Ditto. * range-op.cc (operand_lshift::operand_check_p): Ditto. (operand_rshift::operand_check_p): Ditto. (operand_logical_and::operand_check_p): Ditto. (operand_logical_or::operand_check_p): Ditto. (operand_logical_not::operand_check_p): Ditto.
1 parent b8edb81 commit c6bb413

File tree

4 files changed

+33
-45
lines changed

4 files changed

+33
-45
lines changed

gcc/gimple-range-fold.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,6 @@ gimple_range_ssa_p (tree exp)
8989
return NULL_TREE;
9090
}
9191

92-
// Return true if TYPE1 and TYPE2 are compatible range types.
93-
94-
inline bool
95-
range_compatible_p (tree type1, tree type2)
96-
{
97-
// types_compatible_p requires conversion in both directions to be useless.
98-
// GIMPLE only requires a cast one way in order to be compatible.
99-
// Ranges really only need the sign and precision to be the same.
100-
return (TYPE_PRECISION (type1) == TYPE_PRECISION (type2)
101-
&& TYPE_SIGN (type1) == TYPE_SIGN (type2));
102-
}
103-
10492
// Source of all operands for fold_using_range and gori_compute.
10593
// It abstracts out the source of an operand so it can come from a stmt or
10694
// and edge or anywhere a derived class of fur_source wants.

gcc/range-op-mixed.h

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class operator_equal : public range_operator
140140
const irange &rh) const final override;
141141
// Check op1 and op2 for compatibility.
142142
bool operand_check_p (tree, tree t1, tree t2) const final override
143-
{ return TYPE_PRECISION (t1) == TYPE_PRECISION (t2); }
143+
{ return range_compatible_p (t1, t2); }
144144
};
145145

146146
class operator_not_equal : public range_operator
@@ -179,7 +179,7 @@ class operator_not_equal : public range_operator
179179
const irange &rh) const final override;
180180
// Check op1 and op2 for compatibility.
181181
bool operand_check_p (tree, tree t1, tree t2) const final override
182-
{ return TYPE_PRECISION (t1) == TYPE_PRECISION (t2); }
182+
{ return range_compatible_p (t1, t2); }
183183
};
184184

185185
class operator_lt : public range_operator
@@ -215,7 +215,7 @@ class operator_lt : public range_operator
215215
const irange &rh) const final override;
216216
// Check op1 and op2 for compatibility.
217217
bool operand_check_p (tree, tree t1, tree t2) const final override
218-
{ return TYPE_PRECISION (t1) == TYPE_PRECISION (t2); }
218+
{ return range_compatible_p (t1, t2); }
219219
};
220220

221221
class operator_le : public range_operator
@@ -254,7 +254,7 @@ class operator_le : public range_operator
254254
const irange &rh) const final override;
255255
// Check op1 and op2 for compatibility.
256256
bool operand_check_p (tree, tree t1, tree t2) const final override
257-
{ return TYPE_PRECISION (t1) == TYPE_PRECISION (t2); }
257+
{ return range_compatible_p (t1, t2); }
258258
};
259259

260260
class operator_gt : public range_operator
@@ -292,7 +292,7 @@ class operator_gt : public range_operator
292292
const irange &rh) const final override;
293293
// Check op1 and op2 for compatibility.
294294
bool operand_check_p (tree, tree t1, tree t2) const final override
295-
{ return TYPE_PRECISION (t1) == TYPE_PRECISION (t2); }
295+
{ return range_compatible_p (t1, t2); }
296296
};
297297

298298
class operator_ge : public range_operator
@@ -331,7 +331,7 @@ class operator_ge : public range_operator
331331
const irange &rh) const final override;
332332
// Check op1 and op2 for compatibility.
333333
bool operand_check_p (tree, tree t1, tree t2) const final override
334-
{ return TYPE_PRECISION (t1) == TYPE_PRECISION (t2); }
334+
{ return range_compatible_p (t1, t2); }
335335
};
336336

337337
class operator_identity : public range_operator
@@ -429,8 +429,7 @@ class operator_plus : public range_operator
429429
relation_trio = TRIO_VARYING) const;
430430
// Check compatibility of all operands.
431431
bool operand_check_p (tree t1, tree t2, tree t3) const final override
432-
{ return (TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
433-
&& TYPE_PRECISION (t1) == TYPE_PRECISION (t3)); }
432+
{ return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
434433
private:
435434
void wi_fold (irange &r, tree type, const wide_int &lh_lb,
436435
const wide_int &lh_ub, const wide_int &rh_lb,
@@ -459,7 +458,7 @@ class operator_abs : public range_operator
459458
const irange &rh) const final override;
460459
// Check compatibility of LHS and op1.
461460
bool operand_check_p (tree t1, tree t2, tree) const final override
462-
{ return TYPE_PRECISION (t1) == TYPE_PRECISION (t2); }
461+
{ return range_compatible_p (t1, t2); }
463462
private:
464463
void wi_fold (irange &r, tree type, const wide_int &lh_lb,
465464
const wide_int &lh_ub, const wide_int &rh_lb,
@@ -503,8 +502,7 @@ class operator_minus : public range_operator
503502
relation_trio = TRIO_VARYING) const;
504503
// Check compatibility of all operands.
505504
bool operand_check_p (tree t1, tree t2, tree t3) const final override
506-
{ return (TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
507-
&& TYPE_PRECISION (t1) == TYPE_PRECISION (t3)); }
505+
{ return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
508506
private:
509507
void wi_fold (irange &r, tree type, const wide_int &lh_lb,
510508
const wide_int &lh_ub, const wide_int &rh_lb,
@@ -535,7 +533,7 @@ class operator_negate : public range_operator
535533
relation_trio rel = TRIO_VARYING) const final override;
536534
// Check compatibility of LHS and op1.
537535
bool operand_check_p (tree t1, tree t2, tree) const final override
538-
{ return TYPE_PRECISION (t1) == TYPE_PRECISION (t2); }
536+
{ return range_compatible_p (t1, t2); }
539537
};
540538

541539

@@ -589,8 +587,7 @@ class operator_mult : public cross_product_operator
589587
relation_trio = TRIO_VARYING) const;
590588
// Check compatibility of all operands.
591589
bool operand_check_p (tree t1, tree t2, tree t3) const final override
592-
{ return (TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
593-
&& TYPE_PRECISION (t1) == TYPE_PRECISION (t3)); }
590+
{ return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
594591
};
595592

596593
class operator_addr_expr : public range_operator
@@ -621,8 +618,7 @@ class operator_bitwise_not : public range_operator
621618
const irange &rh) const final override;
622619
// Check compatibility of all operands.
623620
bool operand_check_p (tree t1, tree t2, tree t3) const final override
624-
{ return (TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
625-
&& TYPE_PRECISION (t1) == TYPE_PRECISION (t3)); }
621+
{ return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
626622
};
627623

628624
class operator_bitwise_xor : public range_operator
@@ -645,8 +641,7 @@ class operator_bitwise_xor : public range_operator
645641
const irange &rh) const final override;
646642
// Check compatibility of all operands.
647643
bool operand_check_p (tree t1, tree t2, tree t3) const final override
648-
{ return (TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
649-
&& TYPE_PRECISION (t1) == TYPE_PRECISION (t3)); }
644+
{ return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
650645
private:
651646
void wi_fold (irange &r, tree type, const wide_int &lh_lb,
652647
const wide_int &lh_ub, const wide_int &rh_lb,
@@ -672,8 +667,7 @@ class operator_bitwise_and : public range_operator
672667
const irange &rh) const override;
673668
// Check compatibility of all operands.
674669
bool operand_check_p (tree t1, tree t2, tree t3) const final override
675-
{ return (TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
676-
&& TYPE_PRECISION (t1) == TYPE_PRECISION (t3)); }
670+
{ return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
677671
protected:
678672
void wi_fold (irange &r, tree type, const wide_int &lh_lb,
679673
const wide_int &lh_ub, const wide_int &rh_lb,
@@ -698,8 +692,7 @@ class operator_bitwise_or : public range_operator
698692
const irange &rh) const override;
699693
// Check compatibility of all operands.
700694
bool operand_check_p (tree t1, tree t2, tree t3) const final override
701-
{ return (TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
702-
&& TYPE_PRECISION (t1) == TYPE_PRECISION (t3)); }
695+
{ return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
703696
protected:
704697
void wi_fold (irange &r, tree type, const wide_int &lh_lb,
705698
const wide_int &lh_ub, const wide_int &rh_lb,
@@ -713,8 +706,7 @@ class operator_min : public range_operator
713706
const irange &rh) const override;
714707
// Check compatibility of all operands.
715708
bool operand_check_p (tree t1, tree t2, tree t3) const final override
716-
{ return (TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
717-
&& TYPE_PRECISION (t1) == TYPE_PRECISION (t3)); }
709+
{ return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
718710
protected:
719711
void wi_fold (irange &r, tree type, const wide_int &lh_lb,
720712
const wide_int &lh_ub, const wide_int &rh_lb,
@@ -728,8 +720,7 @@ class operator_max : public range_operator
728720
const irange &rh) const override;
729721
// Check compatibility of all operands.
730722
bool operand_check_p (tree t1, tree t2, tree t3) const final override
731-
{ return (TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
732-
&& TYPE_PRECISION (t1) == TYPE_PRECISION (t3)); }
723+
{ return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
733724
protected:
734725
void wi_fold (irange &r, tree type, const wide_int &lh_lb,
735726
const wide_int &lh_ub, const wide_int &rh_lb,

gcc/range-op.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,7 +2493,7 @@ class operator_lshift : public cross_product_operator
24932493
{ update_known_bitmask (r, LSHIFT_EXPR, lh, rh); }
24942494
// Check compatibility of LHS and op1.
24952495
bool operand_check_p (tree t1, tree t2, tree) const final override
2496-
{ return TYPE_PRECISION (t1) == TYPE_PRECISION (t2); }
2496+
{ return range_compatible_p (t1, t2); }
24972497
} op_lshift;
24982498

24992499
class operator_rshift : public cross_product_operator
@@ -2525,7 +2525,7 @@ class operator_rshift : public cross_product_operator
25252525
{ update_known_bitmask (r, RSHIFT_EXPR, lh, rh); }
25262526
// Check compatibility of LHS and op1.
25272527
bool operand_check_p (tree t1, tree t2, tree) const final override
2528-
{ return TYPE_PRECISION (t1) == TYPE_PRECISION (t2); }
2528+
{ return range_compatible_p (t1, t2); }
25292529
} op_rshift;
25302530

25312531

@@ -3103,8 +3103,7 @@ class operator_logical_and : public range_operator
31033103
relation_trio rel = TRIO_VARYING) const;
31043104
// Check compatibility of all operands.
31053105
bool operand_check_p (tree t1, tree t2, tree t3) const final override
3106-
{ return (TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
3107-
&& TYPE_PRECISION (t1) == TYPE_PRECISION (t3)); }
3106+
{ return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
31083107
} op_logical_and;
31093108

31103109
bool
@@ -3608,8 +3607,7 @@ class operator_logical_or : public range_operator
36083607
relation_trio rel = TRIO_VARYING) const;
36093608
// Check compatibility of all operands.
36103609
bool operand_check_p (tree t1, tree t2, tree t3) const final override
3611-
{ return (TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
3612-
&& TYPE_PRECISION (t1) == TYPE_PRECISION (t3)); }
3610+
{ return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); }
36133611
} op_logical_or;
36143612

36153613
bool
@@ -4038,7 +4036,7 @@ class operator_logical_not : public range_operator
40384036
relation_trio rel = TRIO_VARYING) const;
40394037
// Check compatibility of LHS and op1.
40404038
bool operand_check_p (tree t1, tree t2, tree) const final override
4041-
{ return TYPE_PRECISION (t1) == TYPE_PRECISION (t2); }
4039+
{ return range_compatible_p (t1, t2); }
40424040
} op_logical_not;
40434041

40444042
// Folding a logical NOT, oddly enough, involves doing nothing on the

gcc/value-range.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,4 +1550,15 @@ void frange_arithmetic (enum tree_code, tree, REAL_VALUE_TYPE &,
15501550
const REAL_VALUE_TYPE &, const REAL_VALUE_TYPE &,
15511551
const REAL_VALUE_TYPE &);
15521552

1553+
// Return true if TYPE1 and TYPE2 are compatible range types.
1554+
1555+
inline bool
1556+
range_compatible_p (tree type1, tree type2)
1557+
{
1558+
// types_compatible_p requires conversion in both directions to be useless.
1559+
// GIMPLE only requires a cast one way in order to be compatible.
1560+
// Ranges really only need the sign and precision to be the same.
1561+
return (TYPE_PRECISION (type1) == TYPE_PRECISION (type2)
1562+
&& TYPE_SIGN (type1) == TYPE_SIGN (type2));
1563+
}
15531564
#endif // GCC_VALUE_RANGE_H

0 commit comments

Comments
 (0)