llvm / llvm/llvm-project

Missed Optimization: hoist GEP out of select by selecting the offset

Open
#163,109 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

```
define ptr @src(i8 %arg1, ptr %arg0) {
%v0 = icmp eq i8 %arg1, 116
%v1 = select i1 %v0, ptr %arg0, ptr null
%v2 = getelementptr inbounds nuw i8, ptr %v1, i16 48
%v3 = getelementptr inbounds nuw i8, ptr %arg0, i16 40
%v4 = select i1 %v0, ptr %v2, ptr %v3
ret ptr %v4
}

define ptr @tgt(i8 %arg1, ptr %arg0) {
%v0 = icmp eq i8 %arg1, 116
%v1 = select i1 %v0, i16 48, i16 40
%v2 = getelementptr inbounds i8, ptr %arg0, i16 %v1
ret ptr %v2
}
```
alive2:https://alive2.llvm.org/ce/z/YNjzLG
godbolt:https://godbolt.org/z/Tovh8vzvv
Pattern found in: https://github.com/dtcxzyw/llvm-opt-benchmark/blob/main/bench/llvm/optimized/CheckExprLifetime.ll

Contributor guide

Open the contributing guide

Research direction

Start with the LLVM IR example in the issue and compare the source and target functions using the linked Alive2 proof and Godbolt reproduction. Read the referenced llvm-opt-benchmark pattern in bench/llvm/optimized/CheckExprLifetime.ll, then trace the relevant LLVM optimization behavior. Done means the missed optimization is recognized and the resulting code matches the target transformation.

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.