public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/95739] New: [11 Regression] Unordered comparison and VEC_COND_EXPR
@ 2020-06-18 10:11 marxin at gcc dot gnu.org
  2020-06-18 10:12 ` [Bug tree-optimization/95739] " marxin at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-06-18 10:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95739
           Summary: [11 Regression] Unordered comparison and VEC_COND_EXPR
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
                CC: rguenth at gcc dot gnu.org
  Target Milestone: ---

The following is a fallout of
r11-1445-g502d63b6d6141597bb18fd23c87736a1b384cf8f but it seems to me a latent
issue:

$ cat pr50310.c
double s1[4], s2[4], s3[64];

int
main ()
{
  s1[0] = __builtin_nan ("");
  s1[1] = 6.0;
  s1[2] = 6.0;
  s1[3] = 6.0;

  s2[0] = 5.0;
  s2[1] = 5.0;
  s2[2] = 5.0;
  s2[3] = 5.0;

  asm volatile ("" : : : "memory");
  for (int i = 0; i < 4; i++)
    s3[i] = __builtin_isgreater (s1[i], s2[i]) ? -1.0 : 0.0;

  if (s3[1] != -1.0)
    __builtin_abort ();
  return 0;
}

$ gcc pr50310.c -O3 -ffloat-store && ./a.out 
Aborted (core dumped)

The thing is that we newly generate:
--- good        2020-06-18 12:08:56.901799621 +0200
+++ bad 2020-06-18 12:08:54.137825794 +0200
@@ -1,39 +1,43 @@

-;; Function main (main, funcdef_no=0, decl_uid=1937, cgraph_uid=1,
symbol_order=3) (executed once)
+;; Function main (main, funcdef_no=0, decl_uid=1933, cgraph_uid=1,
symbol_order=3) (executed once)

 main ()
 {
   vector(2) double vect_iftmp.11;
   vector(2) double vect__2.10;
   vector(2) double vect__1.7;
+  vector(2) <signed-boolean:64> _4;
   double _14;
+  vector(2) <signed-boolean:64> _43;

   <bb 2> [local count: 214748371]:
   MEM <vector(2) double> [(double *)&s1] = {  Nan, 6.0e+0 };
   MEM <vector(2) double> [(double *)&s1 + 16B] = { 6.0e+0, 6.0e+0 };
   MEM <vector(2) double> [(double *)&s2] = { 5.0e+0, 5.0e+0 };
   MEM <vector(2) double> [(double *)&s2 + 16B] = { 5.0e+0, 5.0e+0 };
   __asm__ __volatile__("" :  :  : "memory");
   vect__1.7_5 = MEM <vector(2) double> [(double *)&s1];
   vect__2.10_19 = MEM <vector(2) double> [(double *)&s2];
-  vect_iftmp.11_4 = VEC_COND_EXPR <vect__1.7_5 u<= vect__2.10_19, { 0.0, 0.0
}, { -1.0e+0, -1.0e+0 }>;
-  MEM <vector(2) double> [(double *)&s3] = vect_iftmp.11_4;
+  _4 = vect__1.7_5 u<= vect__2.10_19;
+  vect_iftmp.11_33 = .VCOND (vect__1.7_5, vect__2.10_19, { 0.0, 0.0 }, {
-1.0e+0, -1.0e+0 }, 117);
+  MEM <vector(2) double> [(double *)&s3] = vect_iftmp.11_33;
   vect__1.7_37 = MEM <vector(2) double> [(double *)&s1 + 16B];
   vect__2.10_40 = MEM <vector(2) double> [(double *)&s2 + 16B];
-  vect_iftmp.11_43 = VEC_COND_EXPR <vect__1.7_37 u<= vect__2.10_40, { 0.0, 0.0
}, { -1.0e+0, -1.0e+0 }>;
-  MEM <vector(2) double> [(double *)&s3 + 16B] = vect_iftmp.11_43;
-  _14 = BIT_FIELD_REF <vect_iftmp.11_4, 64, 64>;
+  _43 = vect__1.7_37 u<= vect__2.10_40;
+  vect_iftmp.11_44 = .VCOND (vect__1.7_37, vect__2.10_40, { 0.0, 0.0 }, {
-1.0e+0, -1.0e+0 }, 117);
+  MEM <vector(2) double> [(double *)&s3 + 16B] = vect_iftmp.11_44;
+  _14 = BIT_FIELD_REF <vect_iftmp.11_33, 64, 64>;
   if (_14 != -1.0e+0)
     goto <bb 3>; [0.00%]
   else
     goto <bb 4>; [100.00%]

   <bb 3> [count: 0]:
   __builtin_abort ();

   <bb 4> [local count: 214748368]:
   return 0;

 }

Looking at the assembly the comparison is somehow gone:
diff -u good.s bad.s
--- good.s      2020-06-18 12:09:52.385274181 +0200
+++ bad.s       2020-06-18 12:09:54.013258763 +0200
@@ -19,31 +19,14 @@
        movapd  .LC2(%rip), %xmm0
        movaps  %xmm0, s2(%rip)
        movaps  %xmm0, s2+16(%rip)
-       movapd  s2(%rip), %xmm3
-       movapd  s1(%rip), %xmm2
-       movapd  .LC3(%rip), %xmm1
-       movapd  s2+16(%rip), %xmm6
-       movaps  %xmm3, 48(%rsp)
-       movapd  48(%rsp), %xmm0
-       movapd  s1+16(%rip), %xmm5
-       movaps  %xmm2, 32(%rsp)
-       cmpnltpd        32(%rsp), %xmm0
-       movaps  %xmm6, 80(%rsp)
-       movaps  %xmm5, 64(%rsp)
-       andnpd  %xmm1, %xmm0
-       movaps  %xmm0, 16(%rsp)
-       movapd  80(%rsp), %xmm0
-       movapd  16(%rsp), %xmm4
-       cmpnltpd        64(%rsp), %xmm0
-       movaps  %xmm4, s3(%rip)
-       andnpd  %xmm1, %xmm0
-       movaps  %xmm0, 96(%rsp)
-       movsd   24(%rsp), %xmm0
-       movapd  96(%rsp), %xmm7
+       movsd   56(%rsp), %xmm0
+       movapd  48(%rsp), %xmm1
+       movapd  96(%rsp), %xmm2
        movsd   %xmm0, 8(%rsp)
        movsd   .LC4(%rip), %xmm0
        ucomisd 8(%rsp), %xmm0
-       movaps  %xmm7, s3+16(%rip)
+       movaps  %xmm1, s3(%rip)
+       movaps  %xmm2, s3+16(%rip)
        jp      .L4
        comisd  8(%rsp), %xmm0
        jne     .L4
@@ -107,16 +90,10 @@
        .long   1075052544
        .long   0
        .long   1075052544
-       .align 16
-.LC3:
-       .long   0
-       .long   -1074790400
-       .long   0
-       .long   -1074790400
        .section        .rodata.cst8,"aM",@progbits,8
        .align 8
 .LC4:
        .long   0
        .long   -1074790400
-       .ident  "GCC: (SUSE Linux) 10.1.1 20200507 [revision
dd38686d9c810cecbaa80bb82ed91caaa58ad635]"
+       .ident  "GCC: (GNU) 11.0.0 20200618 (experimental)"
        .section        .note.GNU-stack,"",@progbits

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

* [Bug tree-optimization/95739] [11 Regression] Unordered comparison and VEC_COND_EXPR
  2020-06-18 10:11 [Bug tree-optimization/95739] New: [11 Regression] Unordered comparison and VEC_COND_EXPR marxin at gcc dot gnu.org
@ 2020-06-18 10:12 ` marxin at gcc dot gnu.org
  2020-06-18 11:37 ` [Bug middle-end/95739] " rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-06-18 10:12 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-06-18

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
@Richi: Do you have a hint what went wrong?

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

* [Bug middle-end/95739] [11 Regression] Unordered comparison and VEC_COND_EXPR
  2020-06-18 10:11 [Bug tree-optimization/95739] New: [11 Regression] Unordered comparison and VEC_COND_EXPR marxin at gcc dot gnu.org
  2020-06-18 10:12 ` [Bug tree-optimization/95739] " marxin at gcc dot gnu.org
