Skip to content

Commit

Permalink
Introduce BooleanCmp2 instructions that perform 2 comparison operatio…
Browse files Browse the repository at this point in the history
…ns and then either an AND or OR of the results.
  • Loading branch information
Ian Rogers committed Apr 22, 2009
1 parent c12d618 commit 68fdd78
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
8 changes: 8 additions & 0 deletions rvm/src-generated/opt-ir/InstructionFormatList.dat
Expand Up @@ -151,6 +151,14 @@ BooleanCmp
"U Cond ConditionOperand" "U BranchProfile BranchProfileOperand"


BooleanCmp2
1 0 8
"D Result RegisterOperand" "U Val1 Operand" "U Val2 Operand" \
"U Cond1 ConditionOperand" "U BranchProfile1 BranchProfileOperand" \
"U Val3 Operand" "U Val4 Operand" \
"U Cond2 ConditionOperand" "U BranchProfile2 BranchProfileOperand"


CondMove
1 0 5
"D Result RegisterOperand" "U Val1 Operand" "U Val2 Operand" \
Expand Down
16 changes: 15 additions & 1 deletion rvm/src-generated/opt-ir/OperatorList.dat
Expand Up @@ -1296,7 +1296,21 @@ compare



# Load a singed byte
# Compare two sets of two int values and put the boolean OR in the result register
BOOLEAN_CMP2_INT_OR
BooleanCmp2
compare



# Compare two sets of two int values and put the boolean AND in the result register
BOOLEAN_CMP2_INT_AND
BooleanCmp2
compare



# Load a signed byte
# NOTE: Because of our strategy of using explict guard instructions, there is no
# way in the HIR/LIR that the actual load instruction can except.
BYTE_LOAD
Expand Down
51 changes: 51 additions & 0 deletions rvm/src/org/jikesrvm/compilers/opt/Simplifier.java
Expand Up @@ -32,6 +32,7 @@
import org.jikesrvm.compilers.opt.ir.AbstractRegisterPool;
import org.jikesrvm.compilers.opt.ir.Binary;
import org.jikesrvm.compilers.opt.ir.BooleanCmp;
import org.jikesrvm.compilers.opt.ir.BooleanCmp2;
import org.jikesrvm.compilers.opt.ir.BoundsCheck;
import org.jikesrvm.compilers.opt.ir.Call;
import org.jikesrvm.compilers.opt.ir.CondMove;
Expand Down Expand Up @@ -222,6 +223,12 @@ public static DefUseEffect simplify(boolean hir, AbstractRegisterPool regpool, O
case BOOLEAN_CMP_ADDR_opcode:
result = booleanCmpAddr(s, opts);
break;
case BOOLEAN_CMP2_INT_OR_opcode:
result = booleanCmp2IntOr(s, opts);
break;
// case BOOLEAN_CMP2_INT_AND:
// result = booleanCmp2IntAnd(s);
// break;
case INT_ADD_opcode:
result = intAdd(s, opts);
break;
Expand Down Expand Up @@ -1204,6 +1211,50 @@ private static DefUseEffect booleanCmpAddr(Instruction s, OptOptions opts) {
return DefUseEffect.UNCHANGED;
}

private static DefUseEffect booleanCmp2IntOr(Instruction s, OptOptions opts) {
if (opts.SIMPLIFY_INTEGER_OPS) {
Operand op1 = BooleanCmp2.getVal1(s);
Operand op2 = BooleanCmp2.getVal2(s);
if (op1.isConstant()) {
if (op2.isConstant()) {
// 1st 2 operands are constants, can fold if result is true
int cond1 = BooleanCmp2.getCond1(s).evaluate(op1, op2);
if (cond1 == ConditionOperand.TRUE) {
Move.mutate(s, REF_MOVE, BooleanCmp2.getResult(s), IC(1));
return DefUseEffect.MOVE_FOLDED;
} else if (cond1 == ConditionOperand.FALSE) {
BooleanCmp.mutate(s, BOOLEAN_CMP_INT, BooleanCmp2.getResult(s),
BooleanCmp2.getVal3(s), BooleanCmp2.getVal4(s), BooleanCmp2
.getCond2(s), BooleanCmp2.getBranchProfile2(s));
DefUseEffect result = booleanCmpInt(s, opts);
return (result == DefUseEffect.UNCHANGED) ? DefUseEffect.REDUCED
: result;
}
}
}
Operand op3 = BooleanCmp2.getVal3(s);
Operand op4 = BooleanCmp2.getVal4(s);
if (op3.isConstant()) {
if (op4.isConstant()) {
// 3rd and 4th operands are constants, can fold if result is true
int cond2 = BooleanCmp2.getCond1(s).evaluate(op3, op4);
if (cond2 == ConditionOperand.TRUE) {
Move.mutate(s, REF_MOVE, BooleanCmp2.getResult(s), IC(1));
return DefUseEffect.MOVE_FOLDED;
} else if (cond2 == ConditionOperand.FALSE) {
BooleanCmp.mutate(s, BOOLEAN_CMP_INT, BooleanCmp2.getResult(s),
BooleanCmp2.getVal1(s), BooleanCmp2.getVal2(s), BooleanCmp2
.getCond1(s), BooleanCmp2.getBranchProfile1(s));
DefUseEffect result = booleanCmpInt(s, opts);
return (result == DefUseEffect.UNCHANGED) ? DefUseEffect.REDUCED
: result;
}
}
}
}
return DefUseEffect.UNCHANGED;
}

private static DefUseEffect intAdd(Instruction s, OptOptions opts) {
if (opts.SIMPLIFY_INTEGER_OPS) {
canonicalizeCommutativeOperator(s);
Expand Down

0 comments on commit 68fdd78

Please sign in to comment.