The shift count was 31 under an int32 requirement, which left the rule
untested on every other int width.
Tested on x86_64-pc-linux-gnu, aarch64-linux-gnu and arm-none-eabi
(cortex-m0 soft).
Assisted-by: Claude Opus 5 (Anthropic)
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/minmax-swar-1.c: Derive the shift count from
sizeof (int); drop the int32 requirement.
* gcc.dg/tree-ssa/minmax-swar-2.c: Likewise.
Signed-off-by: Dominic P <[email protected]>
---
gcc/testsuite/gcc.dg/tree-ssa/minmax-swar-1.c | 20 ++++++++++---------
gcc/testsuite/gcc.dg/tree-ssa/minmax-swar-2.c | 7 ++++---
2 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-swar-1.c
b/gcc/testsuite/gcc.dg/tree-ssa/minmax-swar-1.c
index 53bf1242cb8..1c7395af1d4 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-swar-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-swar-1.c
@@ -1,47 +1,49 @@
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-forwprop1 -fdump-tree-optimized" } */
-/* { dg-require-effective-target int32 } */
+
+#define SHIFT (sizeof (int) * __CHAR_BIT__ - 1)
/* The branchless min and max that x264's x264_median writes. The existing
- rule turns x & (x >> 31) into MIN <x, 0>; these have to finish the job. */
+ rule turns x & (x >> (precision - 1)) into MIN <x, 0>; these have to finish
+ the job. */
int
swar_min (int a, int b)
{
int t = a - b;
- return b + (t & (t >> 31));
+ return b + (t & (t >> SHIFT));
}
int
swar_max (int a, int b)
{
int t = a - b;
- return a - (t & (t >> 31));
+ return a - (t & (t >> SHIFT));
}
int
swar_min_not (int a, int b)
{
int t = a - b;
- return a - (t & ~(t >> 31));
+ return a - (t & ~(t >> SHIFT));
}
int
swar_max_not (int a, int b)
{
int t = a - b;
- return b + (t & ~(t >> 31));
+ return b + (t & ~(t >> SHIFT));
}
/* Both uses of the one difference have to fold. */
int
swar_median (int a, int b, int c)
{
- int t = (a - b) & ((a - b) >> 31);
+ int t = (a - b) & ((a - b) >> SHIFT);
a -= t;
b += t;
- b -= (b - c) & ((b - c) >> 31);
- b += (a - b) & ((a - b) >> 31);
+ b -= (b - c) & ((b - c) >> SHIFT);
+ b += (a - b) & ((a - b) >> SHIFT);
return b;
}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-swar-2.c
b/gcc/testsuite/gcc.dg/tree-ssa/minmax-swar-2.c
index b600d69207e..0066b185abf 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/minmax-swar-2.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-swar-2.c
@@ -1,6 +1,7 @@
/* { dg-do compile } */
/* { dg-options "-O2 -fwrapv -fdump-tree-optimized" } */
-/* { dg-require-effective-target int32 } */
+
+#define SHIFT (sizeof (int) * __CHAR_BIT__ - 1)
/* With a wrapping difference the identity fails: for a = INT_MIN, b = 1 the
difference wraps positive and the branchless form returns b. The inner
@@ -11,14 +12,14 @@ int
swar_min (int a, int b)
{
int t = a - b;
- return b + (t & (t >> 31));
+ return b + (t & (t >> SHIFT));
}
int
swar_max (int a, int b)
{
int t = a - b;
- return a - (t & (t >> 31));
+ return a - (t & (t >> SHIFT));
}
/* { dg-final { scan-tree-dump-times "MIN_EXPR <\[^,\]*, 0>" 2 "optimized" } }
*/
--
2.55.0