diff mbox series

[2/2] tree-optimization/113831 - revert original fix

Message ID 20240228130944.25330385841D@sourceware.org
State New
Headers show
Series [1/2] tree-optimization/114121 - wrong VN with context sensitive range info | expand

Commit Message

Richard Biener Feb. 28, 2024, 1:09 p.m. UTC
This reverts the original fix for PR113831 which is better fixed by
the PR114121 fix.  I've XFAILed instead of removing the PR108355
testcase again.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/113831
	PR tree-optimization/108355
	* tree-ssa-sccvn.cc (copy_reference_ops_from_ref): Revert
	PR113831 fix.

	* gcc.dg/tree-ssa/ssa-fre-104.c: XFAIL.
---
 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-104.c |   2 +-
 gcc/tree-ssa-sccvn.cc                       | 134 --------------------
 2 files changed, 1 insertion(+), 135 deletions(-)
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-104.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-104.c
index f0f12ef82b7..425c32dd93c 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-104.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-104.c
@@ -21,4 +21,4 @@  int main() {
   *c = &d;
 }
 
-/* { dg-final { scan-tree-dump-not "foo" "fre1" } } */
+/* { dg-final { scan-tree-dump-not "foo" "fre1" { xfail *-*-* } } } */
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 21123644a5a..0b7fb0663c7 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -912,8 +912,6 @@  copy_reference_ops_from_ref (tree ref, vec<vn_reference_op_s> *result)
 {
   /* For non-calls, store the information that makes up the address.  */
   tree orig = ref;
-  unsigned start = result->length ();
-  bool seen_variable_array_ref = false;
   while (ref)
     {
       vn_reference_op_s temp;
@@ -1000,12 +998,6 @@  copy_reference_ops_from_ref (tree ref, vec<vn_reference_op_s> *result)
 	    tree eltype = TREE_TYPE (TREE_TYPE (TREE_OPERAND (ref, 0)));
 	    /* Record index as operand.  */
 	    temp.op0 = TREE_OPERAND (ref, 1);
-	    /* When the index is not constant we have to apply the same
-	       logic as get_ref_base_and_extent which eventually uses
-	       global ranges to refine the overall ref extent.  Record
-	       we've seen such a case, fixup below.  */
-	    if (TREE_CODE (temp.op0) == SSA_NAME)
-	      seen_variable_array_ref = true;
 	    /* Always record lower bounds and element size.  */
 	    temp.op1 = array_ref_low_bound (ref);
 	    /* But record element size in units of the type alignment.  */
@@ -1098,132 +1090,6 @@  copy_reference_ops_from_ref (tree ref, vec<vn_reference_op_s> *result)
       else
 	ref = NULL_TREE;
     }
-  poly_int64 offset, size, max_size;
-  tree base;
-  bool rev;
-  if (seen_variable_array_ref
-      && handled_component_p (orig)
-      && (base = get_ref_base_and_extent (orig,
-					  &offset, &size, &max_size, &rev))
-      && known_size_p (max_size)
-      && known_eq (size, max_size))
-    {
-      poly_int64 orig_offset = offset;
-      poly_int64 tem;
-      if (TREE_CODE (base) == MEM_REF
-	  && mem_ref_offset (base).to_shwi (&tem))
-	offset += tem * BITS_PER_UNIT;
-      HOST_WIDE_INT coffset = offset.to_constant ();
-      /* When get_ref_base_and_extent computes an offset constrained to
-	 a constant position we have to fixup variable array indexes in
-	 the ref to avoid the situation where based on context we'd have
-	 to value-number the same vn_reference ops differently.  Make
-	 the vn_reference ops differ by adjusting those indexes to
-	 appropriate constants.  */
-      poly_int64 off = 0;
-      bool oob_index = false;
-      for (unsigned i = result->length (); i > start; --i)
-	{
-	  auto &op = (*result)[i-1];
-	  if (flag_checking
-	      && op.opcode == ARRAY_REF
-	      && TREE_CODE (op.op0) == INTEGER_CST)
-	    {
-	      /* The verifier below chokes on inconsistencies of handling
-		 out-of-bound accesses so disable it in that case.  */
-	      tree atype = (*result)[i].type;
-	      if (TREE_CODE (atype) == ARRAY_TYPE)
-		if (tree dom = TYPE_DOMAIN (atype))
-		  if ((TYPE_MIN_VALUE (dom)
-		       && TREE_CODE (TYPE_MIN_VALUE (dom)) == INTEGER_CST
-		       && (wi::to_widest (op.op0)
-			   < wi::to_widest (TYPE_MIN_VALUE (dom))))
-		      || (TYPE_MAX_VALUE (dom)
-			  && TREE_CODE (TYPE_MAX_VALUE (dom)) == INTEGER_CST
-			  && (wi::to_widest (op.op0)
-			      > wi::to_widest (TYPE_MAX_VALUE (dom)))))
-		    oob_index = true;
-	    }
-	  if ((op.opcode == ARRAY_REF
-	       || op.opcode == ARRAY_RANGE_REF)
-	      && TREE_CODE (op.op0) == SSA_NAME)
-	    {
-	      /* There's a single constant index that get's 'off' closer
-		 to 'offset'.  */
-	      unsigned HOST_WIDE_INT elsz
-		= tree_to_uhwi (op.op2) * vn_ref_op_align_unit (&op);
-	      unsigned HOST_WIDE_INT idx
-		= (coffset - off.to_constant ()) / BITS_PER_UNIT / elsz;
-	      if (idx == 0)
-		op.op0 = op.op1;
-	      else
-		op.op0 = wide_int_to_tree (TREE_TYPE (op.op0),
-					   wi::to_poly_wide (op.op1) + idx);
-	      op.off = idx * elsz;
-	      off += op.off * BITS_PER_UNIT;
-	    }
-	  else
-	    {
-	      if (op.opcode == ERROR_MARK)
-		/* two-ops codes have the offset in the first op.  */
-		;
-	      else if (op.opcode == ADDR_EXPR
-		       || op.opcode == SSA_NAME
-		       || op.opcode == CONSTRUCTOR
-		       || TREE_CODE_CLASS (op.opcode) == tcc_declaration
-		       || TREE_CODE_CLASS (op.opcode) == tcc_constant)
-		/* end-of ref.  */
-		gcc_assert (i == result->length ());
-	      else if (op.opcode == COMPONENT_REF)
-		{
-		  /* op.off is tracked in bytes, re-do it manually
-		     because of bitfields.  */
-		  tree field = op.op0;
-		  /* We do not have a complete COMPONENT_REF tree here so we
-		     cannot use component_ref_field_offset.  Do the interesting
-		     parts manually.  */
-		  tree this_offset = DECL_FIELD_OFFSET (field);
-		  if (op.op1 || !poly_int_tree_p (this_offset))
-		    gcc_unreachable ();
-		  else
-		    {
-		      poly_offset_int woffset
-			= (wi::to_poly_offset (this_offset)
-			   << LOG2_BITS_PER_UNIT);
-		      woffset += wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
-		      off += woffset.force_shwi ();
-		    }
-		}
-	      else
-		{
-		  gcc_assert (known_ne (op.off, -1)
-			      /* The constant offset can be -1.  */
-			      || op.opcode == MEM_REF
-			      /* Out-of-bound indices can compute to
-				 a known -1 offset.  */
-			      || ((op.opcode == ARRAY_REF
-				   || op.opcode == ARRAY_RANGE_REF)
-				  && poly_int_tree_p (op.op0)
-				  && poly_int_tree_p (op.op1)
-				  && TREE_CODE (op.op2) == INTEGER_CST));
-		  off += op.off * BITS_PER_UNIT;
-		}
-	    }
-	}
-      if (flag_checking && !oob_index)
-	{
-	  ao_ref r;
-	  if (start != 0)
-	    ;
-	  else if (ao_ref_init_from_vn_reference (&r, 0, 0, TREE_TYPE (orig),
-						  *result))
-	    gcc_assert (known_eq (r.offset, orig_offset)
-			&& known_eq (r.size, size)
-			&& known_eq (r.max_size, max_size));
-	  else
-	    gcc_unreachable ();
-	}
-    }
 }
 
 /* Build a alias-oracle reference abstraction in *REF from the vn_reference