llvm / llvm/llvm-project

Missed Optimization: fold shift+add then `ashr 1` into smaller shift + add

Open
#163,115 2 comments 0 reactions 1 assignee Claimed by @manik-muk View on GitHub
llvm:optimizations missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```
define i32 @src(i32 %arg0) {
%v0 = shl nsw i32 %arg0, 4
%v1 = add nsw i32 %v0, 16
%v2 = ashr exact i32 %v1, 1
ret i32 %v2
}

define i32 @tgt(i32 %arg0) {
%v0 = shl i32 %arg0, 3
%v1 = add i32 %v0, 8
ret i32 %v1
}
```
alive2: https://alive2.llvm.org/ce/z/bUptzx
godbolt: https://godbolt.org/z/zfarv13YK
Pattern Found in: https://github.com/dtcxzyw/llvm-opt-benchmark/blob/main/bench/ffmpeg/optimized/dnxhdenc.ll

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.