middle-end: fix min/max phiopts reduction [PR106744]
authorTamar Christina <tamar.christina@arm.com>
Tue, 30 Aug 2022 06:49:02 +0000 (07:49 +0100)
committerTamar Christina <tamar.christina@arm.com>
Tue, 30 Aug 2022 06:49:02 +0000 (07:49 +0100)
This corrects the argument usage to use them in the order that they occur in
the comparisons in gimple.

gcc/ChangeLog:

PR tree-optimization/106744
* tree-ssa-phiopt.cc (minmax_replacement): Correct arguments.

gcc/testsuite/ChangeLog:

PR tree-optimization/106744
* gcc.dg/tree-ssa/minmax-10.c: Make runtime test.
* gcc.dg/tree-ssa/minmax-11.c: Likewise.
* gcc.dg/tree-ssa/minmax-12.c: Likewise.
* gcc.dg/tree-ssa/minmax-13.c: Likewise.
* gcc.dg/tree-ssa/minmax-14.c: Likewise.
* gcc.dg/tree-ssa/minmax-15.c: Likewise.
* gcc.dg/tree-ssa/minmax-16.c: Likewise.
* gcc.dg/tree-ssa/minmax-3.c: Likewise.
* gcc.dg/tree-ssa/minmax-4.c: Likewise.
* gcc.dg/tree-ssa/minmax-5.c: Likewise.
* gcc.dg/tree-ssa/minmax-6.c: Likewise.
* gcc.dg/tree-ssa/minmax-7.c: Likewise.
* gcc.dg/tree-ssa/minmax-8.c: Likewise.
* gcc.dg/tree-ssa/minmax-9.c: Likewise.

15 files changed:
gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c
gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c
gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c
gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c
gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c
gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c
gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c
gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c
gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c
gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c
gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c
gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c
gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c
gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c
gcc/tree-ssa-phiopt.cc

index 5899536..c9322a1 100644 (file)
@@ -1,8 +1,9 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O -fdump-tree-optimized" } */
 
 #include <stdint.h>
 
+__attribute__ ((noipa, noinline))
 uint8_t three_max (uint8_t xc, uint8_t xm, uint8_t xy) {
     uint8_t     xk;
     xc=~xc;
@@ -16,5 +17,16 @@ uint8_t three_max (uint8_t xc, uint8_t xm, uint8_t xy) {
     return xk;
 }
 
+int
+main (void)
+{
+  volatile uint8_t xy = 255;
+  volatile uint8_t xm = 0;
+  volatile uint8_t xc = 127;
+  if (three_max (xc, xm, xy) != 255)
+    __builtin_abort ();
+  return 0;
+}
+
 /* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "= ~" 1 "optimized" } } */
index 1c2ef01..b1da417 100644 (file)
@@ -1,8 +1,10 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O -fdump-tree-optimized" } */
 
 #include <stdint.h>
 
+
+__attribute__ ((noipa, noinline))
 uint8_t three_minmax1 (uint8_t xc, uint8_t xm, uint8_t xy) {
        uint8_t  xk;
     xc=~xc;
@@ -16,6 +18,17 @@ uint8_t three_minmax1 (uint8_t xc, uint8_t xm, uint8_t xy) {
     return xk;
 }
 
+int
+main (void)
+{
+  volatile uint8_t xy = 255;
+  volatile uint8_t xm = 0;
+  volatile uint8_t xc = 127;
+  if (three_minmax1 (xc, xm, xy) != 0)
+    __builtin_abort ();
+  return 0;
+}
+
 /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "= ~" 1 "optimized" } } */
index 3d0c07d..cb9188f 100644 (file)
@@ -1,8 +1,9 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O -fdump-tree-phiopt" } */
 
 #include <stdint.h>
 
+__attribute__ ((noinline, noipa))
 uint8_t three_minmax3 (uint8_t xc, uint8_t xm, uint8_t xy) {
         uint8_t  xk;
     xc=~xc;
@@ -16,5 +17,16 @@ uint8_t three_minmax3 (uint8_t xc, uint8_t xm, uint8_t xy) {
     return xk;
 }
 
+int
+main (void)
+{
+  volatile uint8_t xy = 255;
+  volatile uint8_t xm = 0;
+  volatile uint8_t xc = 127;
+  if (three_minmax3 (xc, xm, xy) != 0)
+    __builtin_abort ();
+  return 0;
+}
+
 /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */
 /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */
index c0d0f27..62ba71e 100644 (file)
@@ -1,8 +1,9 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O -fdump-tree-phiopt" } */
 
 #include <stdint.h>
 
+__attribute__ ((noipa, noinline))
 uint8_t three_minmax2 (uint8_t xc, uint8_t xm, uint8_t xy) {
        uint8_t  xk;
     xc=~xc;
@@ -15,5 +16,17 @@ uint8_t three_minmax2 (uint8_t xc, uint8_t xm, uint8_t xy) {
     }
     return xk;
 }
+
+int
+main (void)
+{
+  volatile uint8_t xy = 255;
+  volatile uint8_t xm = 127;
+  volatile uint8_t xc = 0;
+  if (three_minmax2 (xc, xm, xy) != 255)
+    __builtin_abort ();
+  return 0;
+}
+
 /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */
 /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */
index 9c0cadb..a3ec584 100644 (file)
@@ -1,8 +1,9 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O -fdump-tree-optimized" } */
 
 #include <stdint.h>
 
+__attribute__ ((noipa, noinline))
 uint8_t three_minmax11 (uint8_t xc, uint8_t xm, uint8_t xy) {
         uint8_t  xk;
     xc=~xc;
@@ -16,6 +17,17 @@ uint8_t three_minmax11 (uint8_t xc, uint8_t xm, uint8_t xy) {
     return xk;
 }
 
+int
+main (void)
+{
+  volatile uint8_t xy = 255;
+  volatile uint8_t xm = 0;
+  volatile uint8_t xc = 127;
+  if (three_minmax11 (xc, xm, xy) != 128)
+    __builtin_abort ();
+  return 0;
+}
+
 /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "= ~" 1 "optimized" } } */
index 1d97a16..8a39871 100644 (file)
@@ -1,10 +1,11 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O -fdump-tree-phiopt" } */
 
 #include <stdint.h>
 #include <stdbool.h>
 
-uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy, bool m) {
+__attribute__ ((noinline, noipa))
+uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy) {
     uint8_t  xk;
     if (xc)
       {
@@ -17,5 +18,17 @@ uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy, bool m) {
 
     return xk;
 }
+
+int
+main (void)
+{
+  volatile uint8_t xy = 255;
+  volatile uint8_t xm = 0;
+  volatile uint8_t xc = 127;
+  if (three_min (xc, xm, xy) != 0)
+    __builtin_abort ();
+  return 0;
+}
+
 /* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */
 /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */
index 89377a2..4febd09 100644 (file)
@@ -1,8 +1,9 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O -fdump-tree-phiopt -g" } */
 
 #include <stdint.h>
 
+__attribute__ ((noipa, noinline))
 uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy) {
        uint8_t  xk;
     if (xc < xm) {
@@ -13,5 +14,16 @@ uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy) {
     return xk;
 }
 
+int
+main (void)
+{
+  volatile uint8_t xy = 255;
+  volatile uint8_t xm = 0;
+  volatile uint8_t xc = 127;
+  if (three_min (xc, xm, xy) != 0)
+    __builtin_abort ();
+  return 0;
+}
+
 /* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */
 /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */
index de3b2e9..2af1077 100644 (file)
@@ -1,8 +1,9 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O -fdump-tree-phiopt" } */
 
 #include <stdint.h>
 
+__attribute__ ((noipa, noinline))
 uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy) {
        uint8_t  xk;
     if (xc < xm) {
@@ -13,5 +14,16 @@ uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy) {
     return xk;
 }
 
+int
+main (void)
+{
+  volatile uint8_t xy = 255;
+  volatile uint8_t xm = 0;
+  volatile uint8_t xc = 127;
+  if (three_min (xc, xm, xy) != 0)
+    __builtin_abort ();
+  return 0;
+}
+
 /* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */
 /* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */
index 0b6d667..973f39b 100644 (file)
@@ -1,8 +1,9 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O -fdump-tree-phiopt" } */
 
 #include <stdint.h>
 
+__attribute__ ((noipa, noinline))
 uint8_t three_max (uint8_t xc, uint8_t xm, uint8_t xy) {
     uint8_t     xk;
     if (xc > xm) {
@@ -13,5 +14,16 @@ uint8_t three_max (uint8_t xc, uint8_t xm, uint8_t xy) {
     return xk;
 }
 
+int
+main (void)
+{
+  volatile uint8_t xy = 255;
+  volatile uint8_t xm = 0;
+  volatile uint8_t xc = 127;
+  if (three_max (xc, xm, xy) != 255)
+    __builtin_abort ();
+  return 0;
+}
+
 /* { dg-final { scan-tree-dump-times "MIN_EXPR" 0 "phiopt1" } } */
 /* { dg-final { scan-tree-dump-times "MAX_EXPR" 3 "phiopt1" } } */
index 650601a..34e4e72 100644 (file)
@@ -1,8 +1,9 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O -fdump-tree-phiopt" } */
 
 #include <stdint.h>
 
+__attribute__ ((noipa, noinline))
 uint8_t three_minmax1 (uint8_t xc, uint8_t xm, uint8_t xy) {
        uint8_t  xk;
     if (xc > xm) {
@@ -13,5 +14,16 @@ uint8_t three_minmax1 (uint8_t xc, uint8_t xm, uint8_t xy) {
     return xk;
 }
 
+int
+main (void)
+{
+  volatile uint8_t xy = 255;
+  volatile uint8_t xm = 0;
+  volatile uint8_t xc = 127;
+  if (three_minmax1 (xc, xm, xy) != 127)
+    __builtin_abort ();
+  return 0;
+}
+
 /* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "phiopt1" } } */
 /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */
index a628f6d..443d68f 100644 (file)
@@ -1,8 +1,9 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O -fdump-tree-phiopt" } */
 
 #include <stdint.h>
 
+__attribute__ ((noipa, noinline))
 uint8_t three_minmax3 (uint8_t xc, uint8_t xm, uint8_t xy) {
         uint8_t  xk;
     if (xc > xm) {
@@ -13,5 +14,16 @@ uint8_t three_minmax3 (uint8_t xc, uint8_t xm, uint8_t xy) {
     return xk;
 }
 
+int
+main (void)
+{
+  volatile uint8_t xy = 255;
+  volatile uint8_t xm = 0;
+  volatile uint8_t xc = 127;
+  if (three_minmax3 (xc, xm, xy) != 255)
+    __builtin_abort ();
+  return 0;
+}
+
 /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */
 /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */
index cb42412..7e2a3f0 100644 (file)
@@ -1,8 +1,9 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O -fdump-tree-phiopt" } */
 
 #include <stdint.h>
 
+__attribute__ ((noipa, noinline))
 uint8_t three_minmax2 (uint8_t xc, uint8_t xm, uint8_t xy) {
        uint8_t  xk;
     if (xc > xm) {
@@ -12,5 +13,17 @@ uint8_t three_minmax2 (uint8_t xc, uint8_t xm, uint8_t xy) {
     }
     return xk;
 }
+
+int
+main (void)
+{
+  volatile uint8_t xy = 255;
+  volatile uint8_t xm = 0;
+  volatile uint8_t xc = 127;
+  if (three_minmax2 (xc, xm, xy) != 255)
+    __builtin_abort ();
+  return 0;
+}
+
 /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */
 /* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "phiopt1" } } */
index 9cd050e..0160e57 100644 (file)
@@ -1,8 +1,9 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O -fdump-tree-phiopt" } */
 
 #include <stdint.h>
 
+__attribute__ ((noinline, noipa))
 uint8_t three_minmax11 (uint8_t xc, uint8_t xm, uint8_t xy) {
         uint8_t  xk;
     if (xc < xm) {
@@ -13,5 +14,16 @@ uint8_t three_minmax11 (uint8_t xc, uint8_t xm, uint8_t xy) {
     return xk;
 }
 
+int
+main (void)
+{
+  volatile uint8_t xy = 255;
+  volatile uint8_t xm = 0;
+  volatile uint8_t xc = 127;
+  if (three_minmax11 (xc, xm, xy) != 255)
+    __builtin_abort ();
+  return 0;
+}
+
 /* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "phiopt1" } } */
 /* { dg-final { scan-tree-dump-times "MAX_EXPR" 2 "phiopt1" } } */
index 24f5802..0cfb658 100644 (file)
@@ -1,8 +1,9 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O -fdump-tree-optimized" } */
 
 #include <stdint.h>
 
+__attribute__ ((noipa, noinline))
 uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy) {
        uint8_t  xk;
     xc=~xc;
@@ -16,5 +17,16 @@ uint8_t three_min (uint8_t xc, uint8_t xm, uint8_t xy) {
     return xk;
 }
 
+int
+main (void)
+{
+  volatile uint8_t xy = 255;
+  volatile uint8_t xm = 0;
+  volatile uint8_t xc = 127;
+  if (three_min (xc, xm, xy) != 0)
+    __builtin_abort ();
+  return 0;
+}
+
 /* { dg-final { scan-tree-dump-times "= ~" 1 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "MAX_EXPR" 2 "optimized" } } */
index d5f2ba8..925bd7d 100644 (file)
@@ -2150,9 +2150,9 @@ minmax_replacement (basic_block cond_bb, basic_block middle_bb, basic_block alt_
       gimple_seq stmts = NULL;
       tree phi_result = PHI_RESULT (phi);
       result = gimple_build (&stmts, locus, minmax, TREE_TYPE (phi_result),
-                            arg0, bound);
+                            arg0, arg1);
       result = gimple_build (&stmts, locus, ass_code, TREE_TYPE (phi_result),
-                            result, arg1);
+                            result, bound);
       if (invert)
        result = gimple_build (&stmts, locus, BIT_NOT_EXPR, TREE_TYPE (phi_result),
                               result);