Merging r236457 and r236635:

------------------------------------------------------------------------
r236457 | tnorthover | 2015-05-04 13:41:51 -0700 (Mon, 04 May 2015) |
9 lines

CodeGen: match up correct insertvalue indices when assessing tail
calls.

When deciding whether a value comes from the aggregate or inserted
value of an insertvalue instruction, we compare the indices against
those of the location we're interested in. One of the lists needs
reversing because the input data is backwards (so that modifications
take place at the end of the SmallVector), but we were reversing both
before leading to incorrect results.

------------------------------------------------------------------------
r236635 | tnorthover | 2015-05-06 13:07:38 -0700 (Wed, 06 May 2015) |
12 lines

CodeGen: move over-zealous assert into actual if statement.

It's quite possible to encounter an insertvalue instruction that's
more deeply nested than the value we're looking for, but when that
happens we really mustn't compare beyond the end of the index array.

Since I couldn't see any guarantees about what comparisons std::equal
makes, we probably need to directly check the size beforehand. In
practice, I suspect most std::equal implementations would probably
bail early, which would be OK.  But just in case...

rdar://20834485




git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_36@239611 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Tim Northover
2015-06-12 15:57:35 +00:00
parent e17b540032
commit 4b3f6b49e5
2 changed files with 40 additions and 2 deletions
+2 -2
View File
@@ -295,8 +295,8 @@ static const Value *getNoopInput(const Value *V,
} else if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(V)) {
// Value may come from either the aggregate or the scalar
ArrayRef<unsigned> InsertLoc = IVI->getIndices();
if (std::equal(InsertLoc.rbegin(), InsertLoc.rend(),
ValLoc.rbegin())) {
if (ValLoc.size() >= InsertLoc.size() &&
std::equal(InsertLoc.begin(), InsertLoc.end(), ValLoc.rbegin())) {
// The type being inserted is a nested sub-type of the aggregate; we
// have to remove those initial indices to get the location we're
// interested in for the operand.