llvm / llvm/llvm-project

Missed Optimization: Failure to narrow a wide vector load and adjust GEP offset when only trailing elements are used.

Open
#185,556 1 comment 0 reactions 0 assignees View on GitHub
llvm:optimizations missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```llvm
define <2 x float> @src(ptr %arg0) {
%v0 = getelementptr inbounds nuw i8, ptr %arg0, i64 40
%v1 = load <4 x float>, ptr %v0, align 8
%v2 = shufflevector <4 x float> %v1, <4 x float> poison, <2 x i32>
ret <2 x float> %v2
}

define <2 x float> @tgt(ptr %arg0) {
%v0 = getelementptr inbounds nuw i8, ptr %arg0, i64 48
%v1 = load <2 x float>, ptr %v0, align 8
ret <2 x float> %v1
}
```
Godbolt: https://godbolt.org/z/1nKbrnxfM
alive2: https://alive2.llvm.org/ce/z/DZj48j
Pattern found in: https://github.com/dtcxzyw/llvm-opt-benchmark/blob/main/bench/pbrt-v4/optimized/camera.ll

Contributor guide

Open the contributing guide

Research direction

Start with the LLVM IR reproducer and validate the source/target pair using the linked Godbolt and Alive2 examples. Read the optimization code that handles vector loads and shuffles, then use the linked camera.ll benchmark to confirm that trailing-element uses are narrowed with the adjusted offset and preserved semantics.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.