Skip to content

Commit 774ad67

Browse files
Implement operator_pointer_diff::fold_range
prange has no default fold_range processing like irange does, so each pointer specific operator needs to implement its own fold routine. PR tree-optimization/117222 gcc/ * range-op-ptr.cc (operator_pointer_diff::fold_range): New. (operator_pointer_diff::op1_op2_relation_effect): Remove irange variant. (operator_pointer_diff::update_bitmask): Likewise. gcc/testsuite * g++.dg/pr117222.C: New.
1 parent 4b0f238 commit 774ad67

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

gcc/range-op-ptr.cc

+20-17
Original file line numberDiff line numberDiff line change
@@ -567,25 +567,38 @@ pointer_or_operator::wi_fold (irange &r, tree type,
567567

568568
class operator_pointer_diff : public range_operator
569569
{
570+
using range_operator::fold_range;
570571
using range_operator::update_bitmask;
571572
using range_operator::op1_op2_relation_effect;
572-
virtual bool op1_op2_relation_effect (irange &lhs_range,
573-
tree type,
574-
const irange &op1_range,
575-
const irange &op2_range,
576-
relation_kind rel) const;
573+
virtual bool fold_range (irange &r, tree type,
574+
const prange &op1,
575+
const prange &op2,
576+
relation_trio trio) const final override;
577577
virtual bool op1_op2_relation_effect (irange &lhs_range,
578578
tree type,
579579
const prange &op1_range,
580580
const prange &op2_range,
581581
relation_kind rel) const final override;
582-
void update_bitmask (irange &r, const irange &lh, const irange &rh) const
583-
{ update_known_bitmask (r, POINTER_DIFF_EXPR, lh, rh); }
584582
void update_bitmask (irange &r,
585583
const prange &lh, const prange &rh) const final override
586584
{ update_known_bitmask (r, POINTER_DIFF_EXPR, lh, rh); }
587585
} op_pointer_diff;
588586

587+
bool
588+
operator_pointer_diff::fold_range (irange &r, tree type,
589+
const prange &op1,
590+
const prange &op2,
591+
relation_trio trio) const
592+
{
593+
gcc_checking_assert (r.supports_type_p (type));
594+
595+
r.set_varying (type);
596+
relation_kind rel = trio.op1_op2 ();
597+
op1_op2_relation_effect (r, type, op1, op2, rel);
598+
update_bitmask (r, op1, op2);
599+
return true;
600+
}
601+
589602
bool
590603
operator_pointer_diff::op1_op2_relation_effect (irange &lhs_range, tree type,
591604
const prange &op1_range,
@@ -602,16 +615,6 @@ operator_pointer_diff::op1_op2_relation_effect (irange &lhs_range, tree type,
602615
return minus_op1_op2_relation_effect (lhs_range, type, op1, op2, rel);
603616
}
604617

605-
bool
606-
operator_pointer_diff::op1_op2_relation_effect (irange &lhs_range, tree type,
607-
const irange &op1_range,
608-
const irange &op2_range,
609-
relation_kind rel) const
610-
{
611-
return minus_op1_op2_relation_effect (lhs_range, type, op1_range, op2_range,
612-
rel);
613-
}
614-
615618
bool
616619
operator_identity::fold_range (prange &r, tree type ATTRIBUTE_UNUSED,
617620
const prange &lh ATTRIBUTE_UNUSED,

gcc/testsuite/g++.dg/pr117222.C

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// { dg-do compile }
2+
// { dg-require-effective-target c++11 }
3+
// { dg-options "-O3 -fdump-tree-evrp" }
4+
5+
#include <vector>
6+
int main()
7+
{
8+
std::vector<int> c {1,2,3,0};
9+
while(c.size() > 0 && c.back() == 0)
10+
{
11+
auto sz = c.size() -1;
12+
c.resize(sz);
13+
}
14+
return 0;
15+
}
16+
/* { dg-final { scan-tree-dump "Global Exported.*\[-INF, -1\]\[1, +INF\]" "evrp" } } */

0 commit comments

Comments
 (0)