Skip to content

Commit

Permalink
SROA: Don't crash on a select with two identical operands.
Browse files Browse the repository at this point in the history
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179982 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
d0k committed Apr 21, 2013
1 parent 54d9a3e commit d81a0de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/Transforms/Scalar/SROA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3051,16 +3051,16 @@ class AllocaPartitionRewriter : public InstVisitor<AllocaPartitionRewriter,

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;
Expand Down
11 changes: 11 additions & 0 deletions test/Transforms/SROA/basictest.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit d81a0de

Please sign in to comment.