diff options
author | Roger Sayle <roger@nextmovesoftware.com> | 2020-08-10 21:09:16 +0100 |
---|---|---|
committer | Giuliano Belinassi <giuliano.belinassi@usp.br> | 2020-08-17 15:07:56 -0300 |
commit | 5634d8a9b56de06f9d4aab55543991a9f8b3db36 (patch) | |
tree | aa1eb77594f707eb122a128ee672f96956291ece /gcc/testsuite | |
parent | 753f39b848cb91d587fa13600f32e0673c416cc7 (diff) |
i386: Improve code generation of smin(x,0) with -m32.
To make amends for the recent (temporary) testsuite failure
of my new gcc.target/i386/minmax-9.c when compiled with -m32,
this patch improves the -m32 code we generate for the examples
in that test case.
The trick is to expand smin(x,0) as "x < 0 ? x : 0" instead
of the current "x <= 0 ? x : 0", as the former can take
advantage of sign_bit_mask operations.
2020-08-10 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
* config/i386/i386-expand.c (ix86_expand_int_movcc): Expand
signed MIN_EXPR against zero as "x < 0 ? x : 0" instead of
"x <= 0 ? x : 0" to enable sign_bit_compare_p optimizations.
gcc/testsuite/ChangeLog
* gcc.target/i386/minmax-12.c: New test.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/gcc.target/i386/minmax-12.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.target/i386/minmax-12.c b/gcc/testsuite/gcc.target/i386/minmax-12.c new file mode 100644 index 00000000000..40efe541e30 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/minmax-12.c @@ -0,0 +1,17 @@ +/* { dg-do compile { target ia32 } } */ +/* { dg-options "-O2 -march=i386 -mtune=generic" } */ + +#define min(a,b) (((a) < (b))? (a) : (b)) + +int foo(int x) +{ + return min(x,0); +} + +signed char bar(signed char x) +{ + return min(x,0); +} + +/* { dg-final { scan-assembler "cltd" } } */ +/* { dg-final { scan-assembler "sarb" } } */ |