[llvm] [InstCombine] Fix #163110: Fold icmp (shl X, L), (add (shl Y, L), 1<<L) to icmp X, (Y + 1) (PR #165975)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 10 05:03:52 PST 2026
dtcxzyw wrote:
Miscompilation reproducer: https://alive2.llvm.org/ce/z/b7sHPP
```
----------------------------------------
define i1 @src(i32 %x, i32 %y) {
#0:
%shlx = shl nuw i32 %x, 5
%shly = shl nsw i32 %y, 5
%add = add nsw i32 %shly, 32
%cmp = icmp ugt i32 %shlx, %add
ret i1 %cmp
}
=>
define i1 @tgt(i32 %x, i32 %y) {
#0:
%shly = and i32 %y, 134217727
%add = add nsw nuw i32 %shly, 1
%cmp = icmp ugt i32 %x, %add
ret i1 %cmp
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
i32 %x = #x00000001 (1)
i32 %y = #xffffffff (4294967295, -1)
Source:
i32 %shlx = #x00000020 (32)
i32 %shly = #xffffffe0 (4294967264, -32)
i32 %add = #x00000000 (0)
i1 %cmp = #x1 (1)
Target:
i32 %shly = #x07ffffff (134217727)
i32 %add = #x08000000 (134217728)
i1 %cmp = #x0 (0)
Source value: #x1 (1)
Target value: #x0 (0)
```
https://github.com/llvm/llvm-project/pull/165975
More information about the llvm-commits
mailing list