Open scottmcm opened 2 months ago
This is somewhat tricky in practice because for comparisons used in branches rather than assumes, tightening the bound in either direction makes the inverse looser.
Very true. Maybe this would be best phrased in terms of range
operand bundles instead, so it's not an icmp
?
I can't figure out how to write this on trunk, but something like
%y = udiv exact i64 %x, 4
call void @llvm.assume(i1 true) ["range"(i64 %y, i64 0, 128)]
turning into
call void @llvm.assume(i1 true) ["range"(i64 %x, i64 0, 509)]
is more obviously good.
Today https://llvm.godbolt.org/z/aqEabMT17, LLVM optimizes
to
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 markedexact
here, though, it could be simplified to a tighter check: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
in the output, when it could have just been
ult(%5, 0x80…00)
akasgt(%5, -1)
.