diff mbox series

pointer_plus [0, 0] + const folding

Message ID 9f6a5a21-ed26-b7bd-471d-7c98c5206cc4@redhat.com
State New
Headers show
Series pointer_plus [0, 0] + const folding | expand

Commit Message

Andrew MacLeod Oct. 16, 2020, 7:12 p.m. UTC
In order to match evrp behaviour, adjust POINTER_PLUS_EXPR processing to 
handle a zero constant plus something to return the something.
ie

[0, 0]  + CONST    will now return [CONST, CONST] instead of the 
previous behaviour of [1, +INF].


Bootstrapped on x86_64-pc-linux-gnu, no regressions, pushed.

Andrew
diff mbox series

Patch

2020-10-16  Andrew MacLeod  <amacleod@redhat.com>

	* range-op.cc (pointer_plus_operator::wi_fold): Make pointer_plus
	[0, 0] + const return a [const, const] range.


diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 6108de367ad..9df08a61289 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -3063,6 +3063,14 @@  pointer_plus_operator::wi_fold (irange &r, tree type,
 				const wide_int &rh_lb,
 				const wide_int &rh_ub) const
 {
+  // Check for [0,0] + const, and simply return the const.
+  if (lh_lb == 0 && lh_ub == 0 && rh_lb == rh_ub)
+    {
+      tree val = wide_int_to_tree (type, rh_lb);
+      r.set (val, val);
+      return;
+    }
+
   // For pointer types, we are really only interested in asserting
   // whether the expression evaluates to non-NULL.
   //