From 4a2dcd20d13738621d2e06d6e5795698deb32490 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 9 Sep 2024 23:06:36 +0200 Subject: [PATCH] fix the "x<2" optimization made a few commits ago to only work on unsigned --- .../src/prog8/compiler/astprocessing/VariousCleanups.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/prog8/compiler/astprocessing/VariousCleanups.kt b/compiler/src/prog8/compiler/astprocessing/VariousCleanups.kt index 8eca2c019..55f8fe1d5 100644 --- a/compiler/src/prog8/compiler/astprocessing/VariousCleanups.kt +++ b/compiler/src/prog8/compiler/astprocessing/VariousCleanups.kt @@ -136,15 +136,15 @@ internal class VariousCleanups(val program: Program, val errors: IErrorReporter, if(isMultiComparisonRecurse(leftBinExpr1)) { val elementType = needle.inferType(program).getOrElse { throw FatalAstException("invalid needle dt") } - if(values.size==2 || values.size==3 && elementType in IntegerDatatypes) { + if(values.size==2 || values.size==3 && (elementType==DataType.UBYTE || elementType==DataType.UWORD)) { val numbers = values.map{it.number}.toSet() if(numbers == setOf(0.0, 1.0)) { - // we can replace x==0 or x==1 with x<2 + // we can replace unsigned x==0 or x==1 with x<2 val compare = BinaryExpression(needle, "<", NumericLiteral(elementType, 2.0, expr.position), expr.position) return listOf(IAstModification.ReplaceNode(expr, compare, parent)) } if(numbers == setOf(0.0, 1.0, 2.0)) { - // we can replace x==0 or x==1 or x==2 with x<3 + // we can replace unsigned x==0 or x==1 or x==2 with x<3 val compare = BinaryExpression(needle, "<", NumericLiteral(elementType, 3.0, expr.position), expr.position) return listOf(IAstModification.ReplaceNode(expr, compare, parent)) }