Issue with instcombine pass inserting llvm.assume

I found an interesting regression in the function<eager-inv>(instcombine) pass.

The code is checking for integer overflow on division and should look something like this after optimizing:

  %cmp1.i = icmp eq i64 %b, -1
  %cmp2.i = icmp eq i64 %a, -9223372036854775808
  %overflow.i = and i1 %cmp2.i, %cmp1.i
  br i1 %overflow.i, label %overflow-exit, label %divide

Instead, when using function<eager-inv>(instcombine) I get this:

  %cmp1.i = icmp ne i64 %b, -1
  %cmp2.i = icmp ne i64 %a, -9223372036854775808
  %0 = or i1 %cmp2.i, %cmp1.i
  tail call void @llvm.assume(i1 %0)

Then when this code goes through the unit tests for this overflow, it breaks. I looked through some of the InstCombine code but it wasn’t immediately obvious where this was being changed. Anyone have any thoughts on how I could fix this?

It’s impossible to tell on a snippet this small.
Please post a sufficient snippet that actually shows the transform firing.
I’d guess that you are checking after performing the division itself?

Almost as soon as I posted this I had an idea what the problem was. I was able to check it this morning and verify the problem was definitely on my side. The function in question was marked dso_local but the optimization pass was running prior to merging with another module. So it correctly detected that the overflow wasn’t happening in the module being optimized. Order of operations error. Sorry to trouble people.