[InstCombine] alive reported incorrect transformation on `--debug-counter=instcombine-visit=2`
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
alive: https://alive2.llvm.org/ce/z/u_Qehj
### Reproducer
```llvm
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
declare i32 @llvm.fshl.i32(i32, i32, i32)
define i8 @f(i1 %c) {
entry:
%x = select i1 %c, i32 -2147483520, i32 -2147483392
%r = call i32 @llvm.fshl.i32(i32 %x, i32 %x, i32 1), !range !0
%t = trunc i32 %r to i8
%f = freeze i8 %t
ret i8 %f
}
!0 = !{i32 257, i32 514}
```
=>
```llvm
; ModuleID = './repro.ll'
source_filename = "./repro.ll"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.fshl.i32(i32, i32, i32) #0
define i8 @f(i1 %c) {
entry:
%x = select i1 %c, i32 -2147483520, i32 -2147483392
%r = call i32 @llvm.fshl.i32(i32 -2147483648, i32 %x, i32 1), !range !0
%t = trunc i32 %r to i8
%f = freeze i8 %t
ret i8 %f
}
attributes #0 = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
!0 = !{i32 257, i32 514}
```
```console
$ alive-tv repro.ll --passes='instcombine' --debug-counter=instcombine-visit=2
...
Transformation doesn't verify!
ERROR: Value mismatch
Example:
i1 %c = #x0 (0)
```
Reproduced on local build of e85a62955715c5ff38b685303379313ac81a0bbf.
However, on godbolt (https://godbolt.org/z/Kn7MdEv8h), the range metadata does not exist in optimized, and alive reported that the transformation is correct for godbolt-produced optimized IR.
Maybe it's a false positive from alive, but I'm not sure, so open the issue for this.
Contributor guide
Research direction
Start with the embedded LLVM IR reproducer in the issue and run alive-tv repro.ll with --passes='instcombine' and --debug-counter=instcombine-visit=2. Compare the local build at e85a629 with the godbolt-produced IR, especially the range metadata, to determine whether this is an alive2 false positive or an incorrect InstCombine transformation.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100