Don't check for missing debug info for optimizing "if" branches.
go/r8g/16320 introduced swapping the "if" branches under certain
conditions, for example, if it does not interfere with missing
line positions.
After go/r8g/16860 we always have debug positions so no need to
check it.
Bug: 73150368
Change-Id: Iaa3f4fa58dfaa0c187cef606676348d098ca1f34
diff --git a/src/main/java/com/android/tools/r8/ir/code/BasicBlock.java b/src/main/java/com/android/tools/r8/ir/code/BasicBlock.java
index 8d5857a..58bc675 100644
--- a/src/main/java/com/android/tools/r8/ir/code/BasicBlock.java
+++ b/src/main/java/com/android/tools/r8/ir/code/BasicBlock.java
@@ -1061,7 +1061,7 @@
return hare;
}
- public boolean isSimpleAlwaysThrowingPath(boolean failOnMissingPosition) {
+ public boolean isSimpleAlwaysThrowingPath() {
// See Floyd's cycle-finding algorithm for reference.
BasicBlock hare = this;
BasicBlock tortuous = this;
@@ -1072,10 +1072,6 @@
return false;
}
- if (failOnMissingPosition && hasThrowingInstructionWithoutPosition(hare)) {
- return false;
- }
-
if (normalSuccessors.size() == 0) {
return hare.exit().isThrow();
}
@@ -1089,15 +1085,6 @@
}
}
- private boolean hasThrowingInstructionWithoutPosition(BasicBlock hare) {
- for (Instruction instruction : hare.instructions) {
- if (instruction.instructionTypeCanThrow() && instruction.getPosition().isNone()) {
- return true;
- }
- }
- return false;
- }
-
public Position getPosition() {
BasicBlock block = endOfGotoChain();
return block != null ? block.entry().getPosition() : Position.none();
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java b/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
index 769228d..069f67c 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
@@ -1434,7 +1434,7 @@
// and the dominator or the original block has catch handlers.
continue;
}
- if (!dominator.isSimpleAlwaysThrowingPath(false)) {
+ if (!dominator.isSimpleAlwaysThrowingPath()) {
// Only move string constants into blocks being part of simple
// always throwing path.
continue;
@@ -1881,7 +1881,7 @@
}
if (block.exit().isIf()) {
// Flip then/else branches if needed.
- if (flipIfBranchesIfNeeded(block, code.hasDebugPositions)) {
+ if (flipIfBranchesIfNeeded(block)) {
ifBranchFlipped = true;
}
// First rewrite zero comparison.
@@ -2207,18 +2207,17 @@
}
}
- private boolean flipIfBranchesIfNeeded(BasicBlock block, boolean failOnMissingPosition) {
+ private boolean flipIfBranchesIfNeeded(BasicBlock block) {
If theIf = block.exit().asIf();
BasicBlock trueTarget = theIf.getTrueTarget();
BasicBlock fallthrough = theIf.fallthroughBlock();
assert trueTarget != fallthrough;
- if (!fallthrough.isSimpleAlwaysThrowingPath(failOnMissingPosition) ||
- trueTarget.isSimpleAlwaysThrowingPath(failOnMissingPosition)) {
+ if (!fallthrough.isSimpleAlwaysThrowingPath() || trueTarget.isSimpleAlwaysThrowingPath()) {
return false;
}
- // In case fall-through block always trows there is a good chance that it
+ // In case fall-through block always throws there is a good chance that it
// is created for error checks and 'trueTarget' represents most more common
// non-error case. Flipping the if in this case may result in faster code
// on older Android versions.