Missed optimization after SimplifyCFG sinks pointer load into conditional block, preventing LoopVectorize from emitting masked load
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Example on Godbolt with LLVM 21.1 https://godbolt.org/z/WdnE3dnbn
I'll be honest, I don't fully understand what's happening but I think SimplifyCFG is moving a load into a diamond that otherwise the vectorizer would've turned into a masked load just fine.
Adding
```llvm
%nn = icmp ne ptr %data, null
call void @llvm.assume(i1 %nn) [ "dereferenceable"(ptr %data, i64 1) ]
```
Apparently prevents SimplifyCFG from doing that, thus allowing the vectorizer to do its thing.
I'd actually be really happy to try and figure out what's happening here, if someone more knowledgeable is willing to help me with that I'd appreciate it a lot.
I encountered this first on LLVM 21.1 I got from here https://github.com/c3lang/llvm-for-c3/releases. Apparently, it also applies to LLVM 18 to 20.
I had originally made a post here https://discourse.llvm.org/t/why-does-llvm-not-emit-a-gather-masked-load-vector-load-when-reading-in-this-loop/90475.
Contributor guide
Research direction
Start with the Godbolt reproducer and compare the LLVM 18–21 behavior described in the issue, focusing on SimplifyCFG and LoopVectorize. Investigate why sinking the pointer load into the conditional block prevents a masked load, and use the llvm.assume variant as a comparison; done means identifying the cause and a clear correction path.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100