Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions dev/core/src/com/google/gwt/dev/jjs/impl/Simplifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,10 @@ public static JExpression simplifyAnd(JBinaryOperation expression) {
if (rhs instanceof JBooleanLiteral) {
if (((JBooleanLiteral) rhs).getValue()) {
return lhs;
} else if (!lhs.hasSideEffects()) {
// Do not remove lhs if it had side effects
return rhs;
} else {
// if side effect, allow rewriting a() && false && b() -> (a(), false) && b()
// -> (a(), false && b()) -> (a(), false)
return lhs.hasSideEffects() ? new JMultiExpression(info, lhs, rhs) : rhs;
Comment thread
zbynek marked this conversation as resolved.
Outdated
}
}

Expand Down Expand Up @@ -482,8 +483,8 @@ public static JExpression simplifyOr(JBinaryOperation expression) {
if (rhs instanceof JBooleanLiteral) {
if (!((JBooleanLiteral) rhs).getValue()) {
return lhs;
} else if (!lhs.hasSideEffects()) {
return rhs;
} else {
return lhs.hasSideEffects() ? new JMultiExpression(info, lhs, rhs) : rhs;
}
}
return expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,10 @@ public void testCommuteMultiExpression() throws Exception {
+ "static int f1;"
+ "static A createA() { A.f1 = 1; return new A(); } "
+ "static boolean booleanWithSideEffects() { createA(); return true;}"
+ "static boolean randomBooleanWithSideEffects() { createA(); return random() > .5;}"
+ "static boolean booleanWithoutSideEffects() { return true;}"
+ "static int arithmeticWithSideEffects() { createA(); return 4;}"
+ "static native double random() /*-{ }-*/;"
Comment thread
zbynek marked this conversation as resolved.
Outdated
+ "}");

optimizeExpressions(false, "boolean", "true && A.booleanWithoutSideEffects()")
Expand All @@ -311,6 +313,12 @@ public void testCommuteMultiExpression() throws Exception {
optimizeExpressions(false, "boolean", "false && A.booleanWithSideEffects()")
.intoString("return false;");

optimizeExpressions(false, "int", "A.randomBooleanWithSideEffects() && false && A.randomBooleanWithSideEffects() ? 1 : 2")
Comment thread
zbynek marked this conversation as resolved.
Outdated
.intoString("return (EntryPoint$A.f1 = 1, new EntryPoint$A(), (EntryPoint$A.random() > 0.5, 2));");

optimizeExpressions(false, "int", "A.randomBooleanWithSideEffects() || true || A.randomBooleanWithSideEffects() ? 1 : 2")
.intoString("return (EntryPoint$A.f1 = 1, new EntryPoint$A(), (EntryPoint$A.random() > 0.5, 1));");

optimizeExpressions(false, "int", "3 + A.arithmeticWithSideEffects()")
.intoString("return (EntryPoint$A.f1 = 1, new EntryPoint$A(), 7);");
}
Expand Down