This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: PR target/53416: Wrong code when optimising loop involving _rdrand32_step


On Sun, May 20, 2012 at 11:37 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Sun, May 20, 2012 at 11:15 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>> On Sun, May 20, 2012 at 10:37:13AM -0700, H.J. Lu wrote:
>>> On Sun, May 20, 2012 at 10:19 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>>> > On Sun, May 20, 2012 at 10:04:26AM -0700, H.J. Lu wrote:
>>> >> rdrand<mode>_1 must be marked with unspec_volatile since it returns
>>> >> a different value every time. ÂOK for trunk, 4.7 and 4.6?
>>> >
>>> > A testcase for this would be nice (runtime is not possible, since the
>>> > RNG in theory could return the same value twice, but scanning assembly
>>> > for a particular number of the rdrand insns would be nice).
>>> >
>>>
>>> For
>>>
>>> Âunsigned int number = 0;
>>> Âvolatile int result = 0;
>>>
>>> Âfor (register int i = 0; i < 4; ++i) {
>>> Â result = _rdrand32_step(&number);
>>> Â printf("%d: %d\n", result, number);
>>> Â}
>>
>> Try it without the loop, unroll it by hand, see if without the patch
>> the rdrand insns are still CSEd together?
>>
>
> It doesn't:
>
> [hjl@gnu-ivb-1 tmp]$ cat x.c
> #include <stdio.h>
>
> int
> main(int argc, char **argv)
> {
> Âunsigned int number = 0;
> Âvolatile int result = 0;
>
> Âresult = __builtin_ia32_rdrand32_step (&number);
> Âprintf("%d: %d\n", result, number);
> Âresult = __builtin_ia32_rdrand32_step (&number);
> Âprintf("%d: %d\n", result, number);
> Âresult = __builtin_ia32_rdrand32_step (&number);
> Âprintf("%d: %d\n", result, number);
> Âresult = __builtin_ia32_rdrand32_step (&number);
> Âprintf("%d: %d\n", result, number);
> Âreturn 0;
> }
> [hjl@gnu-ivb-1 tmp]$
> /export/gnu/import/git/gcc-regression/master/187369/usr/bin/gcc
> -mrdrnd -O3 -S x.c
> [hjl@gnu-ivb-1 tmp]$ grep rdrand x.s
> Â Â Â Ârdrand Â%ebx
> Â Â Â Ârdrand Â%eax
> Â Â Â Ârdrand Â%eax
> Â Â Â Ârdrand Â%eax
> [hjl@gnu-ivb-1 tmp]$

Try:
#include <stdio.h>

 int
 main(int argc, char **argv)
 {
  unsigned int number = 0;
  int result0, result1, result2, result3;

  result0 = __builtin_ia32_rdrand32_step (&number);
  result1 = __builtin_ia32_rdrand32_step (&number);
  result2 = __builtin_ia32_rdrand32_step (&number);
  result3 = __builtin_ia32_rdrand32_step (&number);
  printf("%d: %d\n", result0, number);
  printf("%d: %d\n", result1, number);
  printf("%d: %d\n", result2, number);
  printf("%d: %d\n", result3, number);
  return 0;
 }

Which I Know for a fact fails before the patch:
pinskia@server:~$ grep rdrand t.s
	rdrand	%edx
pinskia@server:~$

Thanks,
Andrew Pinski

>
>
> --
> H.J.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]