| Issue |
84342
|
| Summary |
[InstCombine] Missed optimization: fold `min` in `phi`
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
XChy
|
Alive2 proof: https://alive2.llvm.org/ce/z/IAXE_-
### Motivating example
```llvm
define i1 @src(i32 %a, i32 %b, i1 %c) #0 {
entry:
br i1 %c, label %then, label %loop
then:
call void @dummy()
%min = call i32 @llvm.umin.i32(i32 %a, i32 6)
br label %loop
loop:
%ind = phi i32 [ %min, %then ], [ %b, %entry ]
%cmp = icmp ult i32 %ind, 6
ret i1 %cmp
}
```
can be folded to:
```llvm
define i1 @tgt(i32 %a, i32 %b, i1 %c) #0 {
entry:
br i1 %c, label %then, label %loop
then:
call void @dummy()
br label %loop
loop:
%ind = phi i32 [ %a, %then ], [ %b, %entry ]
%cmp = icmp ult i32 %ind, 6
ret i1 %cmp
}
```
### Real-world motivation
This snippet of IR is derived from [linux/kernel/power/snapshot@snapshot_read_next](https://github.com/torvalds/linux/blob/67be068d31d423b857ffd8c34dbcc093f8dfff76/kernel/power/snapshot.c#L2244)(IR from llvm-opt-benchmark).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, see also:https://godbolt.org/z/135zx6s3K
**Let me know if you can confirm that it's an optimization opportunity, thanks.**
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs