| Issue |
87895
|
| Summary |
`exact` flag in `udiv` isn't used when folding away comparison [InstCombine]
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
scottmcm
|
Today <https://llvm.godbolt.org/z/aqEabMT17>, LLVM optimizes
```llvm
define noundef i1 @src(i64 noundef %a, i64 noundef %b) unnamed_addr #0 {
start:
%db = sub nuw i64 %b, %a
%de = udiv exact i64 %db, 4
%inrange = icmp ule i64 %de, 127
tail call void @llvm.assume(i1 %inrange)
%z = icmp eq i64 %de, 0
ret i1 %z
}
```
to
```llvm
%inrange = icmp ult i64 %db, 512
tail call void @llvm.assume(i1 %inrange)
```
That's good, but it could be better -- that `ult(%db, 512)` is what it needs to be when it might be in-`exact`.
Because the `udiv`ision is marked `exact` here, though, it could be simplified to a tighter check:
```llvm
%inrange = icmp ult i64 %db, 509
tail call void @llvm.assume(i1 %inrange)
```
Alive proof: <https://alive2.llvm.org/ce/z/YTVqCH>
---
Context: I'm trying to give LLVM more value range information for slice iterators in rust, and was surprised to see
```llvm
%_10.i = icmp ult i64 %5, -9223372036854775807 ; 0x8000000000000001
tail call void @llvm.assume(i1 %_10.i)
```
in the output, when it could have just been `ult(%5, 0x80…00)` aka `sgt(%5, -1)`.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs