[Bug target/104401] [x86] Failure to recognize min/max pattern using pcmp+pblendv

2024-01-20 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104401

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |14.0

[Bug target/104401] [x86] Failure to recognize min/max pattern using pcmp+pblendv

2024-01-10 Thread liuhongt at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104401

Hongtao Liu  changed:

   What|Removed |Added

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

--- Comment #8 from Hongtao Liu  ---
Fixed in GCC14.

[Bug target/104401] [x86] Failure to recognize min/max pattern using pcmp+pblendv

2024-01-10 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104401

--- Comment #7 from GCC Commits  ---
The master branch has been updated by hongtao Liu :

https://gcc.gnu.org/g:6686e16fda419067b91614835dd743ebb82717ea

commit r14-7124-g6686e16fda419067b91614835dd743ebb82717ea
Author: liuhongt 
Date:   Tue Dec 19 10:39:06 2023 +0800

Optimize A < B ? A : B to MIN_EXPR.

Similar for A < B ? B : A to MAX_EXPR.
There're codes in the frontend to optimize such pattern but failed to
handle testcase in the PR since it's exposed at gimple level when
folding backend builtins.

pr95906 now can be optimized to MAX_EXPR as it's commented in the
testcase.

// FIXME: this should further optimize to a MAX_EXPR
 typedef signed char v16i8 __attribute__((vector_size(16)));
 v16i8 f(v16i8 a, v16i8 b)

gcc/ChangeLog:

PR target/104401
* match.pd (VEC_COND_EXPR: A < B ? A : B -> MIN_EXPR): New patten
match.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr104401.c: New test.
* gcc.dg/tree-ssa/pr95906.c: Adjust testcase.

[Bug target/104401] [x86] Failure to recognize min/max pattern using pcmp+pblendv

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

Hongtao Liu  changed:

   What|Removed |Added

 CC||liuhongt at gcc dot gnu.org

--- Comment #6 from Hongtao Liu  ---
On latest trunk, we have

19   [local count: 1073741824]:
20  _6 = VIEW_CONVERT_EXPR(value_2(D));
21  _7 = VIEW_CONVERT_EXPR(input_3(D));
22  _8 = _6 < _7;
23  _4 = VEC_COND_EXPR <_8, _6, _7>;
24  _5 = VIEW_CONVERT_EXPR(_4);
25  return _5;
26
27}

And we can match a < b ? a : b for vector modes.

[Bug target/104401] [x86] Failure to recognize min/max pattern using pcmp+pblendv

2022-02-06 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104401

--- Comment #5 from Richard Biener  ---
(In reply to Andrew Pinski from comment #3)
> On a slightly different subject, I wish VCOND would print out the tree code
> symbolically rather than just a number. It would be easier to understand
> what the condition exec is really.

Feel free to add a // comment after it ;)

Btw, forwprop1 sees

   :
  _12 = VIEW_CONVERT_EXPR(value_3(D));
  _13 = VIEW_CONVERT_EXPR(input_4(D));
  _14 = _12 < _13;
  _15 = VEC_COND_EXPR <_14, { -1, -1, -1, -1 }, { 0, 0, 0, 0 }>;
  _16 = VIEW_CONVERT_EXPR<__m128i>(_15);
  _6 = VIEW_CONVERT_EXPR(_15);
  _5 = VIEW_CONVERT_EXPR(value_3(D));
  _8 = VIEW_CONVERT_EXPR(input_4(D));
  _9 = _6 < { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  _10 = VEC_COND_EXPR <_9, _5, _8>;
  _11 = VIEW_CONVERT_EXPR<__m128i>(_10);
  return _11;

the difficulty #1 is the v16qi mode blend vs. the v4si mode compare so
we'd have to pattern match the blend to be done on v4si based on the
_15 value range.

[Bug target/104401] [x86] Failure to recognize min/max pattern using pcmp+pblendv

2022-02-06 Thread crazylht at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104401

--- Comment #4 from Hongtao.liu  ---
(In reply to Andrew Pinski from comment #3)
> On a slightly different subject, I wish VCOND would print out the tree code
> symbolically rather than just a number. It would be easier to understand
> what the condition exec is really.

Yes, not quite straightforward.

Here it means
 _8 = _5 < { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } ? _4 : _6;
(blendv uses sign bit as mask bit).

[Bug target/104401] [x86] Failure to recognize min/max pattern using pcmp+pblendv

2022-02-06 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104401

--- Comment #3 from Andrew Pinski  ---
On a slightly different subject, I wish VCOND would print out the tree code
symbolically rather than just a number. It would be easier to understand what
the condition exec is really.

[Bug target/104401] [x86] Failure to recognize min/max pattern using pcmp+pblendv

2022-02-06 Thread crazylht at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104401

--- Comment #2 from Hongtao.liu  ---
(In reply to Andrew Pinski from comment #1)
> (set (reg:V16QI 93)
> (unspec:V16QI [
> (subreg:V16QI (reg/v:V2DI 92 [ input ]) 0)
> (subreg:V16QI (reg/v:V2DI 91 [ value ]) 0)
> (subreg:V16QI (gt:V4SI (subreg:V4SI (reg/v:V2DI 92 [ input ]) 0)
> (subreg:V4SI (reg/v:V2DI 91 [ value ]) 0)) 0)
> ] UNSPEC_BLENDV))
> 
> blend uses unspec which makes this a little harder

I think it could be done in gimple level.

 18  _10 = VIEW_CONVERT_EXPR(value_2(D));
 19  _11 = VIEW_CONVERT_EXPR(input_3(D));
 20  _12 = _10 < _11;
 21  _13 = VIEW_CONVERT_EXPR(_12);
 22  _5 = VIEW_CONVERT_EXPR(_13);
 23  _4 = VIEW_CONVERT_EXPR(value_2(D));
 24  _6 = VIEW_CONVERT_EXPR(input_3(D));
 25  _8 = .VCOND (_5, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, _4,
_6, 108);
 26  _9 = VIEW_CONVERT_EXPR<__m128i>(_8);

[Bug target/104401] [x86] Failure to recognize min/max pattern using pcmp+pblendv

2022-02-05 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104401

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2022-02-05
 Ever confirmed|0   |1

--- Comment #1 from Andrew Pinski  ---

(set (reg:V16QI 93)
(unspec:V16QI [
(subreg:V16QI (reg/v:V2DI 92 [ input ]) 0)
(subreg:V16QI (reg/v:V2DI 91 [ value ]) 0)
(subreg:V16QI (gt:V4SI (subreg:V4SI (reg/v:V2DI 92 [ input ]) 0)
(subreg:V4SI (reg/v:V2DI 91 [ value ]) 0)) 0)
] UNSPEC_BLENDV))

blend uses unspec which makes this a little harder

[Bug target/104401] [x86] Failure to recognize min/max pattern using pcmp+pblendv

2022-02-05 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104401

Andrew Pinski  changed:

   What|Removed |Added

   Severity|normal  |enhancement