diff mbox

Adjust builtin-bswap-6/7

Message ID 20140404161818.GA26795@bart
State New
Headers show

Commit Message

Andreas Krebbel April 4, 2014, 4:18 p.m. UTC
Hi,

the attached patch modifies the builtin-bswap-6/7 testcases in order
to prevent GCC from using math instead of a compare.  Only with a
compare the folding in combine actually takes place.

Whether the return value is produce with a compare or not depends
again on the value of branch cost.

Ideally we would be able to do the folding also with the math trick
but it is probably not that easy since we have already lost the
information that in the end all we need is a 0 or a 1.

Ok?

Bye,

-Andreas-

2014-04-04  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>

	* gcc.dg/builtin-bswap-6.c: Adjust return value to disable GCC
	optimization.
	* gcc.dg/builtin-bswap-7.c: Likewise.

Comments

Jeff Law April 4, 2014, 5:51 p.m. UTC | #1
On 04/04/14 10:18, Andreas Krebbel wrote:
> Hi,
>
> the attached patch modifies the builtin-bswap-6/7 testcases in order
> to prevent GCC from using math instead of a compare.  Only with a
> compare the folding in combine actually takes place.
>
> Whether the return value is produce with a compare or not depends
> again on the value of branch cost.
>
> Ideally we would be able to do the folding also with the math trick
> but it is probably not that easy since we have already lost the
> information that in the end all we need is a 0 or a 1.
>
> Ok?
>
> Bye,
>
> -Andreas-
>
> 2014-04-04  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>
>
> 	* gcc.dg/builtin-bswap-6.c: Adjust return value to disable GCC
> 	optimization.
> 	* gcc.dg/builtin-bswap-7.c: Likewise.
OK.
Jeff
Richard Biener April 7, 2014, 2:19 p.m. UTC | #2
On Fri, Apr 4, 2014 at 7:51 PM, Jeff Law <law@redhat.com> wrote:
> On 04/04/14 10:18, Andreas Krebbel wrote:
>>
>> Hi,
>>
>> the attached patch modifies the builtin-bswap-6/7 testcases in order
>> to prevent GCC from using math instead of a compare.  Only with a
>> compare the folding in combine actually takes place.
>>
>> Whether the return value is produce with a compare or not depends
>> again on the value of branch cost.
>>
>> Ideally we would be able to do the folding also with the math trick
>> but it is probably not that easy since we have already lost the
>> information that in the end all we need is a 0 or a 1.
>>
>> Ok?
>>
>> Bye,
>>
>> -Andreas-
>>
>> 2014-04-04  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>
>>
>>         * gcc.dg/builtin-bswap-6.c: Adjust return value to disable GCC
>>         optimization.
>>         * gcc.dg/builtin-bswap-7.c: Likewise.
>
> OK.

The adjusted testcases now fail on x86_64/i?86 at least.  See PR60776.

Richard.

> Jeff
>
diff mbox

Patch

diff --git a/gcc/testsuite/gcc.dg/builtin-bswap-6.c b/gcc/testsuite/gcc.dg/builtin-bswap-6.c
index 024ebf1..6f0c782 100644
--- a/gcc/testsuite/gcc.dg/builtin-bswap-6.c
+++ b/gcc/testsuite/gcc.dg/builtin-bswap-6.c
@@ -3,6 +3,10 @@ 
 /* { dg-options "-O -fdump-rtl-combine" } */
 /* { dg-options "-O -fdump-rtl-combine -march=z900" { target s390-*-* } } */
 
+/* The test intentionally returns 1/2 instead of the obvious 0/1 to
+   prevent GCC from calculating the return value with arithmetic
+   instead of a comparison.  */
+
 #include <stdint.h>
 
 #define BS(X) __builtin_bswap32(X)
@@ -11,28 +15,28 @@  int foo1 (uint32_t a)
 {
   if (BS (a) == 0xA0000)
     return 1;
-  return 0;
+  return 2;
 }
 
 int foo2 (uint32_t a)
 {
   if (BS (a) != 0xA0000)
     return 1;
-  return 0;
+  return 2;
 }
 
 int foo3 (uint32_t a, uint32_t b)
 {
   if (BS (a) == BS (b))
     return 1;
-  return 0;
+  return 2;
 }
 
 int foo4 (uint32_t a, uint32_t b)
 {
   if (BS (a) != BS (b))
     return 1;
-  return 0;
+  return 2;
 }
 
 /* { dg-final { scan-rtl-dump-not "bswapsi" "combine" } } */
diff --git a/gcc/testsuite/gcc.dg/builtin-bswap-7.c b/gcc/testsuite/gcc.dg/builtin-bswap-7.c
index 399b825..0eecdd8 100644
--- a/gcc/testsuite/gcc.dg/builtin-bswap-7.c
+++ b/gcc/testsuite/gcc.dg/builtin-bswap-7.c
@@ -3,6 +3,10 @@ 
 /* { dg-require-effective-target lp64 } */
 /* { dg-options "-O -fdump-rtl-combine" } */
 
+/* The test intentionally returns 1/2 instead of the obvious 0/1 to
+   prevent GCC from calculating the return value with arithmetic
+   instead of a comparison.  */
+
 #include <stdint.h>
 
 #define BS(X) __builtin_bswap64(X)
@@ -11,28 +15,28 @@  int foo1 (uint64_t a)
 {
   if (BS (a) == 0xA00000000)
     return 1;
-  return 0;
+  return 2;
 }
 
 int foo2 (uint64_t a)
 {
   if (BS (a) != 0xA00000000)
     return 1;
-  return 0;
+  return 2;
 }
 
 int foo3 (uint64_t a, uint64_t b)
 {
   if (BS (a) == BS (b))
     return 1;
-  return 0;
+  return 2;
 }
 
 int foo4 (uint64_t a, uint64_t b)
 {
   if (BS (a) != BS (b))
     return 1;
-  return 0;
+  return 2;
 }
 
 /* { dg-final { scan-rtl-dump-not "bswapdi" "combine" } } */