Patch implements the logic described in main comment of promoteSingleBlockAlloca for loads not preceded by a store:
- If there are no stores before the load, it is (still) replaced by an undef (test2 in the added lit test)
- IF there are any stores, but none preceding the load we bail out and let the rest of Mem2Reg's machinery handle this alloca, as the load may be affected by a following store, depending on the CFG (test1 in the added lit test).
I'd make this comment more explicit now:
/// alloca is undefined on only some control flow paths. e.g. code like /// this is correct in LLVM IR: /// /// // A is an alloca with no stores so far /// for (...) { /// int t = *A; /// if (!first_iteration) /// use(t); /// *A = 42; /// } ///