llvm / llvm/llvm-project

[InstCombine] Missed: `trunc(((X << m) + C) >> k) -> trunc((X << (m - k)) + (C >> k))`

Open
#214,339 1 comment 0 reactions 1 assignee Claimed by @Ineshmcw View on GitHub
llvm:instcombine missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Missed optimization

```llvm
define i8 @src(i32 %x) local_unnamed_addr #0 {
%v2 = shl i32 %x, 12
%v3 = add i32 %v2, 34816
%v16 = lshr i32 %v3, 8
%v17 = trunc i32 %v16 to i8
ret i8 %v17
}

define i8 @tgt(i32 %x) local_unnamed_addr {
%v2 = shl i32 %x, 4
%v3 = add i32 %v2, 136
%v4 = trunc i32 %v3 to i8
ret i8 %v4
}
```

https://alive2.llvm.org/ce/z/Q4xYvT

Extracted from zlib_deflate function in deflate

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.