Missed Simplification of trunc (lshr (((shl %1, 1) | 1) + %2), 1) to i8 into trunc (%1 + lshr (%2 + 1), 1) to i8
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The following reduced IR is derived from https://github.com/PixarAnimationStudios/OpenUSD/blob/9d7fa210/pxr/imaging/plugin/hioAvif/aom_dsp/loopfilter.c#L378
Godbolt: https://godbolt.org/z/xaTaGMcEM
alive2 proof: https://alive2.llvm.org/ce/z/S2Gfd6
```llvm
define void @filter14(ptr %0, i32 %1, i32 %2) {
%reass.add = shl i32 %1, 1
%4 = or i32 %reass.add, 1
%5 = add i32 %4, %2
%6 = lshr i32 %5, 1
%7 = trunc i32 %6 to i8
store i8 %7, ptr %0, align 1
ret void
}
```
expected:
```llvm
define void @tgt(ptr %0, i32 %1, i32 %2) {
%4 = add i32 %2, 1
%5 = lshr i32 %4, 1
%6 = add i32 %5, %1
%7 = trunc i32 %6 to i8
store i8 %7, ptr %0, align 1
ret void
}
```
Contributor guide
Research direction
Start by reproducing the reduced LLVM IR from the issue with the linked Godbolt example and compare the result with the Alive2 proof. Trace which LLVM simplification or instruction-combining entry point handles the shift, add, or truncation sequence, and confirm completion when the generated IR matches the expected form.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100