From 50b59555fc7b47893353955b47fd766c9f8428fa Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Tue, 6 Aug 2019 09:08:10 +0200 Subject: [PATCH] Added bool-ifs-min test demonstrating problem with constant loop head optimization --- .../passes/Pass2LoopHeadConstantIdentification.java | 4 +--- .../java/dk/camelot64/kickc/test/TestPrograms.java | 4 ++-- src/test/kc/bool-ifs-min.kc | 12 ++++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 src/test/kc/bool-ifs-min.kc diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2LoopHeadConstantIdentification.java b/src/main/java/dk/camelot64/kickc/passes/Pass2LoopHeadConstantIdentification.java index 796b495e0..58f179787 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2LoopHeadConstantIdentification.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2LoopHeadConstantIdentification.java @@ -34,9 +34,7 @@ public class Pass2LoopHeadConstantIdentification extends Pass2SsaOptimization { for(NaturalLoop loop : loopSet.getLoops()) { LabelRef loopHeadRef = loop.getHead(); ControlFlowBlock loopHeadBlock = getGraph().getBlock(loopHeadRef); - //TODO: Fix remaining errors! - //boolean modified = optimizeLoopHead(loopHeadBlock, loop, variableReferenceInfos); - boolean modified = false; + boolean modified = optimizeLoopHead(loopHeadBlock, loop, variableReferenceInfos); if(modified) { getProgram().clearStatementInfos(); getProgram().clearLoopSet(); diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 25409372b..c50a7f03e 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -1952,8 +1952,8 @@ public class TestPrograms { } @Test - public void testBoolIfs() throws IOException, URISyntaxException { - compileAndCompare("bool-ifs"); + public void testBoolIfsMin() throws IOException, URISyntaxException { + compileAndCompare("bool-ifs-min"); } @Test diff --git a/src/test/kc/bool-ifs-min.kc b/src/test/kc/bool-ifs-min.kc new file mode 100644 index 000000000..b5ee3cc2a --- /dev/null +++ b/src/test/kc/bool-ifs-min.kc @@ -0,0 +1,12 @@ +// A test of boolean conditions using && || and ! + +void main() { + const char* screen = 0x400; + for( char i : 0..20) { + if( (i<10) && ((i&1)==0) ) { + screen[i] = '*'; + } + } +} + +