forked from OSchip/llvm-project
[IPSCCP] Use input operand instead of OriginalOp for ssa_copy.
OriginalOp of a Predicate refers to the original IR value, before renaming. While solving in IPSCCP, we have to use the operand of the ssa_copy instead, to avoid missing updates for nested conditions on the same IR value. Fixes PR39772. llvm-svn: 347524
This commit is contained in:
parent
04435677d0
commit
6615a7132a
|
@ -1171,26 +1171,26 @@ void SCCPSolver::visitCallSite(CallSite CS) {
|
|||
if (!PI)
|
||||
return;
|
||||
|
||||
Value *CopyOf = I->getOperand(0);
|
||||
auto *PBranch = dyn_cast<PredicateBranch>(getPredicateInfoFor(I));
|
||||
if (!PBranch) {
|
||||
mergeInValue(ValueState[I], I, getValueState(PI->OriginalOp));
|
||||
mergeInValue(ValueState[I], I, getValueState(CopyOf));
|
||||
return;
|
||||
}
|
||||
|
||||
Value *CopyOf = I->getOperand(0);
|
||||
Value *Cond = PBranch->Condition;
|
||||
|
||||
// Everything below relies on the condition being a comparison.
|
||||
auto *Cmp = dyn_cast<CmpInst>(Cond);
|
||||
if (!Cmp) {
|
||||
mergeInValue(ValueState[I], I, getValueState(PI->OriginalOp));
|
||||
mergeInValue(ValueState[I], I, getValueState(CopyOf));
|
||||
return;
|
||||
}
|
||||
|
||||
Value *CmpOp0 = Cmp->getOperand(0);
|
||||
Value *CmpOp1 = Cmp->getOperand(1);
|
||||
if (CopyOf != CmpOp0 && CopyOf != CmpOp1) {
|
||||
mergeInValue(ValueState[I], I, getValueState(PI->OriginalOp));
|
||||
mergeInValue(ValueState[I], I, getValueState(CopyOf));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1217,7 +1217,7 @@ void SCCPSolver::visitCallSite(CallSite CS) {
|
|||
return;
|
||||
}
|
||||
|
||||
return (void)mergeInValue(IV, I, getValueState(PBranch->OriginalOp));
|
||||
return (void)mergeInValue(IV, I, getValueState(CopyOf));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
; RUN: opt < %s -ipsccp -S | FileCheck %s
|
||||
; RUN: opt < %s -passes=ipsccp -S | FileCheck %s
|
||||
|
||||
; Test for PR39772
|
||||
; CHECK-LABEL: cleanup:
|
||||
; CHECK-NEXT: %retval.0 = phi i32 [ 0, %if.then ], [ %add, %if.then7 ], [ %add8, %if.else ]
|
||||
|
||||
|
||||
%struct.Node = type { %struct.Node*, %struct.Node*, i32 }
|
||||
|
||||
define i32 @check(%struct.Node* %node) {
|
||||
entry:
|
||||
%cmp = icmp eq %struct.Node* %node, null
|
||||
br i1 %cmp, label %if.then, label %if.end
|
||||
|
||||
if.then: ; preds = %entry
|
||||
br label %cleanup
|
||||
|
||||
if.end: ; preds = %entry
|
||||
%left = getelementptr inbounds %struct.Node, %struct.Node* %node, i32 0, i32 0
|
||||
%0 = load %struct.Node*, %struct.Node** %left
|
||||
%call = call i32 @check(%struct.Node* %0)
|
||||
%right = getelementptr inbounds %struct.Node, %struct.Node* %node, i32 0, i32 1
|
||||
%1 = load %struct.Node*, %struct.Node** %right
|
||||
%call1 = call i32 @check(%struct.Node* %1)
|
||||
%2 = load %struct.Node*, %struct.Node** %right
|
||||
%height = getelementptr inbounds %struct.Node, %struct.Node* %2, i32 0, i32 2
|
||||
%3 = load i32, i32* %height
|
||||
%cmp3 = icmp ne i32 %3, %call1
|
||||
br i1 %cmp3, label %if.then4, label %if.end5
|
||||
|
||||
if.then4: ; preds = %if.end
|
||||
unreachable
|
||||
|
||||
if.end5: ; preds = %if.end
|
||||
%cmp6 = icmp sgt i32 %call, %call1
|
||||
br i1 %cmp6, label %if.then7, label %if.else
|
||||
|
||||
if.then7: ; preds = %if.end5
|
||||
%add = add nsw i32 %call, 1
|
||||
br label %cleanup
|
||||
|
||||
if.else: ; preds = %if.end5
|
||||
%add8 = add nsw i32 %call1, 1
|
||||
br label %cleanup
|
||||
|
||||
cleanup: ; preds = %if.else, %if.then7, %if.then
|
||||
%retval.0 = phi i32 [ 0, %if.then ], [ %add, %if.then7 ], [ %add8, %if.else ]
|
||||
ret i32 %retval.0
|
||||
}
|
Loading…
Reference in New Issue