changeset 16559:7d9c2a7f6ec9

use getKind() only for primitive constants in Condition.foldCondition
author Lukas Stadler <lukas.stadler@oracle.com>
date Fri, 18 Jul 2014 13:08:29 +0200
parents f2a4042d9787
children 6acf45a1e7e2
files graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/calc/Condition.java
diffstat 1 files changed, 113 insertions(+), 111 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/calc/Condition.java	Fri Jul 18 01:26:43 2014 +0200
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/calc/Condition.java	Fri Jul 18 13:08:29 2014 +0200
@@ -337,128 +337,130 @@
      *         false
      */
     public boolean foldCondition(Constant lt, Constant rt, ConstantReflectionProvider constantReflection, boolean unorderedIsTrue) {
-        switch (lt.getKind()) {
-            case Boolean:
-            case Byte:
-            case Char:
-            case Short:
-            case Int: {
-                int x = lt.asInt();
-                int y = rt.asInt();
-                switch (this) {
-                    case EQ:
-                        return x == y;
-                    case NE:
-                        return x != y;
-                    case LT:
-                        return x < y;
-                    case LE:
-                        return x <= y;
-                    case GT:
-                        return x > y;
-                    case GE:
-                        return x >= y;
-                    case AE:
-                        return UnsignedMath.aboveOrEqual(x, y);
-                    case BE:
-                        return UnsignedMath.belowOrEqual(x, y);
-                    case AT:
-                        return UnsignedMath.aboveThan(x, y);
-                    case BT:
-                        return UnsignedMath.belowThan(x, y);
-                    default:
-                        throw new GraalInternalError("expected condition: %s", this);
-                }
-            }
-            case Long: {
-                long x = lt.asLong();
-                long y = rt.asLong();
-                switch (this) {
-                    case EQ:
-                        return x == y;
-                    case NE:
-                        return x != y;
-                    case LT:
-                        return x < y;
-                    case LE:
-                        return x <= y;
-                    case GT:
-                        return x > y;
-                    case GE:
-                        return x >= y;
-                    case AE:
-                        return UnsignedMath.aboveOrEqual(x, y);
-                    case BE:
-                        return UnsignedMath.belowOrEqual(x, y);
-                    case AT:
-                        return UnsignedMath.aboveThan(x, y);
-                    case BT:
-                        return UnsignedMath.belowThan(x, y);
-                    default:
-                        throw new GraalInternalError("expected condition: %s", this);
-                }
-            }
-            case Object: {
-                Boolean equal = constantReflection.constantEquals(lt, rt);
-                if (equal != null) {
+        if (lt instanceof PrimitiveConstant) {
+            switch (lt.getKind()) {
+                case Boolean:
+                case Byte:
+                case Char:
+                case Short:
+                case Int: {
+                    int x = lt.asInt();
+                    int y = rt.asInt();
                     switch (this) {
                         case EQ:
-                            return equal.booleanValue();
+                            return x == y;
                         case NE:
-                            return !equal.booleanValue();
+                            return x != y;
+                        case LT:
+                            return x < y;
+                        case LE:
+                            return x <= y;
+                        case GT:
+                            return x > y;
+                        case GE:
+                            return x >= y;
+                        case AE:
+                            return UnsignedMath.aboveOrEqual(x, y);
+                        case BE:
+                            return UnsignedMath.belowOrEqual(x, y);
+                        case AT:
+                            return UnsignedMath.aboveThan(x, y);
+                        case BT:
+                            return UnsignedMath.belowThan(x, y);
+                        default:
+                            throw new GraalInternalError("expected condition: %s", this);
+                    }
+                }
+                case Long: {
+                    long x = lt.asLong();
+                    long y = rt.asLong();
+                    switch (this) {
+                        case EQ:
+                            return x == y;
+                        case NE:
+                            return x != y;
+                        case LT:
+                            return x < y;
+                        case LE:
+                            return x <= y;
+                        case GT:
+                            return x > y;
+                        case GE:
+                            return x >= y;
+                        case AE:
+                            return UnsignedMath.aboveOrEqual(x, y);
+                        case BE:
+                            return UnsignedMath.belowOrEqual(x, y);
+                        case AT:
+                            return UnsignedMath.aboveThan(x, y);
+                        case BT:
+                            return UnsignedMath.belowThan(x, y);
                         default:
                             throw new GraalInternalError("expected condition: %s", this);
                     }
                 }
-            }
-            case Float: {
-                float x = lt.asFloat();
-                float y = rt.asFloat();
-                if (Float.isNaN(x) || Float.isNaN(y)) {
-                    return unorderedIsTrue;
+                case Float: {
+                    float x = lt.asFloat();
+                    float y = rt.asFloat();
+                    if (Float.isNaN(x) || Float.isNaN(y)) {
+                        return unorderedIsTrue;
+                    }
+                    switch (this) {
+                        case EQ:
+                            return x == y;
+                        case NE:
+                            return x != y;
+                        case LT:
+                            return x < y;
+                        case LE:
+                            return x <= y;
+                        case GT:
+                            return x > y;
+                        case GE:
+                            return x >= y;
+                        default:
+                            throw new GraalInternalError("expected condition: %s", this);
+                    }
                 }
-                switch (this) {
-                    case EQ:
-                        return x == y;
-                    case NE:
-                        return x != y;
-                    case LT:
-                        return x < y;
-                    case LE:
-                        return x <= y;
-                    case GT:
-                        return x > y;
-                    case GE:
-                        return x >= y;
-                    default:
-                        throw new GraalInternalError("expected condition: %s", this);
+                case Double: {
+                    double x = lt.asDouble();
+                    double y = rt.asDouble();
+                    if (Double.isNaN(x) || Double.isNaN(y)) {
+                        return unorderedIsTrue;
+                    }
+                    switch (this) {
+                        case EQ:
+                            return x == y;
+                        case NE:
+                            return x != y;
+                        case LT:
+                            return x < y;
+                        case LE:
+                            return x <= y;
+                        case GT:
+                            return x > y;
+                        case GE:
+                            return x >= y;
+                        default:
+                            throw new GraalInternalError("expected condition: %s", this);
+                    }
                 }
+                default:
+                    throw new GraalInternalError("expected value kind %s while folding condition: %s", lt.getKind(), this);
             }
-            case Double: {
-                double x = lt.asDouble();
-                double y = rt.asDouble();
-                if (Double.isNaN(x) || Double.isNaN(y)) {
-                    return unorderedIsTrue;
-                }
-                switch (this) {
-                    case EQ:
-                        return x == y;
-                    case NE:
-                        return x != y;
-                    case LT:
-                        return x < y;
-                    case LE:
-                        return x <= y;
-                    case GT:
-                        return x > y;
-                    case GE:
-                        return x >= y;
-                    default:
-                        throw new GraalInternalError("expected condition: %s", this);
-                }
+        } else {
+            Boolean equal = constantReflection.constantEquals(lt, rt);
+            if (equal == null) {
+                throw new GraalInternalError("could not fold %s %s %s", lt, this, rt);
             }
-            default:
-                throw new GraalInternalError("expected value kind %s while folding condition: %s", lt.getKind(), this);
+            switch (this) {
+                case EQ:
+                    return equal.booleanValue();
+                case NE:
+                    return !equal.booleanValue();
+                default:
+                    throw new GraalInternalError("expected condition: %s", this);
+            }
         }
     }