Skip to content

Fix #6710: reverse code for dcmpg/dcmpl and fcmpg/fcmpl #6722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/backend/ScalaPrimitivesOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class ScalaPrimitivesOps {
final val NE = 43 // x != y
final val LT = 44 // x < y
final val LE = 45 // x <= y
final val GE = 46 // x > y
final val GT = 47 // x >= y
final val GT = 46 // x > y
final val GE = 47 // x >= y

// Boolean unary operations
final val ZNOT = 50 // !x
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1236,11 +1236,11 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
(tk: @unchecked) match {
case LONG => emit(asm.Opcodes.LCMP)
case FLOAT =>
if (op == LT || op == LE) emit(asm.Opcodes.FCMPG)
else emit(asm.Opcodes.FCMPL)
if (op == LT || op == LE) emit(asm.Opcodes.FCMPL)
else emit(asm.Opcodes.FCMPG)
case DOUBLE =>
if (op == LT || op == LE) emit(asm.Opcodes.DCMPG)
else emit(asm.Opcodes.DCMPL)
if (op == LT || op == LE) emit(asm.Opcodes.DCMPL)
else emit(asm.Opcodes.DCMPG)
}
bc.emitIF(op, success)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {
).checkRuns()
}

@Test def runBootstrappedOnly: Unit = {
implicit val testGroup: TestGroup = TestGroup("runBootstrappedOnly")
aggregateTests(
compileFilesInDir("tests/run-bootstrapped", withCompilerOptions),
).checkRuns()
}

// Pickling Tests ------------------------------------------------------------
//
// Pickling tests are very memory intensive and as such need to be run with a
Expand Down
54 changes: 54 additions & 0 deletions tests/run-bootstrapped/i6710.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
object Test {
def main(args: Array[String]): Unit = {
// constant fold will fail for non-bootstrapped Dotty
assert(!(Float.NaN > 0.0))
assert(!(Float.NaN < 0.0))
assert(!(Double.NaN > 0.0))
assert(!(Double.NaN < 0.0))

val f: Float = Float.NaN
val d: Double = Double.NaN
assert(!(f > 0.0f))
assert(!(f < 0.0f))
assert(!(d > 0.0))
assert(!(d < 0.0))

// loop forever before the fix
var x = Double.NaN
while(x < 10.0) { x = x + 1; println(x) }
while(x > 10.0) { x = x + 1; println(x) }
do { x = x + 1; println(x) } while(x < 10.0)
do { x = x + 1; println(x) } while(x > 10.0)

// tests from https://github.com/scala/scala/pull/5207
{
val n = Double.NaN
def ne(x: Double, y: Double) = x != y
val fs: List[(Double, Double) => Boolean] = List(_ < _, _ <= _, _ > _, _ >= _, _ == _, (x, y) => !ne(x, y))
val vs = List[Double](n, 1, -1, 0)
for (f <- fs; v <- vs; (x, y) <- List((n, v), (v, n))) assert(!f(x, y))
}

{
val n = Float.NaN
def ne(x: Float, y: Float) = x != y
val fs: List[(Float, Float) => Boolean] = List(_ < _, _ <= _, _ > _, _ >= _, _ == _, (x, y) => !ne(x, y))
val vs = List[Float](n, 1, -1, 0)
for (f <- fs; v <- vs; (x, y) <- List((n, v), (v, n))) assert(!f(x, y))
}

{
def a[T](x: T, y: T) = x == y
def b[T](x: T, y: T) = x != y
val n = Double.NaN
(a(n, n) :: a(n, 0) :: a (0, n) :: !b(n, n) :: !b(n, 0) :: !b(0, n) :: Nil).foreach(b => assert(!b))
}

{
def a[T](x: T, y: T) = x == y
def b[T](x: T, y: T) = x != y
val n = Float.NaN
(a(n, n) :: a(n, 0) :: a (0, n) :: !b(n, n) :: !b(n, 0) :: !b(0, n) :: Nil).foreach(b => assert(!b))
}
}
}