[PATCH] D79956: [InstCombine] Teach PromoteCastOfAllocation to not insert a bitcast into the middle of a group of allocas
Johannes Doerfert via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 14 14:08:52 PDT 2020
jdoerfert added a comment.
In D79956#2037264 <https://reviews.llvm.org/D79956#2037264>, @craig.topper wrote:
> So for the originally reported issue, it looks like in StackColoring::remapInstructions To is later than From in the basic block. And there's a use of From between them. So when From is replaced with To we create bad IR. So we need to move To to From if From is earlier? Or if there is a user of >From that's earlier than To? I think the code does walk all uses of From already.
It is not wrong for StackColoring to "just" move allocas to the beginning of a block (first insert point probably), even eagerly. Or, less invasive, maybe something like this:
const AllocaInst *From = MFI->getObjectAllocation(SI.first);
const AllocaInst *To = MFI->getObjectAllocation(SI.second);
✚ if (!From->comesBefore(To))
✚ const_cast<AllocaInst*>(From)->moveBefore(const_cast<AllocaInst*>(To));
EDIT: Without looking at the rest of the code, the order property is not "directly" tied to the grouping property. So while one might imply the other it seems to be a safer way to really test/ensure the property we need here.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79956/new/
https://reviews.llvm.org/D79956
More information about the llvm-commits
mailing list