public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/94413] New: auto-vectorization of isfinite raises FP exception
@ 2020-03-30 20:53 kretz at kde dot org
  2020-03-31  7:41 ` [Bug target/94413] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: kretz at kde dot org @ 2020-03-30 20:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94413

            Bug ID: 94413
           Summary: auto-vectorization of isfinite raises FP exception
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kretz at kde dot org
  Target Milestone: ---
            Target: x86_64-*-*, i?86-*-*

Test case (`-O3`, cf. https://godbolt.org/z/jdfv3r):

#include <cfenv>
#include <cmath>
#include <limits>

using f4 [[gnu::vector_size(16)]] = float;

f4 isfinite(f4 x) {
  f4 r = {};
  for (int i = 0; i < 4; ++i) r[i] = std::isfinite(x[i]) ? 1.f : 0.f;
  return r;
}

using L = std::numeric_limits<float>;
f4 test = {1, 2, 3, L::quiet_NaN()};

int main() {
  std::feclearexcept(FE_ALL_EXCEPT);
  test = isfinite(test);
  if (std::fetestexcept(FE_ALL_EXCEPT) != 0) __builtin_abort();
  return 0;
}

This translates to `fabs(test)<=FLT_MAX` but incorrectly using a signaling
compare instruction.

Alterative vectorization of isfinite(x):
* interpret x as int vector
* return inf > x & inf

This works because if all exponent bits of x are set, x is either inf or NaN
(i.e. not finite).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/94413] auto-vectorization of isfinite raises FP exception
  2020-03-30 20:53 [Bug target/94413] New: auto-vectorization of isfinite raises FP exception kretz at kde dot org
@ 2020-03-31  7:41 ` rguenth at gcc dot gnu.org
  2020-03-31  8:45 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-03-31  7:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94413

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-03-31
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
I see

  vect_iftmp.13_34 = VEC_COND_EXPR <vect__7.12_30 u> vect_cst__31,
vect_cst__32, vect_cst__33>;

so we use isgreater here and expand as

(insn 12 11 13 (set (reg:V4SF 93)
        (ungt:V4SF (reg:V4SF 87 [ vect__10.22 ])
            (reg:V4SF 90))) "t.C":18:14 -1 {sse_maskcmpv4sf3}
     (nil))

confirmed.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/94413] auto-vectorization of isfinite raises FP exception
  2020-03-30 20:53 [Bug target/94413] New: auto-vectorization of isfinite raises FP exception kretz at kde dot org
  2020-03-31  7:41 ` [Bug target/94413] " rguenth at gcc dot gnu.org
@ 2020-03-31  8:45 ` jakub at gcc dot gnu.org
  2020-03-31  8:45 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-03-31  8:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94413

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|1                           |0
             Status|NEW                         |UNCONFIRMED
   Last reconfirmed|2020-03-31 00:00:00         |
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |uros at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Somewhat modified testcase:
typedef float f4 __attribute__((vector_size (16)));

f4
isfinite(f4 x) {
  union U { float f[4]; f4 v; } u, v;
  u.v = x;
  v.v = (f4) {};
  int i;
  for (i = 0; i < 4; ++i) v.f[i] = __builtin_isfinite(u.f[i]) ? 1.f : 0.f;
  return v.v;
}
aborts already since r0-82110-g0c8d3c2b0852bf0eca1413c311fc3d2a9d3c1ade.
Though, in *.optimized dump it is
  _2 = ABS_EXPR <_1>;
  if (_2 u> 3.4028234663852885981170418348451692544e+38)
for scalar version which works fine and
  vect__2.8_33 = ABS_EXPR <x_7(D)>;
  vect_iftmp.9_37 = VEC_COND_EXPR <vect__2.8_33 u> {
3.4028234663852885981170418348451692544e+38,
3.4028234663852885981170418348451692544e+38,
3.4028234663852885981170418348451692544e+38,
3.4028234663852885981170418348451692544e+38 }, { 0.0, 0.0, 0.0, 0.0 }, {
1.0e+0, 1.0e+0, 1.0e+0, 1.0e+0 }>;
for vector which doesn't, so it looks like a backend problem.  For AVX we could
use vcmpnlt_uqps, but for < AVX there is no such insn.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/94413] auto-vectorization of isfinite raises FP exception
  2020-03-30 20:53 [Bug target/94413] New: auto-vectorization of isfinite raises FP exception kretz at kde dot org
  2020-03-31  7:41 ` [Bug target/94413] " rguenth at gcc dot gnu.org
  2020-03-31  8:45 ` jakub at gcc dot gnu.org
@ 2020-03-31  8:45 ` jakub at gcc dot gnu.org
  2020-03-31  9:12 ` rguenth at gcc dot gnu.org
  2024-03-14 20:50 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-03-31  8:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94413

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-03-31

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/94413] auto-vectorization of isfinite raises FP exception
  2020-03-30 20:53 [Bug target/94413] New: auto-vectorization of isfinite raises FP exception kretz at kde dot org
                   ` (2 preceding siblings ...)
  2020-03-31  8:45 ` jakub at gcc dot gnu.org
@ 2020-03-31  9:12 ` rguenth at gcc dot gnu.org
  2024-03-14 20:50 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-03-31  9:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94413

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
in expand_vec_cond_expr_p there is

  if (VECTOR_BOOLEAN_TYPE_P (cmp_op_type)
      && get_vcond_mask_icode (TYPE_MODE (value_type),
                               TYPE_MODE (cmp_op_type)) != CODE_FOR_nothing)
    return true;

which doesn't bother to look at 'code' (though here we don't have
VECTOR_BOOLEAN_TYPE_P).  For the other cases we build test RTL and
check insn operand predicates.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/94413] auto-vectorization of isfinite raises FP exception
  2020-03-30 20:53 [Bug target/94413] New: auto-vectorization of isfinite raises FP exception kretz at kde dot org
                   ` (3 preceding siblings ...)
  2020-03-31  9:12 ` rguenth at gcc dot gnu.org
@ 2024-03-14 20:50 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-14 20:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94413

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup.

*** This bug has been marked as a duplicate of bug 91861 ***

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-03-14 20:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-30 20:53 [Bug target/94413] New: auto-vectorization of isfinite raises FP exception kretz at kde dot org
2020-03-31  7:41 ` [Bug target/94413] " rguenth at gcc dot gnu.org
2020-03-31  8:45 ` jakub at gcc dot gnu.org
2020-03-31  8:45 ` jakub at gcc dot gnu.org
2020-03-31  9:12 ` rguenth at gcc dot gnu.org
2024-03-14 20:50 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).