Closed
Description
(Context: I tried adding assume
s to slice lengths in rust -- rust-lang/rust#122926 -- and was surprised that certain things didn't optimize away that I would have expected to. The example here is basically if i < slice.len() { do_something_with(i + 1); })
.)
I tried the following: https://llvm.godbolt.org/z/qM5bnMxxj
define noundef i64 @src(i64 noundef %x.1, i64 noundef %i) unnamed_addr #0 {
start:
%0 = icmp sge i64 %x.1, 0
tail call void @llvm.assume(i1 %0)
%inbounds = icmp ult i64 %i, %x.1
br i1 %inbounds, label %do_something, label %done
do_something:
%next = add i64 %i, 1 ; <-- look here
br label %done
done:
%r = phi i64 [ %next, %do_something ], [-1, %start ]
ret i64 %r
}
expecting to see the add
become add nuw nsw
because of the range restriction on %x.1
, but it doesn't.
Alive proof that it would be ok to do so here: https://alive2.llvm.org/ce/z/3jHXNu