is there a compiler barrier that is effective at codegen level?

Hi,

I would like to prevent that two adjacent calls to external functions getting
interleaved/separated by other neighboring code. This mixing seems to happen
in the code generator. I can prevent it by putting the two calls into a
separate BB, but then I can't use -simplifycfg, -jump-threading, ... as is.

Here is an example:

  %160 = add i64 %158, %159 ; <i64> [#uses=1]
  %161 = sub i64 %160, %startHash.0 ; <i64> [#uses=5]
  tail call void asm sideeffect "", "~{dirflag},~{fpsr},~{flags},~{memory}"()
nounwind
  %fp73 = call i8* @llvm.frameaddress(i32 0) ; <i8*> [#uses=1]
  %sp74 = call i8* @llvm.stacksave() ; <i8*> [#uses=1]
  call fastcc void @Function1(i8* %sp74, i8* %fp73) nounwind
  %162 = call i32 (i32, ...)* @Function2(i32 0) ; <i32> [#uses=1]
  tail call void asm sideeffect "", "~{dirflag},~{fpsr},~{flags},~{memory}"()
nounwind

In particular, I would like to prevent modifications to the stack to be put
between the calls to Function1 and Function2. Is this possible at all?
The standard asm compiler barriers don't seem to work, can I use another hack?
(I could put the calls to Function1 and Function2 into another noinline dummy
function and call this one instead, but is there some kind of barrier?)

Thanks,
Torvald

Putting one of those asm hacks, or a memory fence intrinsic, between the two calls should do the trick. If it doesn't please file a bug with an example including the input code, the output code, and (preferably) what optimization is messing it up.

--Owen