[llvm] [TailDuplicator] Add a limit on the size of predecessors (PR #78582)

Quentin Dian via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 10 00:34:13 PST 2024


DianQK wrote:

Updating my progress with the example of https://github.com/llvm/llvm-project/pull/79993#issuecomment-1936822679.

In both IRs, the BB to be replicated has many predecessors and successors. The current threshold for the copy instruction limit is 2 (`TailDuplicateSize`). So the number of instructions that can be copied is twice that of the predecessors. That doesn't seem to be a problem. **However, once the copied BB termination instruction is an indirect jump, we raise this threshold to 20 (`TailDupIndirectBranchSize`).**

> Why does execute more instructions? (Related to increased PHI?)

I think it's the large increase in PHI instructions that causes us to have to read values from the stack. We have added a number of stack operation instructions.

```asm
movl    80(%rsp), %ebp                  # 4-byte 
movl    84(%rsp), %edx                  # 4-byte 
movl    28(%rsp), %eax                  # 4-byte 
movl    32(%rsp), %r12d                 # 4-byte Reload
```

> Finding a suitable successor size?

I don't actually know the effect of the number of branches jumped on the branch prediction. I don't know anything about this at all. Perhaps the branch prediction mentioned in the comment is just a simple if statement? And not a jump table scenario?

https://github.com/llvm/llvm-project/pull/78582


More information about the llvm-commits mailing list