void emitFunc(Type *Ty, Value *&Agg, const Twine &Name) {
assert(Ty->isSingleValueType());
// Extract the single value and store it using the indices.
- Value *Store = IRB.CreateStore(
- IRB.CreateExtractValue(Agg, Indices, Name + ".extract"),
- IRB.CreateInBoundsGEP(nullptr, Ptr, GEPIndices, Name + ".gep"));
+ //
+ // The gep and extractvalue values are factored out of the CreateStore
+ // call to make the output independent of the argument evaluation order.
+ Value *ExtractValue = IRB.CreateExtractValue(Agg, Indices,
+ Name + ".extract");
+ Value *InBoundsGEP = IRB.CreateInBoundsGEP(nullptr, Ptr, GEPIndices,
+ Name + ".gep");
+ Value *Store = IRB.CreateStore(ExtractValue, InBoundsGEP);
(void)Store;
DEBUG(dbgs() << " to: " << *Store << "\n");
}