| Issue |
235672
|
| Summary |
[RegAlloc][X86] CSR first-use split leaves copies when the CSR gets used anyway
|
| Labels |
backend:X86,
llvm:regalloc,
missed-optimization
|
| Assignees |
|
| Reporter |
chfast
|
Since #220090, `llc -O3` adds copies around a call in the function below, while saving the same registers (r12-r15, rbx) as with `-regalloc-csr-cost-scale=0`.
https://godbolt.org/z/56v6K7TeW
```asm
movq %r10, %rbx
movq %rcx, %r15
movq %r11, %r14
callq g@PLT
movq %r14, %r11
movq %r15, %rcx
movq %rbx, %r10
```
The three values live across the call are allocated while rbx, r14 and r15 are unused, so `tryAssignCSRFirstTime()` splits them around the call (0.47 < CSRCost 0.6). Shorter live ranges allocated later take rbx, r14 and r15 anyway.
Found in evmone: the CALL instruction handler gets 48 more instructions, mostly copies, with all six callee-saved registers saved in both cases.
<details><summary>IR</summary>
```llvm
target triple = "x86_64-unknown-linux-gnu"
@G = external global i64
declare void @g(i64, ptr, i64)
define i1 @f(ptr %p0, i64 %x, ptr %p2, ptr %p3, ptr %p4, ptr %p5, ptr %p6, i64 %a) {
entry:
%v0 = load i64, ptr %p2
%gep = getelementptr i8, ptr %p0, i64 -120
%v1 = load i64, ptr %gep
%v2 = load i64, ptr @G
%v3 = load i64, ptr %p3
%v4 = load i64, ptr %p4
%v5 = load i64, ptr %p6
%v6 = load i64, ptr %p3
%v7 = load i64, ptr %p0
store i64 0, ptr %p0
%v8 = load i64, ptr %p2
%o0 = or i64 %a, %v8
%c0 = icmp eq i64 %o0, 0
br i1 %c0, label %tail, label %check
check:
%o2 = or i64 %v2, %v1
%c1 = icmp ne i64 %o2, 0
br i1 %c1, label %fail, label %docall
docall:
%o3 = or i64 %v4, %v0
call void @g(i64 %x, ptr %p5, i64 %o3)
br label %tail
tail:
%o4 = or i64 -208, %v6
%o5 = or i64 %o4, %v5
%o6 = or i64 %o5, %v7
%c2 = icmp eq i64 %o6, 0
ret i1 %c2
fail:
ret i1 false
}
```
</details>
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs