Index: src/IceCfgNode.cpp |
diff --git a/src/IceCfgNode.cpp b/src/IceCfgNode.cpp |
index 9fc6634af6eaff164f17b3aed4385c44fbe7b104..45979362c2fa867e54047fb4f3ca8fb2d338ae37 100644 |
--- a/src/IceCfgNode.cpp |
+++ b/src/IceCfgNode.cpp |
@@ -84,11 +84,13 @@ void CfgNode::computeSuccessors() { |
OutEdges = Insts.rbegin()->getTerminatorEdges(); |
} |
-// Validate each Phi instruction in the node with respect to control flow. For |
-// every phi argument, its label must appear in the predecessor list. For each |
-// predecessor, there must be a phi argument with that label. We don't check |
-// that phi arguments with the same label have the same value. |
-void CfgNode::validatePhis() { |
+// Ensure each Phi instruction in the node is consistent with respect to control |
+// flow. For each predecessor, there must be a phi argument with that label. |
+// For every phi argument, its label must appear in the predecessor list or the |
+// value must be zero. The latter allows us to remove some dead control flow |
Jim Stichnoth
2016/04/04 15:50:31
I suggest this change of the "For every phi argume
sehr
2016/04/04 17:06:41
Done.
|
+// without a major rework of the phi nodes. We don't check that phi arguments |
Jim Stichnoth
2016/04/04 15:50:31
I prefer "phi instruction" over "phi node", but yo
sehr
2016/04/04 17:06:41
Done.
|
+// with the same label have the same value. |
+void CfgNode::enforcePhiConsistency() { |
for (Inst &Instr : Phis) { |
auto *Phi = llvm::cast<InstPhi>(&Instr); |
// We do a simple O(N^2) algorithm to check for consistency. Even so, it |
@@ -106,8 +108,11 @@ void CfgNode::validatePhis() { |
break; |
} |
} |
- if (!Found) |
- llvm::report_fatal_error("Phi error: label for bad incoming edge"); |
+ if (!Found) { |
+ // Predecessor was unreachable, so if (impossibly) the control flow |
+ // enters from that predecessor, the value should be zero. |
+ Phi->clearOperandForTarget(Label); |
+ } |
} |
for (CfgNode *InNode : getInEdges()) { |
bool Found = false; |