How to keep a instruction from being sunk by instcombine?

I want to keep the instruction with sdiv operator from being sunk.

To do that, I did some investigation on instcombine (InstructionCombining.cpp) and found that there is a function name TryToSinkInstruction. I make a condition in there to do what I want to do.

But the other optimization in instcombine will make the sdiv to udiv and that will make the instruction sunk. But I don’t want it to be sunk.

For example:

entry:
  %div = sdiv i32 %a, %b
  br i1 %cmp, label %if.then, label %if.end

if.then:
  %call = @foo(i32 %div)

if.end:
....
....

If pass this code to instcombine, %div = sdiv i32 %a, %b must be sunk to basic block if.then.

I do some check to keep %div = sdiv i32 %a, %b from being sunk.

But other optimization in instcombine will make %div = sdiv i32 %a, %b to %div = udiv i32 %a, %b and later, it would be sunk, like:

entry:
  br i1 %cmp, label %if.then, label %if.end

if.then:
  %div = udiv i32 %a, %b
  %call = @foo(i32 %div)

if.end:
....
....

But I just want the code be like:

entry:
  %div = udiv i32 %a, %b
  br i1 %cmp, label %if.then, label %if.end

if.then:
  %call = @foo(i32 %div)

if.end:
....
....

What should I do? I tried to get the address of the instruction with sdiv but when it become udiv the address changed too.