Repository: pytorch
Issue: matmul returns uninitialized memory for int64 tensors with inner dimension of zero
Labels: high priority,triaged,module: linear algebra,module: correctness (silent)

### 🐛 Describe the bug

This was found in opinfo tests. Observed in {windows CI test} and {internal @mode/opt}. Only seen on `dtype=torch.long`, not with ints.

Similar bugs are found in:
* `__rmatmul__`, int64
* ~`addmm_decomposed`, float16~ (turns out this is actually a jit-only issue)
* `linalg_multi_dot`, int64

repro scripts for other ops: https://gist.github.com/davidberard98/52fbd8c707b928af0e38b9393eb0403d

Repro:
```python
import torch
from torch import tensor

for i in [0, 5]:
    a = tensor([[-4,  3,  9,  7,  0, -6,  4,  0, -3,  2],
                [-9, -7, -7, -2,  8,  4, -4, -4, -4,  4],
                [-6,  8, -4,  5, -7,  5, -2,  9, -7, -1],
                [-4,  4, -3, -1,  0,  2,  4,  6, -7, -1],
                [-3,  5, -9,  4, -7, -9, -1,  2, -7, -6]], dtype=torch.long)

    b = tensor([[-8,  2, -7, -9, -7],
                [-8,  6,  3,  8, -4],
                [ 9, -5,  5,  4, -6],
                [-8,  7, -1, -8,  9],
                [-5, -9, -3,  4,  2],
                [ 9, -5,  2,  0, -9],
                [ 2,  9, -5,  1,  3],
                [-6,  2, -5, -7,  2],
                [-4, -2,  2, -6,  0],
                [ 1, -3, -3, -8, -1]], dtype=torch.long)

    a0 = a.size(dim=0)
    a1 = a.size(dim=1)
    b0 = b.size(dim=0)
    b1 = b.size(dim=1)

    a = a[:a0-i, :a1-i]
    b = b[:b0-i, :b1-i]

    print('A:', a)
    print('B:', b)

    c = torch.matmul(b, a)

    d = torch.matmul(b, a)
    print('C:', c)
    print('D:', d)
    assert((c==d).all().item())
```

Output:
```
A: tensor([[-4,  3,  9,  7,  0, -6,  4,  0, -3,  2],
        [-9, -7, -7, -2,  8,  4, -4, -4, -4,  4],
        [-6,  8, -4,  5, -7,  5, -2,  9, -7, -1],
        [-4,  4, -3, -1,  0,  2,  4,  6, -7, -1],
        [-3,  5, -9,  4, -7, -9, -1,  2, -7, -6]])
B: tensor([[-8,  2, -7, -9, -7],
        [-8,  6,  3,  8, -4],
        [ 9, -5,  5,  4, -6],
        [-8,  7, -1, -8,  9],
        [-5, -9, -3,  4,  2],
        [ 9, -5,  2,  0, -9],
        [ 2,  9, -5,  1,  3],
        [-6,  2, -5, -7,  2],
        [-4, -2,  2, -6,  0],
        [ 1, -3, -3, -8, -1]])
C: tensor([[ 113, -165,   32, -114,  114,   66,  -55, -139,  177,   50],
        [ -60,  -30, -114,  -77,   55,  139,  -26,   43,  -49,   21],
        [ -19,   88,  138,   70,  -33,   13,   68,   77,  -28,   25],
        [ -20,  -68, -174,  -31,    0,  -26,  -99,  -67,   -4,  -33],
        [  97,   50,    0,  -28,  -65,  -31,   36,   37,   30,  -59],
        [  24,   33,  189,   47,    9,   17,   61,   20,   42,   50],
        [ -72,  -78,  -55,  -18,   86,  -26,  -17,  -69,  -35,   26],
        [  58,  -90,  -45,  -56,   37,  -13,  -52,  -91,   80,   -4],
        [  46,   -6,  -12,   -8,  -30,   14,  -36,  -10,   48,  -12],
        [  76,  -37,   75,    2,    4,  -40,   -9,  -65,   93,    7]])
D: tensor([[ 113, -165,   32, -114,  114,   66,  -55, -139,  177,   50],
        [ -60,  -30, -114,  -77,   55,  139,  -26,   43,  -49,   21],
        [ -19,   88,  138,   70,  -33,   13,   68,   77,  -28,   25],
        [ -20,  -68, -174,  -31,    0,  -26,  -99,  -67,   -4,  -33],
        [  97,   50,    0,  -28,  -65,  -31,   36,   37,   30,  -59],
        [  24,   33,  189,   47,    9,   17,   61,   20,   42,   50],
        [ -72,  -78,  -55,  -18,   86,  -26,  -17,  -69,  -35,   26],
        [  58,  -90,  -45,  -56,   37,  -13,  -52,  -91,   80,   -4],
        [  46,   -6,  -12,   -8,  -30,   14,  -36,  -10,   48,  -12],
        [  76,  -37,   75,    2,    4,  -40,   -9,  -65,   93,    7]])
A: tensor([], size=(0, 5), dtype=torch.int64)
B: tensor([], size=(5, 0), dtype=torch.int64)
C: tensor([[    140142115139344,                  15, 8083509854526923635,
           32199625190698866,     140142115142560],
        [                 22,                  30,                   0,
             140142115142944,                  20],
        [                 30,                   0,     140142115142720,
                          23,                  30],
        [                  0,     140142115142496,                  18,
                          30,                   0],
        [    140142115142656,                  23,                  30,
                           0,     140142115223168]])
D: tensor([[    140142115139088,                  15, 8083509854526923635,
           32199625190698866,     140142115142688],
        [                 22,                  30,                   0,
             140142115142208,                  20],
        [                 30,                   0,     140142115142880,
                          23,                  30],
        [                  0,     140142115142752,                  18,
                          30,                   0],
        [    140142115142624,                  23,                  30,
                           0,     140142115223040]])
Traceback (most recent call last):
  File "/path/matmul.py", line 38, in <module>
    assert((c==d).all().item())
AssertionError
```


### Versions

fbcode, non-gpu machine, `@mode/opt -c python.package_style=inline`

cc @ezyang @gchanan @zou3519 @bdhirsh @jianyuh @nikitaved @pearu @mruberry @walterddr @IvanYashchuk @xwang233 @Lezcano