Index: src/IceInst.cpp |
diff --git a/src/IceInst.cpp b/src/IceInst.cpp |
index f6e8974fa1d1382dca082fe83b93bf50c1e0130f..f05dd71bcef5188aa4212e5ad3548746cf360ca0 100644 |
--- a/src/IceInst.cpp |
+++ b/src/IceInst.cpp |
@@ -304,7 +304,14 @@ InstBr::InstBr(Cfg *Func, Operand *Source, CfgNode *TargetTrue_, |
CfgNode *TargetFalse_) |
: InstHighLevel(Func, Inst::Br, 1, nullptr), TargetFalse(TargetFalse_), |
TargetTrue(TargetTrue_) { |
- if (TargetTrue == TargetFalse) { |
+ |
Jim Stichnoth
2016/04/02 01:19:52
remove initial blank line
sehr
2016/04/04 15:38:51
Done.
|
+ if (auto *Constant = llvm::dyn_cast<ConstantInteger32>(Source)) { |
Jim Stichnoth
2016/04/02 01:19:52
I would name it something like "C32", that isn't a
sehr
2016/04/04 15:38:51
Done.
|
+ int32_t Value = Constant->getValue(); |
+ if (Value != 0) { |
+ TargetFalse = TargetTrue; |
+ } |
+ TargetTrue = nullptr; // turn into unconditional version |
+ } else if (TargetTrue == TargetFalse) { |
TargetTrue = nullptr; // turn into unconditional version |
} else { |
addSource(Source); |
@@ -403,6 +410,20 @@ Operand *InstPhi::getOperandForTarget(CfgNode *Target) const { |
return nullptr; |
} |
+// Replace the source operand corresponding to the incoming edge for the given |
+// node by a zero of the appropriate type. TODO: This uses a linear-time search, |
Jim Stichnoth
2016/04/02 01:19:52
TODO(owner)
Actually, maybe this TODO and the ide
sehr
2016/04/04 15:38:51
Done.
|
+// which could be improved if it becomes a problem. |
+void InstPhi::clearOperandForTarget(CfgNode *Target) { |
+ for (SizeT I = 0; I < getSrcSize(); ++I) { |
+ if (getLabel(I) == Target) { |
+ Type Ty = Dest->getType(); |
+ Srcs[I] = Target->getCfg()->getContext()->getConstantZero(Ty); |
+ return; |
+ } |
+ } |
+ llvm_unreachable("Phi target not found"); |
+} |
+ |
// Updates liveness for a particular operand based on the given predecessor |
// edge. Doesn't mark the operand as live if the Phi instruction is dead or |
// deleted. |