Skip to content

nuw nsw not deduced for add 1 inbounds of range-restricted length #87854

Description

@scottmcm

(Context: I tried adding assumes 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

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions