diff mbox series

middle-end: fix min/max phiopts reduction [PR106744]

Message ID patch-16177-tamar@arm.com
State New
Headers show
Series middle-end: fix min/max phiopts reduction [PR106744] | expand

Commit Message

Tamar Christina Aug. 30, 2022, 6:35 a.m. UTC
Hi All,

This corrects the argument usage to use them in the order that they occur in
the comparisons in gimple.

This was tested by disabling the pass, adding the runtime checks and re-enabling
the pass and verifying the tests still pass.

Also tested that the runtime test caught the issue by updating the tests on an
unpatched tree and observing that some fail.

Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.

Ok for master?

Thanks,
Tamar

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.

--- inline copy of patch -- 
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c
index 589953684416a9d263084deb58f6cde7094dd517..c9322a17a4af8e01add2f04176805c812af62e07 100644




--
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c
index 589953684416a9d263084deb58f6cde7094dd517..c9322a17a4af8e01add2f04176805c812af62e07 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c
index 1c2ef01b5d1e639fbf95bb5ca473b63cc98e9df1..b1da41712b342cd7344167a0da91ffd419491391 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c
index 3d0c07d9b57dd689bcb89653937727ab441e7f2b..cb9188f90e8e12c6244d559e63723177102177ee 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c
index c0d0f27c8027ae87654532d1b919cfeccf4413e0..62ba71e8c3f21f1cb33ae2473fd2b30bfdc13c81 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c
index 9c0cadbf7e3119527cb2007d01fe4c7dd772c069..a3ec58460838ebbcfa5451a2471dde07608a38e3 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c
index 1d97a16564f069b4348ff325c4fd713a224f838a..8a39871c93890b553dc8d4aed494c2f14f8508fe 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c
index 89377a2cb341bdafa6ba145c61c1f966af536839..4febd092d837542017438bcc4f8554fdb05c4adf 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c
index de3b2e946e81701e3b75f580e6a843695a05786e..2af107763469cd16401b618f0e6b556e5ac2b04d 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c
index 0b6d667be868c2405eaefd17cb522da44bafa0e2..973f39bfed305d636cd7290ab5dbb726d6d75f12 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c
index 650601a3cc75d09a9e6e54a35f5b9993074f8510..34e4e7205111b6c3e28fbe7c8cde85740ac52630 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c
index a628f6d99222958cfd8c410f0e85639e3a49dd4b..443d68f826db91118ff8fa4f62333f660fdf5546 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c
index cb42412c4ada433b2f59df0a8bef9fa7b1c5e104..7e2a3f08060bc84f33ad416a4c89d0ef74dc9cb3 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c
index 9cd050e932376bc50bd6ae60cb654fcab0bfdd1c..0160e573fef8aba106d4f8ef86b5c958ab52cb30 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c
index 24f580271c3ac3945860b506d4dc7d178a826093..0cfb65845889af4f25f7c6c57264617a72cda0ad 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c
@@ -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" } } */
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index d5f2ba8be1c33e3ea441a61e9dbf8867aee93a98..925bd7d885357dce114a9b29176d953e30ae3b4d 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -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);

Comments

Richard Biener Aug. 30, 2022, 6:46 a.m. UTC | #1
On Tue, 30 Aug 2022, Tamar Christina wrote:

> Hi All,
> 
> This corrects the argument usage to use them in the order that they occur in
> the comparisons in gimple.
> 
> This was tested by disabling the pass, adding the runtime checks and re-enabling
> the pass and verifying the tests still pass.
> 
> Also tested that the runtime test caught the issue by updating the tests on an
> unpatched tree and observing that some fail.
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> 
> Ok for master?

OK.
 
