[Bug tree-optimization/94234] missed ccp folding for (addr + 8 * n) - (addr + 8 * (n - 1))

2020-09-15 Thread fxue at os dot amperecomputing.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94234

Feng Xue  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|NEW |RESOLVED

--- Comment #6 from Feng Xue  ---
Fixed.

[Bug tree-optimization/94234] missed ccp folding for (addr + 8 * n) - (addr + 8 * (n - 1))

2020-09-15 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94234

--- Comment #5 from CVS Commits  ---
The master branch has been updated by Feng Xue :

https://gcc.gnu.org/g:8f0d743c2dee6afae5c6f861b0642b7b112a4a70

commit r11-3207-g8f0d743c2dee6afae5c6f861b0642b7b112a4a70
Author: Feng Xue 
Date:   Mon Aug 17 23:00:35 2020 +0800

tree-optimization/94234 - add plusminus-with-convert pattern

Add a rule (T)(A) +- (T)(B) -> (T)(A +- B), which works only when (A +- B)
could be folded to a simple value. By this rule, a
plusminus-mult-with-convert
expression could be handed over to the rule (A * C) +- (B * C) -> (A +- B).

2020-09-15  Feng Xue  

gcc/
PR tree-optimization/94234
* match.pd (T)(A) +- (T)(B) -> (T)(A +- B): New simplification.

gcc/testsuite/
PR tree-optimization/94234
* gcc.dg/pr94234-3.c: New test.

[Bug tree-optimization/94234] missed ccp folding for (addr + 8 * n) - (addr + 8 * (n - 1))

2020-09-14 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94234

--- Comment #4 from CVS Commits  ---
The master branch has been updated by Feng Xue :

https://gcc.gnu.org/g:f9d2def016410a2095df6b399097b482f82064a5

commit r11-3199-gf9d2def016410a2095df6b399097b482f82064a5
Author: Feng Xue 
Date:   Tue Sep 1 17:17:58 2020 +0800

tree-optimization/94234 - Fold plusminus_mult expr with multi-use operands

2020-09-03  Feng Xue  

gcc/
PR tree-optimization/94234
* genmatch.c (dt_simplify::gen_1): Emit check on final
simplification
result when "!" is specified on toplevel output expr.
* match.pd ((A * C) +- (B * C) -> (A +- B) * C): Allow folding on
expr
with multi-use operands if final result is a simple gimple value.

gcc/testsuite/
PR tree-optimization/94234
* gcc.dg/pr94234-2.c: New test.

[Bug tree-optimization/94234] missed ccp folding for (addr + 8 * n) - (addr + 8 * (n - 1))

2020-08-19 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94234

--- Comment #3 from CVS Commits  ---
The master branch has been updated by Feng Xue :

https://gcc.gnu.org/g:459f6f68a75fe88e7c8309ca8ad3244a532b0d8e

commit r11-2764-g459f6f68a75fe88e7c8309ca8ad3244a532b0d8e
Author: Feng Xue 
Date:   Mon Jun 1 11:57:35 2020 +0800

tree-optimization/94234 - add pattern for ptr-diff on addresses with same
offset

2020-08-19  Feng Xue  

gcc/
PR tree-optimization/94234
* match.pd ((PTR_A + OFF) - (PTR_B + OFF)) -> (PTR_A - PTR_B): New
simplification.

gcc/testsuite/
PR tree-optimization/94234
* gcc.dg/pr94234-1.c: New test.

[Bug tree-optimization/94234] missed ccp folding for (addr + 8 * n) - (addr + 8 * (n - 1))

2020-03-20 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94234

--- Comment #2 from Marc Glisse  ---
The closest we have is

/* (A * C) +- (B * C) -> (A+-B) * C and (A * C) +- A -> A * (C+-1).

which does not handle conversions, although it should be possible to add them.

[Bug tree-optimization/94234] missed ccp folding for (addr + 8 * n) - (addr + 8 * (n - 1))

2020-03-20 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94234

Richard Biener  changed:

   What|Removed |Added

 Ever confirmed|0   |1
   Last reconfirmed||2020-03-20
   Keywords||missed-optimization
Version|unknown |10.0
 Status|UNCONFIRMED |NEW

--- Comment #1 from Richard Biener  ---
Confirmed.  Might be also a regression since POINTER_DIFF_EXPR introduction.

We have

   (simplify
(pointer_diff (pointer_plus @@0 @1) (pointer_plus @0 @2))
/* The second argument of pointer_plus must be interpreted as signed, and
   thus sign-extended if necessary.  */
(with { tree stype = signed_type_for (TREE_TYPE (@1)); }
 /* Use view_convert instead of convert here, as POINTER_PLUS_EXPR
second arg is unsigned even when we need to consider it as signed,
we don't want to diagnose overflow here.  */
 (minus (convert (view_convert:stype @1))
(convert (view_convert:stype @2)))

which triggers here but appearantly the resulting minus isn't simplified.

  _1 = n_5(D) * 8;
  b1_7 = a_6(D) + _1;
  _2 = n_5(D) + 18446744073709551615;
  _3 = _2 * 8;
  b2_8 = a_6(D) + _3;

and we need to simplify _1 - _3.  Possibly the excessive conversions above
mess with the constraint of CCP not wanting new stmts.  You can see what
forwprop does which applies all foldings possible and computes:

  _1 = n_5(D) * 8;
  _2 = n_5(D) + 18446744073709551615;
  _3 = _2 * 8;
  _11 = (signed long) _1;
  _12 = (signed long) _3;
  _4 = _11 - _12;
  _9 = (long unsigned int) _4;
  return _9;

I don't think we have match.pd patterns simplifying that.