SROA: Don't crash on a select with two identical operands.

This is an edge case that can happen if we modify a chain of multiple selects.
Update all operands in that case and remove the assert. PR15805.

llvm-svn: 179982
This commit is contained in:
Benjamin Kramer 2013-04-21 17:48:39 +00:00
parent 4938ddb1ab
commit 0212dc27ed
2 changed files with 19 additions and 8 deletions

View File

@ -3051,16 +3051,16 @@ private:
bool visitSelectInst(SelectInst &SI) {
DEBUG(dbgs() << " original: " << SI << "\n");
// Find the operand we need to rewrite here.
bool IsTrueVal = SI.getTrueValue() == OldPtr;
if (IsTrueVal)
assert(SI.getFalseValue() != OldPtr && "Pointer is both operands!");
else
assert(SI.getFalseValue() == OldPtr && "Pointer isn't an operand!");
assert((SI.getTrueValue() == OldPtr || SI.getFalseValue() == OldPtr) &&
"Pointer isn't an operand!");
Value *NewPtr = getAdjustedAllocaPtr(IRB, OldPtr->getType());
SI.setOperand(IsTrueVal ? 1 : 2, NewPtr);
// Replace the operands which were using the old pointer.
if (SI.getOperand(1) == OldPtr)
SI.setOperand(1, NewPtr);
if (SI.getOperand(2) == OldPtr)
SI.setOperand(2, NewPtr);
DEBUG(dbgs() << " to: " << SI << "\n");
deleteIfTriviallyDead(OldPtr);
return false;

View File

@ -1306,3 +1306,14 @@ end:
; CHECK: ret void
}
define void @PR15805(i1 %a, i1 %b) {
; CHECK: @PR15805
; CHECK: select i1 undef, i64* %c, i64* %c
; CHECK: ret void
%c = alloca i64, align 8
%p.0.c = select i1 undef, i64* %c, i64* %c
%cond.in = select i1 undef, i64* %p.0.c, i64* %c
%cond = load i64* %cond.in, align 8
ret void
}