Skip to content

Commit

Permalink
Implement operator_pointer_diff::fold_range
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andrewwmacleod committed Oct 23, 2024
1 parent 4b0f238 commit 774ad67
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
37 changes: 20 additions & 17 deletions gcc/range-op-ptr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -567,25 +567,38 @@ pointer_or_operator::wi_fold (irange &r, tree type,

class operator_pointer_diff : public range_operator
{
using range_operator::fold_range;
using range_operator::update_bitmask;
using range_operator::op1_op2_relation_effect;
virtual bool op1_op2_relation_effect (irange &lhs_range,
tree type,
const irange &op1_range,
const irange &op2_range,
relation_kind rel) const;
virtual bool fold_range (irange &r, tree type,
const prange &op1,
const prange &op2,
relation_trio trio) const final override;
virtual bool op1_op2_relation_effect (irange &lhs_range,
tree type,
const prange &op1_range,
const prange &op2_range,
relation_kind rel) const final override;
void update_bitmask (irange &r, const irange &lh, const irange &rh) const
{ update_known_bitmask (r, POINTER_DIFF_EXPR, lh, rh); }
void update_bitmask (irange &r,
const prange &lh, const prange &rh) const final override
{ update_known_bitmask (r, POINTER_DIFF_EXPR, lh, rh); }
} op_pointer_diff;

bool
operator_pointer_diff::fold_range (irange &r, tree type,
const prange &op1,
const prange &op2,
relation_trio trio) const
{
gcc_checking_assert (r.supports_type_p (type));

r.set_varying (type);
relation_kind rel = trio.op1_op2 ();
op1_op2_relation_effect (r, type, op1, op2, rel);
update_bitmask (r, op1, op2);
return true;
}

bool
operator_pointer_diff::op1_op2_relation_effect (irange &lhs_range, tree type,
const prange &op1_range,
Expand All @@ -602,16 +615,6 @@ operator_pointer_diff::op1_op2_relation_effect (irange &lhs_range, tree type,
return minus_op1_op2_relation_effect (lhs_range, type, op1, op2, rel);
}

bool
operator_pointer_diff::op1_op2_relation_effect (irange &lhs_range, tree type,
const irange &op1_range,
const irange &op2_range,
relation_kind rel) const
{
return minus_op1_op2_relation_effect (lhs_range, type, op1_range, op2_range,
rel);
}

bool
operator_identity::fold_range (prange &r, tree type ATTRIBUTE_UNUSED,
const prange &lh ATTRIBUTE_UNUSED,
Expand Down
16 changes: 16 additions & 0 deletions gcc/testsuite/g++.dg/pr117222.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// { dg-do compile }
// { dg-require-effective-target c++11 }
// { dg-options "-O3 -fdump-tree-evrp" }

#include <vector>
int main()
{
std::vector<int> c {1,2,3,0};
while(c.size() > 0 && c.back() == 0)
{
auto sz = c.size() -1;
c.resize(sz);
}
return 0;
}
/* { dg-final { scan-tree-dump "Global Exported.*\[-INF, -1\]\[1, +INF\]" "evrp" } } */

0 comments on commit 774ad67

Please sign in to comment.