[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-12-11 Thread liuhongt at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

--- Comment #20 from Hongtao Liu  ---
(In reply to Andrew Pinski from comment #19)
> Fixed.

Thanks.

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-12-11 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

Andrew Pinski  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #19 from Andrew Pinski  ---
Fixed.

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-12-11 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

--- Comment #18 from GCC Commits  ---
The trunk branch has been updated by Andrew Pinski :

https://gcc.gnu.org/g:85c5efcffed19ca6160eeecc2d4faebd9fee63aa

commit r14-6420-g85c5efcffed19ca6160eeecc2d4faebd9fee63aa
Author: Andrew Pinski 
Date:   Sat Nov 11 15:54:10 2023 -0800

MATCH: (convert)(zero_one !=/== 0/1) for outer type and zero_one type are
the same

When I moved two_value to match.pd, I removed the check for the {0,+-1}
as I had placed it after the {0,+-1} case for cond in match.pd.
In the case of {0,+-1} and non boolean, before we would optmize those
case to just `(convert)a` but after we would get `(convert)(a != 0)`
which was not handled anyways to just `(convert)a`.
So this adds a pattern to match `(convert)(zeroone != 0)` and simplify
to `(convert)zeroone`.

Also this optimizes (convert)(zeroone == 0) into (zeroone^1) if the
type match. Removing the opposite transformation from fold.
The opposite transformation was added with
https://gcc.gnu.org/pipermail/gcc-patches/2006-February/190514.html
It is no longer considered the canonicalization either, even VRP will
transform it back into `(~a) & 1` so removing it is a good idea.

Note the testcase pr69270.c needed a slight update due to not matching
exactly a scan pattern, this update makes it more robust and will match
before and afterwards and if there are other changes in this area too.

Note the testcase gcc.target/i386/pr110790-2.c needs a slight update
for better code generation in LP64 bit mode.

Bootstrapped and tested on x86_64-linux-gnu with no regressions.

gcc/ChangeLog:

PR tree-optimization/111972
PR tree-optimization/110637
* match.pd (`(convert)(zeroone !=/== CST)`): Match
and simplify to ((convert)zeroone){,^1}.
* fold-const.cc (fold_binary_loc): Remove
transformation of `(~a) & 1` and `(a ^ 1) & 1`
into `(convert)(a == 0)`.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr110637-1.c: New test.
* gcc.dg/tree-ssa/pr110637-2.c: New test.
* gcc.dg/tree-ssa/pr110637-3.c: New test.
* gcc.dg/tree-ssa/pr111972-1.c: New test.
* gcc.dg/tree-ssa/pr69270.c: Update testcase.
* gcc.target/i386/pr110790-2.c: Update testcase.
* gcc.dg/fold-even-1.c: Removed.

Signed-off-by: Andrew Pinski 

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-12-10 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||patch
URL||https://gcc.gnu.org/piperma
   ||il/gcc-patches/2023-Decembe
   ||r/640064.html

--- Comment #17 from Andrew Pinski  ---
Updated patch set:
https://gcc.gnu.org/pipermail/gcc-patches/2023-December/640064.html

The first patch of the original patch set was applied.

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-12-04 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

--- Comment #16 from GCC Commits  ---
The trunk branch has been updated by Andrew Pinski :

https://gcc.gnu.org/g:886f256ce3be4aa85f30af88558f0dfcb8003300

commit r14-6126-g886f256ce3be4aa85f30af88558f0dfcb8003300
Author: Andrew Pinski 
Date:   Sat Nov 11 20:33:28 2023 -0800

MATCH: Fix zero_one_valued_p's convert pattern

While working on PR 111972, I was getting a regression
due to zero_one_valued_p matching a signed 1 bit integer
when it came to convert. This patch fixes that by checking
the outer type too.

Bootstrapped and tested on x86_64-linux-gnu with no regressions.

gcc/ChangeLog:

* match.pd (zero_one_valued_p): For convert
make sure type is not a signed 1-bit integer.

Signed-off-by: Andrew Pinski 

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-12-01 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

--- Comment #15 from Andrew Pinski  ---
Patch set finally posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-December/639019.html

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-11-20 Thread liuhongt at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

--- Comment #14 from liuhongt at gcc dot gnu.org ---
(In reply to Andrew Pinski from comment #13)
> (In reply to liuhongt from comment #12)
> > 
> > Is there any progress for this?
> 
> I have a patch ready to post for this but since I changed employement a few
> weeks ago, I have to clear legal requirements still. It is a holiday week in
> the US this week too which partly blocks that too. I should be able to
> submit it the week after next.

Thanks, Happy Thanksgiving to you.

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-11-20 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

--- Comment #13 from Andrew Pinski  ---
(In reply to liuhongt from comment #12)
> 
> Is there any progress for this?

I have a patch ready to post for this but since I changed employement a few
weeks ago, I have to clear legal requirements still. It is a holiday week in
the US this week too which partly blocks that too. I should be able to submit
it the week after next.

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-11-20 Thread liuhongt at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

liuhongt at gcc dot gnu.org changed:

   What|Removed |Added

 CC||liuhongt at gcc dot gnu.org

--- Comment #12 from liuhongt at gcc dot gnu.org ---
(In reply to Andrew Pinski from comment #8)
> These should work:
> 
> (simplify
>  (convert (eq one_zero_valued_p@1 one_zero_valued_p@2))
>  (if (types_match (type, TREE_TYPE (@1)))
>   (bit_xor @1 (bit_xor! @2 { build_one_cst (type); }
> 
> (simplify
>  (convert (ne one_zero_valued_p@1 one_zero_valued_p@2))
>  (if (types_match (type, TREE_TYPE (@1)))
>   (bit_xor @1 @2})))
> 
> 
> Will test tomorrow.

Is there any progress for this?

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-11-13 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

--- Comment #11 from CVS Commits  ---
The master branch has been updated by hongtao Liu :

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

commit r14-5428-gfd1596f9962569afff6c9298a7c79686c6950bef
Author: liuhongt 
Date:   Mon Oct 30 15:43:48 2023 +0800

Handle bitop with INTEGER_CST in analyze_and_compute_bitop_with_inv_effect.

analyze_and_compute_bitop_with_inv_effect assumes the first operand is
loop invariant which is not the case when it's INTEGER_CST.

gcc/ChangeLog:

PR tree-optimization/105735
PR tree-optimization/111972
* tree-scalar-evolution.cc
(analyze_and_compute_bitop_with_inv_effect): Handle bitop with
INTEGER_CST.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr105735-3.c: New test.

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-10-27 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P1

--- Comment #10 from Richard Biener  ---
  # j_19 = PHI <_14(8), j_22(5)>
  _9 = j_19 != 1;
  _14 = (long int) _9;

so the vectorizer interesting thing is whether we can handle (equality)
compares the same as other associative operations (apart from the
involved cast).  Now the above isn't canonical, j_19 ^ 1 was though.

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-10-27 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

--- Comment #9 from Andrew Pinski  ---
(In reply to Andrew Pinski from comment #8)
> These should work:
> 
> (simplify
>  (convert (eq one_zero_valued_p@1 one_zero_valued_p@2))
>  (if (types_match (type, TREE_TYPE (@1)))
>   (bit_xor @1 (bit_xor! @2 { build_one_cst (type); }
> 
> (simplify
>  (convert (ne one_zero_valued_p@1 one_zero_valued_p@2))
>  (if (types_match (type, TREE_TYPE (@1)))
>   (bit_xor @1 @2})))
> 
> 
> Will test tomorrow.

Maybe we don't need the types_match either ...
But then we need a convert. That would fix PR 110637 too.

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-10-27 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

--- Comment #8 from Andrew Pinski  ---
These should work:

(simplify
 (convert (eq one_zero_valued_p@1 one_zero_valued_p@2))
 (if (types_match (type, TREE_TYPE (@1)))
  (bit_xor @1 (bit_xor! @2 { build_one_cst (type); }

(simplify
 (convert (ne one_zero_valued_p@1 one_zero_valued_p@2))
 (if (types_match (type, TREE_TYPE (@1)))
  (bit_xor @1 @2})))


Will test tomorrow.

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-10-26 Thread crazylht at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

--- Comment #7 from Hongtao.liu  ---
(In reply to Andrew Pinski from comment #3)
> First off does this even make sense to vectorize but rather do some kind of
> scalar reduction with respect to j = j^1 here  .  Filed PR 112104 for that.
> 
> Basically vectorizing this loop is a waste compared to that.

Yes, it's always zero, it would be nice if the middle end can optimize the
whole loop off. So for this PR, it's more related to the misoptimization of the
redundant loop(better finalize the induction variable with a simple
assignment), not vectorization.

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-10-26 Thread crazylht at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

--- Comment #6 from Hongtao.liu  ---
(In reply to Andrew Pinski from comment #5)
> Oh this is the original code:
> https://github.com/kdlucas/byte-unixbench/blob/master/UnixBench/src/whets.c
> 
Yes, it's from unixbench.

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-10-26 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

--- Comment #5 from Andrew Pinski  ---
Oh this is the original code:
https://github.com/kdlucas/byte-unixbench/blob/master/UnixBench/src/whets.c


HEHEHEHEHEHEHEHEH. Basically after optimizing:

  _9 = j_19 != 1;
  _14 = (long int) _9;

Over to:
_14 = j_19 ^ 1;

We could optimize this whole loop out.

Note this is a bad benchmark.

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-10-26 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

--- Comment #4 from Andrew Pinski  ---
Is there a non-reduced testcase here? Or does the loop really just do j = j^1 ?

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-10-26 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

Andrew Pinski  changed:

   What|Removed |Added

   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=112104

--- Comment #3 from Andrew Pinski  ---
First off does this even make sense to vectorize but rather do some kind of
scalar reduction with respect to j = j^1 here  .  Filed PR 112104 for that.

Basically vectorizing this loop is a waste compared to that.

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-10-25 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |ASSIGNED
   Keywords||missed-optimization
 Ever confirmed|0   |1
   Last reconfirmed||2023-10-25
   Assignee|unassigned at gcc dot gnu.org  |pinskia at gcc dot 
gnu.org
   Target Milestone|--- |14.0

--- Comment #2 from Andrew Pinski  ---
Mine.

[Bug tree-optimization/111972] [14 regression] missed vectorzation for bool a = j != 1; j = (long int)a;

2023-10-25 Thread crazylht at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111972

Hongtao.liu  changed:

   What|Removed |Added

 CC||pinskia at gcc dot gnu.org
  Component|middle-end  |tree-optimization

--- Comment #1 from Hongtao.liu  ---
The phiopt change is caused by
r14-338-g1dd154f6407658d46faa4d21bfec04fc2551506a