> Thanks,
> Tamar
> 
> 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.
> 
> --- inline copy of patch -- 
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c
> index 589953684416a9d263084deb58f6cde7094dd517..c9322a17a4af8e01add2f04176805c812af62e07 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c
> index 1c2ef01b5d1e639fbf95bb5ca473b63cc98e9df1..b1da41712b342cd7344167a0da91ffd419491391 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c
> index 3d0c07d9b57dd689bcb89653937727ab441e7f2b..cb9188f90e8e12c6244d559e63723177102177ee 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c
> index c0d0f27c8027ae87654532d1b919cfeccf4413e0..62ba71e8c3f21f1cb33ae2473fd2b30bfdc13c81 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c
> index 9c0cadbf7e3119527cb2007d01fe4c7dd772c069..a3ec58460838ebbcfa5451a2471dde07608a38e3 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c
> index 1d97a16564f069b4348ff325c4fd713a224f838a..8a39871c93890b553dc8d4aed494c2f14f8508fe 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c
> index 89377a2cb341bdafa6ba145c61c1f966af536839..4febd092d837542017438bcc4f8554fdb05c4adf 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c
> index de3b2e946e81701e3b75f580e6a843695a05786e..2af107763469cd16401b618f0e6b556e5ac2b04d 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c
> index 0b6d667be868c2405eaefd17cb522da44bafa0e2..973f39bfed305d636cd7290ab5dbb726d6d75f12 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c
> index 650601a3cc75d09a9e6e54a35f5b9993074f8510..34e4e7205111b6c3e28fbe7c8cde85740ac52630 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c
> index a628f6d99222958cfd8c410f0e85639e3a49dd4b..443d68f826db91118ff8fa4f62333f660fdf5546 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c
> index cb42412c4ada433b2f59df0a8bef9fa7b1c5e104..7e2a3f08060bc84f33ad416a4c89d0ef74dc9cb3 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c
> index 9cd050e932376bc50bd6ae60cb654fcab0bfdd1c..0160e573fef8aba106d4f8ef86b5c958ab52cb30 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c
> index 24f580271c3ac3945860b506d4dc7d178a826093..0cfb65845889af4f25f7c6c57264617a72cda0ad 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c
> @@ -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" } } */
> diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
> index d5f2ba8be1c33e3ea441a61e9dbf8867aee93a98..925bd7d885357dce114a9b29176d953e30ae3b4d 100644
> --- a/gcc/tree-ssa-phiopt.cc
> +++ b/gcc/tree-ssa-phiopt.cc
> @@ -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);
> 
> 
> 
> 
>
diff mbox series

Patch

--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-10.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c
index 1c2ef01b5d1e639fbf95bb5ca473b63cc98e9df1..b1da41712b342cd7344167a0da91ffd419491391 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-11.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c
index 3d0c07d9b57dd689bcb89653937727ab441e7f2b..cb9188f90e8e12c6244d559e63723177102177ee 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-12.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c
index c0d0f27c8027ae87654532d1b919cfeccf4413e0..62ba71e8c3f21f1cb33ae2473fd2b30bfdc13c81 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-13.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c
index 9c0cadbf7e3119527cb2007d01fe4c7dd772c069..a3ec58460838ebbcfa5451a2471dde07608a38e3 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-14.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c
index 1d97a16564f069b4348ff325c4fd713a224f838a..8a39871c93890b553dc8d4aed494c2f14f8508fe 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-15.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c
index 89377a2cb341bdafa6ba145c61c1f966af536839..4febd092d837542017438bcc4f8554fdb05c4adf 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-16.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c
index de3b2e946e81701e3b75f580e6a843695a05786e..2af107763469cd16401b618f0e6b556e5ac2b04d 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-3.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c
index 0b6d667be868c2405eaefd17cb522da44bafa0e2..973f39bfed305d636cd7290ab5dbb726d6d75f12 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-4.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c
index 650601a3cc75d09a9e6e54a35f5b9993074f8510..34e4e7205111b6c3e28fbe7c8cde85740ac52630 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-5.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c
index a628f6d99222958cfd8c410f0e85639e3a49dd4b..443d68f826db91118ff8fa4f62333f660fdf5546 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-6.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c
index cb42412c4ada433b2f59df0a8bef9fa7b1c5e104..7e2a3f08060bc84f33ad416a4c89d0ef74dc9cb3 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-7.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c
index 9cd050e932376bc50bd6ae60cb654fcab0bfdd1c..0160e573fef8aba106d4f8ef86b5c958ab52cb30 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-8.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c
index 24f580271c3ac3945860b506d4dc7d178a826093..0cfb65845889af4f25f7c6c57264617a72cda0ad 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-9.c
@@ -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" } } */
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index d5f2ba8be1c33e3ea441a61e9dbf8867aee93a98..925bd7d885357dce114a9b29176d953e30ae3b4d 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -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);