Mercurial > hg > graal-compiler
comparison graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/calc/Condition.java @ 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 | 97eed257999b |
children | 9619ba4daf4c |
comparison
equal
deleted
inserted
replaced
16558:f2a4042d9787 | 16559:7d9c2a7f6ec9 |
---|---|
335 * @param unorderedIsTrue true if an undecided float comparison should result in "true" | 335 * @param unorderedIsTrue true if an undecided float comparison should result in "true" |
336 * @return true if the comparison is known to be true, false if the comparison is known to be | 336 * @return true if the comparison is known to be true, false if the comparison is known to be |
337 * false | 337 * false |
338 */ | 338 */ |
339 public boolean foldCondition(Constant lt, Constant rt, ConstantReflectionProvider constantReflection, boolean unorderedIsTrue) { | 339 public boolean foldCondition(Constant lt, Constant rt, ConstantReflectionProvider constantReflection, boolean unorderedIsTrue) { |
340 switch (lt.getKind()) { | 340 if (lt instanceof PrimitiveConstant) { |
341 case Boolean: | 341 switch (lt.getKind()) { |
342 case Byte: | 342 case Boolean: |
343 case Char: | 343 case Byte: |
344 case Short: | 344 case Char: |
345 case Int: { | 345 case Short: |
346 int x = lt.asInt(); | 346 case Int: { |
347 int y = rt.asInt(); | 347 int x = lt.asInt(); |
348 switch (this) { | 348 int y = rt.asInt(); |
349 case EQ: | |
350 return x == y; | |
351 case NE: | |
352 return x != y; | |
353 case LT: | |
354 return x < y; | |
355 case LE: | |
356 return x <= y; | |
357 case GT: | |
358 return x > y; | |
359 case GE: | |
360 return x >= y; | |
361 case AE: | |
362 return UnsignedMath.aboveOrEqual(x, y); | |
363 case BE: | |
364 return UnsignedMath.belowOrEqual(x, y); | |
365 case AT: | |
366 return UnsignedMath.aboveThan(x, y); | |
367 case BT: | |
368 return UnsignedMath.belowThan(x, y); | |
369 default: | |
370 throw new GraalInternalError("expected condition: %s", this); | |
371 } | |
372 } | |
373 case Long: { | |
374 long x = lt.asLong(); | |
375 long y = rt.asLong(); | |
376 switch (this) { | |
377 case EQ: | |
378 return x == y; | |
379 case NE: | |
380 return x != y; | |
381 case LT: | |
382 return x < y; | |
383 case LE: | |
384 return x <= y; | |
385 case GT: | |
386 return x > y; | |
387 case GE: | |
388 return x >= y; | |
389 case AE: | |
390 return UnsignedMath.aboveOrEqual(x, y); | |
391 case BE: | |
392 return UnsignedMath.belowOrEqual(x, y); | |
393 case AT: | |
394 return UnsignedMath.aboveThan(x, y); | |
395 case BT: | |
396 return UnsignedMath.belowThan(x, y); | |
397 default: | |
398 throw new GraalInternalError("expected condition: %s", this); | |
399 } | |
400 } | |
401 case Object: { | |
402 Boolean equal = constantReflection.constantEquals(lt, rt); | |
403 if (equal != null) { | |
404 switch (this) { | 349 switch (this) { |
405 case EQ: | 350 case EQ: |
406 return equal.booleanValue(); | 351 return x == y; |
407 case NE: | 352 case NE: |
408 return !equal.booleanValue(); | 353 return x != y; |
354 case LT: | |
355 return x < y; | |
356 case LE: | |
357 return x <= y; | |
358 case GT: | |
359 return x > y; | |
360 case GE: | |
361 return x >= y; | |
362 case AE: | |
363 return UnsignedMath.aboveOrEqual(x, y); | |
364 case BE: | |
365 return UnsignedMath.belowOrEqual(x, y); | |
366 case AT: | |
367 return UnsignedMath.aboveThan(x, y); | |
368 case BT: | |
369 return UnsignedMath.belowThan(x, y); | |
409 default: | 370 default: |
410 throw new GraalInternalError("expected condition: %s", this); | 371 throw new GraalInternalError("expected condition: %s", this); |
411 } | 372 } |
412 } | 373 } |
374 case Long: { | |
375 long x = lt.asLong(); | |
376 long y = rt.asLong(); | |
377 switch (this) { | |
378 case EQ: | |
379 return x == y; | |
380 case NE: | |
381 return x != y; | |
382 case LT: | |
383 return x < y; | |
384 case LE: | |
385 return x <= y; | |
386 case GT: | |
387 return x > y; | |
388 case GE: | |
389 return x >= y; | |
390 case AE: | |
391 return UnsignedMath.aboveOrEqual(x, y); | |
392 case BE: | |
393 return UnsignedMath.belowOrEqual(x, y); | |
394 case AT: | |
395 return UnsignedMath.aboveThan(x, y); | |
396 case BT: | |
397 return UnsignedMath.belowThan(x, y); | |
398 default: | |
399 throw new GraalInternalError("expected condition: %s", this); | |
400 } | |
401 } | |
402 case Float: { | |
403 float x = lt.asFloat(); | |
404 float y = rt.asFloat(); | |
405 if (Float.isNaN(x) || Float.isNaN(y)) { | |
406 return unorderedIsTrue; | |
407 } | |
408 switch (this) { | |
409 case EQ: | |
410 return x == y; | |
411 case NE: | |
412 return x != y; | |
413 case LT: | |
414 return x < y; | |
415 case LE: | |
416 return x <= y; | |
417 case GT: | |
418 return x > y; | |
419 case GE: | |
420 return x >= y; | |
421 default: | |
422 throw new GraalInternalError("expected condition: %s", this); | |
423 } | |
424 } | |
425 case Double: { | |
426 double x = lt.asDouble(); | |
427 double y = rt.asDouble(); | |
428 if (Double.isNaN(x) || Double.isNaN(y)) { | |
429 return unorderedIsTrue; | |
430 } | |
431 switch (this) { | |
432 case EQ: | |
433 return x == y; | |
434 case NE: | |
435 return x != y; | |
436 case LT: | |
437 return x < y; | |
438 case LE: | |
439 return x <= y; | |
440 case GT: | |
441 return x > y; | |
442 case GE: | |
443 return x >= y; | |
444 default: | |
445 throw new GraalInternalError("expected condition: %s", this); | |
446 } | |
447 } | |
448 default: | |
449 throw new GraalInternalError("expected value kind %s while folding condition: %s", lt.getKind(), this); | |
413 } | 450 } |
414 case Float: { | 451 } else { |
415 float x = lt.asFloat(); | 452 Boolean equal = constantReflection.constantEquals(lt, rt); |
416 float y = rt.asFloat(); | 453 if (equal == null) { |
417 if (Float.isNaN(x) || Float.isNaN(y)) { | 454 throw new GraalInternalError("could not fold %s %s %s", lt, this, rt); |
418 return unorderedIsTrue; | |
419 } | |
420 switch (this) { | |
421 case EQ: | |
422 return x == y; | |
423 case NE: | |
424 return x != y; | |
425 case LT: | |
426 return x < y; | |
427 case LE: | |
428 return x <= y; | |
429 case GT: | |
430 return x > y; | |
431 case GE: | |
432 return x >= y; | |
433 default: | |
434 throw new GraalInternalError("expected condition: %s", this); | |
435 } | |
436 } | 455 } |
437 case Double: { | 456 switch (this) { |
438 double x = lt.asDouble(); | 457 case EQ: |
439 double y = rt.asDouble(); | 458 return equal.booleanValue(); |
440 if (Double.isNaN(x) || Double.isNaN(y)) { | 459 case NE: |
441 return unorderedIsTrue; | 460 return !equal.booleanValue(); |
442 } | 461 default: |
443 switch (this) { | 462 throw new GraalInternalError("expected condition: %s", this); |
444 case EQ: | |
445 return x == y; | |
446 case NE: | |
447 return x != y; | |
448 case LT: | |
449 return x < y; | |
450 case LE: | |
451 return x <= y; | |
452 case GT: | |
453 return x > y; | |
454 case GE: | |
455 return x >= y; | |
456 default: | |
457 throw new GraalInternalError("expected condition: %s", this); | |
458 } | |
459 } | 463 } |
460 default: | |
461 throw new GraalInternalError("expected value kind %s while folding condition: %s", lt.getKind(), this); | |
462 } | 464 } |
463 } | 465 } |
464 | 466 |
465 public Condition join(Condition other) { | 467 public Condition join(Condition other) { |
466 if (other == this) { | 468 if (other == this) { |