Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Unified Diff: src/IceInst.cpp

Issue 1847423003: Replace constant conditional branches by unconditional branches (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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.
« src/IceCfgNode.cpp ('K') | « src/IceInst.h ('k') | tests_lit/reader_tests/forwardref.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698