diff mbox series

[COMMITTED] tree-optimization/101335 - Do not register a cast as an equivalence.

Message ID dd2018ac-ae15-2b49-d945-1e07b2a1df93@redhat.com
State New
Headers show
Series [COMMITTED] tree-optimization/101335 - Do not register a cast as an equivalence. | expand

Commit Message

Andrew MacLeod July 12, 2021, 6:37 p.m. UTC
Registering an equivalence between objects of the same size in a cast 
can cause other registered relations to be incorrect. Detailed in the 
PR.  This was an older attempt to solve a problem which has since been 
resolved by recomputation in the GORI engine.

Bootstrapped on  x86_64-pc-linux-gnu with no regressions. Pushed.

Andrew
diff mbox series

Patch

commit a1539b797a06e03b08e1f1de28ad0d19a3956616
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Mon Jul 12 11:38:17 2021 -0400

    Do not register a cast as an equivalence.
    
    Registering an equivalence between objects of the same size in a cast can
    cause other relations to be incorrect.
    
            gcc/
            PR tree-optimization/101335
            * range-op.cc (operator_cast::lhs_op1_relation): Delete.
    
            gcc/testsuite/
            * gcc.dg/tree-ssa/pr101335.c: New.

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index f8e4c6d4e49..08000465fd9 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -2159,10 +2159,6 @@  public:
 			  const irange &lhs,
 			  const irange &op2,
 			  relation_kind rel = VREL_NONE) const;
-  virtual enum tree_code lhs_op1_relation (const irange &lhs,
-					   const irange &op1,
-					   const irange &op2) const;
-
 private:
   bool truncating_cast_p (const irange &inner, const irange &outer) const;
   bool inside_domain_p (const wide_int &min, const wide_int &max,
@@ -2171,27 +2167,6 @@  private:
 			   const irange &outer) const;
 } op_convert;
 
-// Determine if there is a relationship between LHS and OP1.
-
-enum tree_code
-operator_cast::lhs_op1_relation (const irange &lhs,
-				 const irange &op1,
-				 const irange &op2 ATTRIBUTE_UNUSED) const
-{
-  if (op1.undefined_p ())
-    return VREL_NONE;
-  // We can't make larger types equivalent to smaller types because we can
-  // miss sign extensions in a chain of casts.
-  // u32 = 0xfffff
-  // s32 = (s32) u32
-  // s64 = (s64) s32
-  // we cant simply "convert" s64 = (s64)u32  or we get positive 0xffff
-  // value instead of sign extended negative value.
-  if (TYPE_PRECISION (lhs.type ()) == TYPE_PRECISION (op1.type ()))
-    return EQ_EXPR;
-  return VREL_NONE;
-}
-
 // Return TRUE if casting from INNER to OUTER is a truncating cast.
 
 inline bool
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr101335.c b/gcc/testsuite/gcc.dg/tree-ssa/pr101335.c
new file mode 100644
index 00000000000..921362c2954
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr101335.c
@@ -0,0 +1,17 @@ 
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+unsigned a = 0xFFFFFFFF;
+int b;
+int main()
+{
+  int c = ~a;
+  unsigned d = c - 10;
+  if (d > c)
+    c = 20;
+  b = -(c | 0);
+  if (b > -8)
+    __builtin_abort ();
+  return 0;
+}
+