Currently InstCombine would only sink instruction if all its users are in the same block and this is block is a successor of the current one.
There are cases where the users are in different blocks but all these blocks are dominated by succesor of our block.
E.g.:
%bb: %x = call i8* @foo() %is.null = icmp eq i8* %p, null br i1 %is.null, label %null, label %not.null not.null: call void @use(i8* %x) br i1 %c, label %not.null.2, label %exit not.null.2: call void @use(i8* %x) br label %exit
Here we could sink %x to not.null block.
This patch adjustes the InstCombine sinking mechanism so that it sinks instructions to the nearest common dominator of instruction users.