About Reg2Mem's DemotePHIToStack behavior.

Hi Fellows,

I have a question about why DemotePHIToStack inserts the StoreInst’s right before the terminator instruction of each incoming basic block. Shouldn’t it make more sense to put them immediate below where the original incoming value was computed? For example,

%indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]

where, in the second incoming BB,

(front) …
some instructions here

%nextindar = add one

(A) …
several instructions here
(B) …
br label %toindvar

Reg2Mem puts the StoreInst at point (B), where I think it would make more sense to put it at point (A). Are these ways two equivalent? Are there any particular reason to choose what was implemented? Thanks a bunch.

Best Regards,
Paul