[llvm] r347524 - [IPSCCP] Use input operand instead of OriginalOp for ssa_copy.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 25 08:32:02 PST 2018
Author: fhahn
Date: Sun Nov 25 08:32:02 2018
New Revision: 347524
URL: http://llvm.org/viewvc/llvm-project?rev=347524&view=rev
Log:
[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.
Added:
llvm/trunk/test/Transforms/SCCP/ipsccp-ssa-copy-nested-conds.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=347524&r1=347523&r2=347524&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Sun Nov 25 08:32:02 2018
@@ -1171,26 +1171,26 @@ void SCCPSolver::visitCallSite(CallSite
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
return;
}
- return (void)mergeInValue(IV, I, getValueState(PBranch->OriginalOp));
+ return (void)mergeInValue(IV, I, getValueState(CopyOf));
}
}
Added: llvm/trunk/test/Transforms/SCCP/ipsccp-ssa-copy-nested-conds.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SCCP/ipsccp-ssa-copy-nested-conds.ll?rev=347524&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SCCP/ipsccp-ssa-copy-nested-conds.ll (added)
+++ llvm/trunk/test/Transforms/SCCP/ipsccp-ssa-copy-nested-conds.ll Sun Nov 25 08:32:02 2018
@@ -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
+}
More information about the llvm-commits
mailing list