llvm / llvm/llvm-project

Missed loop-invariant PHI hoisting in LICM

Open
#222,078 0 comments 0 reactions 0 assignees View on GitHub
new issue
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

**Godbolt:** https://godbolt.org/z/Mb4oE85x5

LLVM leaves loop-invariant control flow and a PHI inside the loop in this testcase.

I found this testcase in Folly's MurmurHash implementation, which uses the `partialLoadUnaligned` function (the Godbolt testcase above is a reduced version):
https://github.com/facebook/folly/blob/1e0a1b4dd4cebceef64c76bf63ed8be1984474fa/folly/lang/Bits.h#L517

GCC hoists the corresponding address/shift calculations out of the loop, while Clang recomputes them on every iteration.

Enabling:

```text
-licm-control-flow-hoisting
```

allows LICM to hoist the relevant control flow/PHI. However, this option is currently disabled by default.

From the commit history, it appears that enabling control-flow hoisting by default originally exposed a significant compile-time regression. However, that regression seems to have been fixed:
* https://bugs.llvm.org/show_bug.cgi?id=39836
* https://github.com/llvm/llvm-project/commit/a7eb2c863fa9c55ee60f37a4ad6846cd2bbeec67

Is there a remaining reason for keeping `licm-control-flow-hoisting` disabled by default?
If so, what would be needed to enable it by default?

Contributor guide

Open the contributing guide

Research direction

Start with the reduced Godbolt testcase and the LICM handling controlled by -licm-control-flow-hoisting. Review the linked Bug 39836 and LLVM commit a7eb2c863fa9c55ee60f37a4ad6846cd2bbeec67 to determine whether the compile-time regression remains. Done means identifying any remaining reason the option is disabled and the requirements for enabling it by default.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.