Repository: pytorch
Issue: test_qnnpack_sigmoid failing on old CPU, built pytorch 1.5.0
Labels: module: binaries,module: build,triaged

## 🐛 Bug

Built from 1.5.0 source, tests fail with SIGILL illegal instruction on `test_type_conversions (__main__.TestAutograd)`. Import works. 
With same system/hardware, it works on 1.4.1.

Valgrind:
```
==1765222==
F...vex amd64->IR: unhandled instruction bytes: 0xC5 0xF1 0x57 0xC9 0x4D 0x1 0xEE 0x89 0xC0 0x49
vex amd64->IR:   REX=0 REX.W=0 REX.R=0 REX.X=0 REX.B=0
vex amd64->IR:   VEX=0 VEX.L=0 VEX.nVVVV=0x0 ESC=NONE
vex amd64->IR:   PFX.66=0 PFX.F2=0 PFX.F3=0
==1765222== valgrind: Unrecognised instruction at address 0x9a5df6f.
==1765222==    at 0x9A5DF6F: void c10::function_ref<void (char**, long const*, long)>::callback_fn<void at::native::(anonymous namespace)::cpu_serial_kernel<void at::native::templates::cpu::random_from_to_kernel<at::CPUGenerator>(at::TensorIterator&, unsigned long, long, at::CPUGenerator*)::{lambda()#1}::operator()() const::{lambda()#3}::operator()() const::{lambda()#2}>(at::TensorIterator&, void at::native::templates::cpu::random_from_to_kernel<at::CPUGenerator>(at::TensorIterator&, unsigned long, long, at::CPUGenerator*)::{lambda()#1}::operator()() const::{lambda()#3}::operator()() const::{lambda()#2}&&)::{lambda(char**, long const*, long)#1}>(long, char**, long const*, long) (in /home/samuel/.local/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so)
==1765222==    by 0x9544463: void c10::function_ref<void (char**, long const*, long, long)>::callback_fn<at::TensorIterator::serial_for_each(c10::function_ref<void (char**, long const*, long)>, at::Range) const::{lambda(char**, long const*, long, long)#1}>(long, char**, long const*,long, long) (in /home/samuel/.local/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so)
```

