A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/magarciaEPFL/scala/commit/3281236219ad0a7894a0c1c743e8550e2ce20dbf below:

test constant folding including nullness propagation · magarciaEPFL/scala@3281236 · GitHub

File tree Expand file treeCollapse file tree 3 files changed

+39

-0

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+39

-0

lines changed Original file line number Diff line number Diff line change

@@ -0,0 +1 @@

1 +

-neo:o1 -Ynooptimize

Original file line number Diff line number Diff line change

@@ -0,0 +1,11 @@

1 + 2 +

class CF_1 {

3 +

def foo() {

4 +

// constant optimization should eliminate all branches

5 +

val i = 1

6 +

val x = if (i != 1) null else "good"

7 +

val y = if (x == null) "good" else x + ""

8 +

println(y)

9 +

}

10 +

}

11 + Original file line number Diff line number Diff line change

@@ -0,0 +1,27 @@

1 + 2 +

import scala.tools.partest.BytecodeTest

3 +

import scala.tools.asm

4 +

import asm.tree.InsnList

5 +

import scala.collection.JavaConverters._

6 + 7 +

object Test extends BytecodeTest {

8 +

val comparisons = Set(asm.Opcodes.IF_ACMPEQ, asm.Opcodes.IF_ACMPNE, asm.Opcodes.IF_ICMPEQ, asm.Opcodes.IF_ICMPGE, asm.Opcodes.IF_ICMPGT, asm.Opcodes.IF_ICMPLE,

9 +

asm.Opcodes.IF_ICMPLT, asm.Opcodes.IF_ICMPNE, asm.Opcodes.IFEQ, asm.Opcodes.IFGE, asm.Opcodes.IFGT, asm.Opcodes.IFLE, asm.Opcodes.IFLT,

10 +

asm.Opcodes.IFNE, asm.Opcodes.IFNONNULL, asm.Opcodes.IFNULL)

11 + 12 +

def show: Unit = {

13 +

val classNode = loadClassNode("CF_1")

14 +

val methodNode = getMethod(classNode, "foo")

15 +

// after optimization there should be no comparisons left

16 +

val expected = 0

17 + 18 +

val got = countComparisons(methodNode.instructions)

19 +

assert(got == expected, s"expected $expected but got $got comparisons")

20 +

}

21 + 22 +

def countComparisons(insnList: InsnList): Int = {

23 +

def isComparison(node: asm.tree.AbstractInsnNode): Boolean =

24 +

(comparisons contains node.getOpcode)

25 +

insnList.iterator.asScala count isComparison

26 +

}

27 +

}

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4