Issue 180137
Summary Unnecessary register spill chains on x86-64-v4
Labels new issue
Assignees
Reporter ImpleLee
    I found this pattern from the machine code compiled for x86-64-v4. I don't know llvm ir, so sorry I can't give a smaller replication code. Godbolt link: https://godbolt.org/z/1TzerzGqc (contains the llvm ir passed to llc and the assembly).

Notice this part of the assembly at the top of `.LBB1_11` and this corresponding part before `.LBB1_15`:
```asm
.LBB1_11:                               # =>This Loop Header: Depth=1
# ...
        vmovdqu64       %ymm23, -96(%rsp)       # 32-byte Spill
        vmovdqa64       %ymm22, %ymm23
        vmovdqa64 %ymm14, %ymm22
        vmovdqa64       %ymm28, %ymm11
        vmovdqa64 %ymm19, %ymm28
        vmovdqa64       %ymm17, %ymm19
        vmovdqa64 %ymm31, %ymm17
        vmovdqa64       %ymm30, %ymm31
 vmovdqa64       %ymm29, %ymm30
        vmovdqa64       %ymm27, %ymm29
 vmovdqa64       %ymm26, %ymm27
        vmovdqa64       %ymm24, %ymm26
 vmovdqa64       %ymm25, %ymm24
# ...
.LBB1_13:
# ...
        jae .LBB1_13 # the only place that jumps to .LBB1_13
# ...
        vmovdqa64 %ymm24, %ymm25
        vmovdqa64       %ymm26, %ymm24
        vmovdqa64 %ymm27, %ymm26
        vmovdqa64       %ymm29, %ymm27
 vmovdqa64       %ymm30, %ymm29
        vmovdqa64       %ymm31, %ymm30
 vmovdqa64       %ymm17, %ymm31
        vmovdqa64       %ymm19, %ymm17
 vmovdqa64       %ymm28, %ymm19
        vmovdqa64       %ymm11, %ymm28
 vmovdqa64       %ymm22, %ymm14
        vmovdqa64       %ymm23, %ymm22
        vmovdqu64       -96(%rsp), %ymm23       # 32-byte Reload
# ...
```

They correspond to (probably) basic blocks 301, 310 and 327 in the LLVM IR, corresponding to the part before `.LBB1_13`, `.LBB1_13` and the part after `.LBB1_13` respectively.

These reload part can only be reached after the spill part.

In the spill part, the compiler has the following register spill chains (each pair of `->` indicates the latter place is used to store the value of the former):
```
14 -> 22 -> 23 -> memory
25 -> 24 -> 26 -> 27 -> 29 -> 30 -> 31 -> 17 -> 19 -> 28 -> 11
```

In the restore part, the compiler has the following register restore chains:
```
11 -> 28 -> 19 -> 17 -> 31 -> 30 -> 29 -> 27 -> 26 -> 24 -> 25
memory -> 23 -> 22 -> 14
```

However, these register spill chains are unnecessary, because their whole purpose is to get two free registers `%ymm14` and `%ymm25`, but they can simply use the free registers `%ymm23` (after saving it to the memory) and `%ymm11` in the first place.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to