[llvm] [InstCombine] Fold (1 << a) to (a + 1) and (2 >> a) to (2 - a) when a is in [0,1] (PR #207108)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 1 19:01:41 PDT 2026
dtcxzyw wrote:
The following correctness issue was found by [llvm-hackme](https://github.com/dtcxzyw/llvm-hackme).
<!-- llvm-hackme-state: bug_found -->
<!-- llvm-hackme-baseline: 815533b0f85beed5133bc078a0582ad50f5bd70a -->
<!-- llvm-hackme-head-sha: b6b64580d796d112a7d9c1390d0b645256e24eff -->
<!-- llvm-hackme-patch-sha256: 7805af024d6d6d2fb37750f6b0c002433d98068acecabd30a6b62a41a298867f -->
<!-- llvm-hackme-kind: miscompilation -->
This comment is generated by an automated correctness checking service designed to help identify critical correctness bugs (opt crashes or Alive2 miscompilations) and improve PR review efficiency under limited reviewer bandwidth.
The reproducer was generated by LLM.
This bug is a regression introduced by this PR. It does not reproduce on the baseline commit.
## Reproducer
**Kind**: miscompilation
**IR Reproducer**:
```llvm
; RUN: opt -passes=instcombine<no-verify-fixpoint> -S
define i2 @f(i2 range(i2 0, 2) %x) {
%shr = lshr i2 2, %x
ret i2 %shr
}
```
**Alive2 Counterexample**:
```
----------------------------------------
define i2 @f(i2 %x) {
init:
%#range_0_%x = !range i2 %x, i2 0, i2 2
br label %#0
#0:
%shr = lshr i2 2, %#range_0_%x
ret i2 %shr
}
=>
define i2 @f(i2 %x) {
init:
%#range_0_%x = !range i2 %x, i2 0, i2 2
br label %#0
#0:
%shr = sub nsw nuw i2 2, %#range_0_%x
ret i2 %shr
}
Transformation doesn't verify!
ERROR: Target is more poisonous than source
NOTE: The counterexample is unique.
Example:
i2 %x = #x1 (1)
Source:
i2 %#range_0_%x = #x1 (1)
>> Jump to %#0
i2 %shr = #x1 (1)
Target:
i2 %#range_0_%x = #x1 (1)
>> Jump to %#0
i2 %shr = poison
Source value: #x1 (1)
Target value: poison
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errors
```
**Opt Output**:
```llvm
; ModuleID = '/tmp/tmpgb3nbyir.ll'
source_filename = "/tmp/tmpgb3nbyir.ll"
define i2 @f(i2 range(i2 0, -2) %x) {
%shr = sub nuw nsw i2 -2, %x
ret i2 %shr
}
```
**Baseline Revision**: `815533b0f85beed5133bc078a0582ad50f5bd70a`
**PR Head SHA**: `b6b64580d796d112a7d9c1390d0b645256e24eff`
**Patch SHA256**: `7805af024d6d6d2fb37750f6b0c002433d98068acecabd30a6b62a41a298867f`
https://github.com/llvm/llvm-project/pull/207108
More information about the llvm-commits
mailing list