gdb disas:
```
Dump of assembler code for function _ZN3c1012function_refIFvPPcPKllEE11callback_fnIZN2at6native12_GLOBAL__N_117cpu_serial_kernelIZZZNS9_9templates3cpu21random_from_to_kernelINS8_12CPUGeneratorEEEvRNS8_14TensorIteratorEmlPT_ENKUlvE_clEvENKUlvE1_clEvEUlvE0_EEvSH_OSI_EUlS2_S4_lE_EEvlS2_S4_l:
   0x00007ffff158ded0 <+0>:↹····push   %r15
   0x00007ffff158ded2 <+2>:↹····push   %r14
   0x00007ffff158ded4 <+4>:↹····push   %r13
   0x00007ffff158ded6 <+6>:↹····push   %r12
   0x00007ffff158ded8 <+8>:↹····mov    %rcx,%r12
   0x00007ffff158dedb <+11>:↹···push   %rbp
   0x00007ffff158dedc <+12>:↹···mov    %rsi,%rbp
   0x00007ffff158dedf <+15>:↹···push   %rbx
   0x00007ffff158dee0 <+16>:↹···sub    $0x18,%rsp
   0x00007ffff158dee4 <+20>:↹···mov    (%rdx),%r15
   0x00007ffff158dee7 <+23>:↹···mov    (%rdi),%rbx
   0x00007ffff158deea <+26>:↹···cmp    $0x8,%r15
   0x00007ffff158deee <+30>:↹···je     0x7ffff158df50 <_ZN3c1012function_refIFvPPcPKllEE11callback_fnIZN2at6native12_GLOBAL__N_117cpu_serial_kernelIZZZNS9_9templates3cpu21random_from_to_kernelINS8_12CPUGeneratorEEEvRNS8_14TensorIteratorEmlPT_ENKUlvE_clEvENKUlvE1_clEvEUlvE0_EEvSH_OSI_EUlS2_S4_lE_EEvlS2_S4_l+128>
   0x00007ffff158def0 <+32>:↹···test   %rcx,%rcx
   0x00007ffff158def3 <+35>:↹···jle    0x7ffff158df3e <_ZN3c1012function_refIFvPPcPKllEE11callback_fnIZN2at6native12_GLOBAL__N_117cpu_serial_kernelIZZZNS9_9templates3cpu21random_from_to_kernelINS8_12CPUGeneratorEEEvRNS8_14TensorIteratorEmlPT_ENKUlvE_clEvENKUlvE1_clEvEUlvE0_EEvSH_OSI_EUlS2_S4_lE_EEvlS2_S4_l+110>
   0x00007ffff158def5 <+37>:↹···xor    %r14d,%r14d
   0x00007ffff158def8 <+40>:↹···xor    %r13d,%r13d
   0x00007ffff158defb <+43>:↹···nopl   0x0(%rax,%rax,1)
   0x00007ffff158df00 <+48>:↹···mov    0x0(%rbp),%rcx
   0x00007ffff158df04 <+52>:↹···mov    0x10(%rbx),%rdi
   0x00007ffff158df08 <+56>:↹···add    $0x1,%r13
   0x00007ffff158df0c <+60>:↹···add    %r14,%rcx
   0x00007ffff158df0f <+63>:↹···add    %r15,%r14
   0x00007ffff158df12 <+66>:↹···mov    %rcx,0x8(%rsp)
   0x00007ffff158df17 <+71>:↹···callq  0x7ffff02f1130 <_ZN2at12CPUGenerator6randomEv@plt>
   0x00007ffff158df1c <+76>:↹···xor    %edx,%edx
   0x00007ffff158df1e <+78>:↹···vxorpd %xmm2,%xmm2,%xmm2
   0x00007ffff158df22 <+82>:↹···mov    0x8(%rsp),%rcx
   0x00007ffff158df27 <+87>:↹···mov    %eax,%eax
   0x00007ffff158df29 <+89>:↹···divq   (%rbx)
   0x00007ffff158df2c <+92>:↹···add    0x8(%rbx),%rdx
   0x00007ffff158df30 <+96>:↹···vcvtsi2sd %rdx,%xmm2,%xmm0
   0x00007ffff158df35 <+101>:↹··vmovsd %xmm0,(%rcx)
   0x00007ffff158df39 <+105>:↹··cmp    %r13,%r12
   0x00007ffff158df3c <+108>:↹··jne    0x7ffff158df00 <_ZN3c1012function_refIFvPPcPKllEE11callback_fnIZN2at6native12_GLOBAL__N_117cpu_serial_kernelIZZZNS9_9templates3cpu21random_from_to_kernelINS8_12CPUGeneratorEEEvRNS8_14TensorIteratorEmlPT_ENKUlvE_clEvENKUlvE1_clEvEUlvE0_EEvSH_OSI_EUlS2_S4_lE_EEvlS2_S4_l+48>
   0x00007ffff158df3e <+110>:↹··add    $0x18,%rsp
   0x00007ffff158df42 <+114>:↹··pop    %rbx
   0x00007ffff158df43 <+115>:↹··pop    %rbp
   0x00007ffff158df44 <+116>:↹··pop    %r12
   0x00007ffff158df46 <+118>:↹··pop    %r13
   0x00007ffff158df48 <+120>:↹··pop    %r14
   0x00007ffff158df4a <+122>:↹··pop    %r15
   0x00007ffff158df4c <+124>:↹··retq
   0x00007ffff158df4d <+125>:↹··nopl   (%rax)
   0x00007ffff158df50 <+128>:↹··test   %rcx,%rcx
   0x00007ffff158df53 <+131>:↹··jle    0x7ffff158df3e <_ZN3c1012function_refIFvPPcPKllEE11callback_fnIZN2at6native12_GLOBAL__N_117cpu_serial_kernelIZZZNS9_9templates3cpu21random_from_to_kernelINS8_12CPUGeneratorEEEvRNS8_14TensorIteratorEmlPT_ENKUlvE_clEvENKUlvE1_clEvEUlvE0_EEvSH_OSI_EUlS2_S4_lE_EEvlS2_S4_l+110>
   0x00007ffff158df55 <+133>:↹··shl    $0x3,%r12
   0x00007ffff158df59 <+137>:↹··xor    %r13d,%r13d
   0x00007ffff158df5c <+140>:↹··nopl   0x0(%rax)
   0x00007ffff158df60 <+144>:↹··mov    0x10(%rbx),%rdi
   0x00007ffff158df64 <+148>:↹··mov    0x0(%rbp),%r14
   0x00007ffff158df68 <+152>:↹··callq  0x7ffff02f1130 <_ZN2at12CPUGenerator6randomEv@plt>
   0x00007ffff158df6d <+157>:↹··xor    %edx,%edx
=> 0x00007ffff158df6f <+159>:↹··vxorpd %xmm1,%xmm1,%xmm1
   0x00007ffff158df73 <+163>:↹··add    %r13,%r14
   0x00007ffff158df76 <+166>:↹··mov    %eax,%eax
   0x00007ffff158df78 <+168>:↹··add    $0x8,%r13
   0x00007ffff158df7c <+172>:↹··divq   (%rbx)
   0x00007ffff158df7f <+175>:↹··add    0x8(%rbx),%rdx
   0x00007ffff158df83 <+179>:↹··vcvtsi2sd %rdx,%xmm1,%xmm0
   0x00007ffff158df88 <+184>:↹··vmovsd %xmm0,(%r14)
   0x00007ffff158df8d <+189>:↹··cmp    %r12,%r13
   0x00007ffff158df90 <+192>:↹··jne    0x7ffff158df60 <_ZN3c1012function_refIFvPPcPKllEE11callback_fnIZN2at6native12_GLOBAL__N_117cpu_serial_kernelIZZZNS9_9templates3cpu21random_from_to_kernelINS8_12CPUGeneratorEEEvRNS8_14TensorIteratorEmlPT_ENKUlvE_clEvENKUlvE1_clEvEUlvE0_EEvSH_OSI_--Type <RET> for more, q to quit, c to continue without paging--c
EUlS2_S4_lE_EEvlS2_S4_l+144>
   0x00007ffff158df92 <+194>:↹··add    $0x18,%rsp
   0x00007ffff158df96 <+198>:↹··pop    %rbx
   0x00007ffff158df97 <+199>:↹··pop    %rbp
   0x00007ffff158df98 <+200>:↹··pop    %r12
   0x00007ffff158df9a <+202>:↹··pop    %r13
   0x00007ffff158df9c <+204>:↹··pop    %r14
   0x00007ffff158df9e <+206>:↹··pop    %r15
   0x00007ffff158dfa0 <+208>:↹··retq
End of assembler dump.
```

## To Reproduce

Steps to reproduce the behavior:

1. compile pytorch 1.5.0
2. python test/test_autograd.py --verbose

## Expected behavior

Tests pass.

## Environment

 - PyTorch Version (e.g., 1.0): 1.5.0
 - OS (e.g., Linux): Archlinux, kernel 5.6.8-arch1-1
 - How you installed PyTorch (`conda`, `pip`, source): source
 - Build command you used (if compiling from source): python setup.py build
 - Python version: 3.8.2
 - CUDA/cuDNN version: None
 - GPU models and configuration: Not built with GPU support
 - Any other relevant information:
    + old cpu : intel i7 970
    + use openblas (compiled from source)

## Additional context

- Same error, different error location (first test), with another build (build with ROCm=ON) on Archlinux, same hardware
- Same error, different error location (in the middle of autograd) when compiled on Ubuntu 18.04 in docker (ROCm=ON), same hardware

When I build on v1.4.1, it works as expected on archlinux and ubuntu.


cc @ezyang @seemethere @malfet