@ 2020-06-18 11:37 ` rguenth at gcc dot gnu.org
  2020-06-18 12:47 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-06-18 11:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |middle-end
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Hmm, the vectorizer emits

  vect_cst__41 = { 0.0, 0.0 };
  vect_cst__42 = { -1.0e+0, -1.0e+0 };
...
  vect__1.7_37 = MEM <vector(2) double> [(double *)vectp_s1.5_35];
  _1 = s1[i_23];
  vect__2.10_40 = MEM <vector(2) double> [(double *)vectp_s2.8_38];
  _2 = s2[i_23];
  _43 = vect__1.7_37 u<= vect__2.10_40;
  vect_iftmp.11_44 = VEC_COND_EXPR <_43, vect_cst__41, vect_cst__42>;
  iftmp.0_5 = _1 u<= _2 ? 0.0 : -1.0e+0;

but this is __builtin__isgreaterequal (s1[i], s2[i]) ? 0:0 : -1.0; already
this way from if-conversion it seems.  Before we have

  if (_1 u<= _2)
    goto <bb 10>; [50.00%]
  else
    goto <bb 4>; [50.00%]

  <bb 10> [local count: 429496729]:
  goto <bb 5>; [100.00%]

  <bb 4> [local count: 429496728]:

  <bb 5> [local count: 858993457]:
  # iftmp.0_5 = PHI <-1.0e+0(4), 0.0(10)>

And even .original:

    s3[i] = s1[i] u<= s2[i] ? 0.0 : -1.0e+0;

but that's the inverted condition plus swapped which should be u>=!?

Seemingly this is generated from

 /* !A ? B : C -> A ? C : B.  */
 (simplify
  (cnd (logical_inverted_value truth_valued_p@0) @1 @2)
  (cnd @0 @2 @1)))

fed by !(s1[i] u<= s2[i]) ? -1. : 0.  Hmm, which looks OK.

later the backend via ix86_prepare_sse_fp_compare_args correctly (!?)
swaps operands of the compare to s2[i] u>= s1[i].

Now somewhere things go wrong and the __builtin_isgreater vanishes completely,
leaving us with uninitialized stack slots:

main:
.LFB0:
        .cfi_startproc
        subq    $120, %rsp
        .cfi_def_cfa_offset 128
        movapd  .LC0(%rip), %xmm0
        movaps  %xmm0, s1(%rip)
        movapd  .LC1(%rip), %xmm0
        movaps  %xmm0, s1+16(%rip)
        movapd  .LC2(%rip), %xmm0
        movaps  %xmm0, s2(%rip)
        movaps  %xmm0, s2+16(%rip)
        movsd   56(%rsp), %xmm0
        movapd  48(%rsp), %xmm1
        movapd  96(%rsp), %xmm2
        movsd   %xmm0, 8(%rsp)
        movsd   .LC4(%rip), %xmm0
        ucomisd 8(%rsp), %xmm0
        movaps  %xmm1, s3(%rip)
        movaps  %xmm2, s3+16(%rip)

I guess the issue is

   31: r104:V2DF=unge(r103:V2DF,[r77:DI-0x60])
   32: r101:V2DF=~r104:V2DF&r102:V2DF
   33: r105:DI=`s3'
   34: r106:V2DF=[r77:DI-0x40]
   35: [r105:DI]=r106:V2DF

look at how we compute the result into r101 but then use [r77:D1-0x40]
as source for the store.  When I trace expand_vect_cond_optab_fn
I see 'target' is expanded to

(mem/c:V2DF (plus:DI (reg/f:DI 77 virtual-stack-vars)
        (const_int -64 [0xffffffffffffffc0])) [1 vect_iftmp.11+0 S16 A128])

but we don't check whether ops[0].value matches target after expand_insn
and fail to move it there.

testing patch.

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

* [Bug middle-end/95739] [11 Regression] Unordered comparison and VEC_COND_EXPR
  2020-06-18 10:11 [Bug tree-optimization/95739] New: [11 Regression] Unordered comparison and VEC_COND_EXPR marxin at gcc dot gnu.org
  2020-06-18 10:12 ` [Bug tree-optimization/95739] " marxin at gcc dot gnu.org
  2020-06-18 11:37 ` [Bug middle-end/95739] " rguenth at gcc dot gnu.org
@ 2020-06-18 12:47 ` cvs-commit at gcc dot gnu.org
  2020-06-18 12:47 ` rguenth at gcc dot gnu.org
  2020-06-18 12:48 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-06-18 12:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

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

commit r11-1510-geccc3d432669ba272229d49f015cb986df21eb0a
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Jun 18 14:45:03 2020 +0200

    middle-end/95739 - fix vector condition IFN expansion

    This fixes the omission of moving the expansion result to the
    target.

    2020-06-18  Richard Biener  <rguenther@suse.de>

            PR middle-end/95739
            * internal-fn.c (expand_vect_cond_optab_fn): Move the result
            to the target if necessary.
            (expand_vect_cond_mask_optab_fn): Likewise.

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

* [Bug middle-end/95739] [11 Regression] Unordered comparison and VEC_COND_EXPR
  2020-06-18 10:11 [Bug tree-optimization/95739] New: [11 Regression] Unordered comparison and VEC_COND_EXPR marxin at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-06-18 12:47 ` cvs-commit at gcc dot gnu.org
@ 2020-06-18 12:47 ` rguenth at gcc dot gnu.org
  2020-06-18 12:48 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-06-18 12:47 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.

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

* [Bug middle-end/95739] [11 Regression] Unordered comparison and VEC_COND_EXPR
  2020-06-18 10:11 [Bug tree-optimization/95739] New: [11 Regression] Unordered comparison and VEC_COND_EXPR marxin at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2020-06-18 12:47 ` rguenth at gcc dot gnu.org
@ 2020-06-18 12:48 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-06-18 12:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.0

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

end of thread, other threads:[~2020-06-18 12:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-18 10:11 [Bug tree-optimization/95739] New: [11 Regression] Unordered comparison and VEC_COND_EXPR marxin at gcc dot gnu.org
2020-06-18 10:12 ` [Bug tree-optimization/95739] " marxin at gcc dot gnu.org
2020-06-18 11:37 ` [Bug middle-end/95739] " rguenth at gcc dot gnu.org
2020-06-18 12:47 ` cvs-commit at gcc dot gnu.org
2020-06-18 12:47 ` rguenth at gcc dot gnu.org
2020-06-18 12:48 ` rguenth 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).