This is an archive of the discontinued LLVM Phabricator instance.

CGCleanup: Use correct insertion point for AllocaInst
AbandonedPublic

Authored by GorNishanov on May 29 2017, 7:44 PM.

Details

Summary

This is a follow up for the rL297084 which made sure that dominance is preserved during expression cleanup emission.
We ran into a case where dominance fixup code was inserting the store in the middle of allocas.

%x = alloca i32, align 4
store i32* %x, i32** %tmp.exprcleanup, align 4 ; <===== HERE
%ref.tmp3 = alloca %struct.A, align 1
%agg.tmp5 = alloca %"struct.std::experimental::coroutines_v1::coroutine_handle.0", align 4
%tmp.exprcleanup = alloca i32*, align 4
%allocapt = bitcast i32 undef to i32
store i32 %0, i32* %.addr, align 4

This fix makes sure that if we are fixing up domination for an alloca instruction we will do it after the AllocaInsertPt

Posted an alternative fix here: https://reviews.llvm.org/D33733

Diff Detail

Event Timeline

GorNishanov created this revision.May 29 2017, 7:44 PM
rnk added inline comments.May 31 2017, 10:55 AM
lib/CodeGen/CGCleanup.cpp
464

This doesn't seem right, Inst could be a dynamic alloca. If it's static, we definitely don't need to store and reload it. All static allocas better be in the entry block... You might want to use isStaticAlloca, but that still feels like we're hacking around some deeper problem.

Make sure that we use AllocaInsertPt for only static allocas in the entry block

GorNishanov marked an inline comment as done.May 31 2017, 11:09 AM
GorNishanov added inline comments.May 31 2017, 11:16 AM
lib/CodeGen/CGCleanup.cpp
464

An extra context. Without the fix:

coro f(int) {
  int x = co_await A{}; // compiles fine
}
coro f(int) {
  int x = 42;
  x = co_await A{}; // does not compile due to broken IR
}
GorNishanov edited the summary of this revision. (Show Details)May 31 2017, 11:28 AM
GorNishanov abandoned this revision.May 31 2017, 5:02 PM

Abandoning... Reid fixed the problem with "r304335 - Don't try to spill static allocas when emitting expr cleanups with branches"

Thank you Reid for looking into it!