Manual inspection of generated IR shows temporary stack allocation
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Hmm, I thought mem2reg was supposed to run even at O0. Turns out that's not the case, which explains why the alloca [3 x i64]* was not removed.
libcxx/include/string | ||
---|---|---|
1561 | Actually, that's a reference to an array. So I don't think we should be creating any temporary here. |
Here is the IR output for a small example, in the _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__zeroEv function: https://godbolt.org/z/174Pav
At O0, the reference in __a is lowered as a stack-allocated temporary array pointer, which stores the value of __r_.first().__r.__words. Then, it is loaded back out from __a in every iteration of the loop body and combined with __i in a GEP expression.
This change does remove the temporary from being emitted at O0, although the mem2reg pass does eliminate it at higher optimization levels.
Oh, thanks for the clarification. So the temporary was the pointer to the array. I thought we were trying to eliminate a stack allocated array. Anyway, it looks like this is not relevant anyway. Thank you!
Actually, that's a reference to an array. So I don't think we should be creating any temporary here.