This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Remove temporary stack-allocated array pointer
AbandonedPublic

Authored by ddcc on Feb 18 2021, 8:36 AM.

Details

Reviewers
ldionne
curdeius
EricWF
Group Reviewers
Restricted Project
Summary

Manual inspection of generated IR shows temporary stack allocation

Diff Detail

Event Timeline

ddcc requested review of this revision.Feb 18 2021, 8:36 AM
ddcc created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 18 2021, 8:36 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
ddcc retitled this revision from [libc++] Remove temporary stack-allocated array to [libc++] Remove temporary stack-allocated array pointer.Feb 18 2021, 8:46 AM

Do you have an example where this occurs (e.g. godbolt link)?

ddcc added a comment.Feb 18 2021, 10:31 AM

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.

ddcc abandoned this revision.Feb 18 2021, 1:19 PM
ldionne added inline comments.Feb 18 2021, 1:45 PM
libcxx/include/string
1561

Actually, that's a reference to an array. So I don't think we should be creating any temporary here.

ddcc added a comment.EditedFeb 18 2021, 2:31 PM

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.

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!