@@ -1331,10 +1331,10 @@ private module Cached {
13311331 */
13321332 cached
13331333 predicate compares_eq (
1334- ValueNumber test , Operand left , Operand right , int k , boolean areEqual , AbstractValue value
1334+ ValueNumber test , Operand left , Operand right , int k , boolean areEqual , GuardValue value
13351335 ) {
13361336 /* The simple case where the test *is* the comparison so areEqual = testIsTrue xor eq. */
1337- exists ( AbstractValue v | simple_comparison_eq ( test , left , right , k , v ) |
1337+ exists ( GuardValue v | simple_comparison_eq ( test , left , right , k , v ) |
13381338 areEqual = true and value = v
13391339 or
13401340 areEqual = false and value = v .getDualValue ( )
@@ -1349,15 +1349,15 @@ private module Cached {
13491349 complex_eq ( test , left , right , k , areEqual , value )
13501350 or
13511351 /* (x is true => (left == right + k)) => (!x is false => (left == right + k)) */
1352- exists ( AbstractValue dual | value = dual .getDualValue ( ) |
1352+ exists ( GuardValue dual | value = dual .getDualValue ( ) |
13531353 compares_eq ( test .( LogicalNotValueNumber ) .getUnary ( ) , left , right , k , areEqual , dual )
13541354 )
13551355 or
13561356 compares_eq ( test .( BuiltinExpectCallValueNumber ) .getCondition ( ) , left , right , k , areEqual , value )
13571357 or
1358- exists ( Operand l , BooleanValue bv |
1358+ exists ( Operand l , GuardValue bv |
13591359 // 1. test = value -> int(l) = 0 is !bv
1360- unary_compares_eq ( test , l , 0 , bv .getValue ( ) .booleanNot ( ) , value ) and
1360+ unary_compares_eq ( test , l , 0 , bv .asBooleanValue ( ) .booleanNot ( ) , value ) and
13611361 // 2. l = bv -> left + right is areEqual
13621362 compares_eq ( valueNumber ( BooleanInstruction< isUnaryComparesEqLeft / 1 > :: get ( l .getDef ( ) ) ) , left ,
13631363 right , k , areEqual , bv )
@@ -1374,10 +1374,10 @@ private module Cached {
13741374 */
13751375 cached
13761376 predicate unary_compares_eq (
1377- ValueNumber test , Operand op , int k , boolean areEqual , AbstractValue value
1377+ ValueNumber test , Operand op , int k , boolean areEqual , GuardValue value
13781378 ) {
13791379 /* The simple case where the test *is* the comparison so areEqual = testIsTrue xor eq. */
1380- exists ( AbstractValue v | unary_simple_comparison_eq ( test , op , k , v ) |
1380+ exists ( GuardValue v | unary_simple_comparison_eq ( test , op , k , v ) |
13811381 areEqual = true and value = v
13821382 or
13831383 areEqual = false and value = v .getDualValue ( )
@@ -1386,7 +1386,7 @@ private module Cached {
13861386 unary_complex_eq ( test , op , k , areEqual , value )
13871387 or
13881388 /* (x is true => (op == k)) => (!x is false => (op == k)) */
1389- exists ( AbstractValue dual |
1389+ exists ( GuardValue dual |
13901390 value = dual .getDualValue ( ) and
13911391 unary_compares_eq ( test .( LogicalNotValueNumber ) .getUnary ( ) , op , k , areEqual , dual )
13921392 )
@@ -1400,18 +1400,18 @@ private module Cached {
14001400 )
14011401 or
14021402 // See argument for why this is correct in compares_eq
1403- exists ( Operand l , BooleanValue bv |
1404- unary_compares_eq ( test , l , 0 , bv .getValue ( ) .booleanNot ( ) , value ) and
1403+ exists ( Operand l , GuardValue bv |
1404+ unary_compares_eq ( test , l , 0 , bv .asBooleanValue ( ) .booleanNot ( ) , value ) and
14051405 unary_compares_eq ( valueNumber ( BooleanInstruction< isUnaryComparesEqLeft / 1 > :: get ( l .getDef ( ) ) ) ,
14061406 op , k , areEqual , bv )
14071407 )
14081408 or
14091409 unary_compares_eq ( test .( BuiltinExpectCallValueNumber ) .getCondition ( ) , op , k , areEqual , value )
14101410 or
1411- exists ( BinaryLogicalOperation logical , Expr operand , boolean b |
1411+ exists ( Cpp :: BinaryLogicalOperation logical , Cpp :: Expr operand , boolean b |
14121412 test .getAnInstruction ( ) .getUnconvertedResultExpression ( ) = logical and
14131413 op .getDef ( ) .getUnconvertedResultExpression ( ) = operand and
1414- logical .impliesValue ( operand , b , value .( BooleanValue ) . getValue ( ) )
1414+ logical .impliesValue ( operand , b , value .asBooleanValue ( ) )
14151415 |
14161416 k = 1 and
14171417 areEqual = b
@@ -1423,17 +1423,17 @@ private module Cached {
14231423
14241424 /** Rearrange various simple comparisons into `left == right + k` form. */
14251425 private predicate simple_comparison_eq (
1426- CompareValueNumber cmp , Operand left , Operand right , int k , AbstractValue value
1426+ CompareValueNumber cmp , Operand left , Operand right , int k , GuardValue value
14271427 ) {
14281428 cmp instanceof CompareEQValueNumber and
14291429 cmp .hasOperands ( left , right ) and
14301430 k = 0 and
1431- value .( BooleanValue ) . getValue ( ) = true
1431+ value .asBooleanValue ( ) = true
14321432 or
14331433 cmp instanceof CompareNEValueNumber and
14341434 cmp .hasOperands ( left , right ) and
14351435 k = 0 and
1436- value .( BooleanValue ) . getValue ( ) = false
1436+ value .asBooleanValue ( ) = false
14371437 }
14381438
14391439 /**
@@ -1469,35 +1469,33 @@ private module Cached {
14691469 }
14701470
14711471 /** Rearrange various simple comparisons into `op == k` form. */
1472- private predicate unary_simple_comparison_eq (
1473- ValueNumber test , Operand op , int k , AbstractValue value
1474- ) {
1475- exists ( CaseEdge case , SwitchConditionValueNumber condition |
1472+ private predicate unary_simple_comparison_eq ( ValueNumber test , Operand op , int k , GuardValue value ) {
1473+ exists ( SwitchConditionValueNumber condition , CaseEdge edge |
14761474 condition = test and
14771475 op = condition .getExpressionOperand ( ) and
1478- case = value .( MatchValue ) . getCase ( ) and
1479- exists ( condition . getSuccessor ( case ) ) and
1480- case . getValue ( ) . toInt ( ) = k
1476+ value .asIntValue ( ) = k and
1477+ edge . getValue ( ) . toInt ( ) = k and
1478+ exists ( condition . getSuccessor ( edge ) )
14811479 )
14821480 or
14831481 exists ( Instruction const | int_value ( const ) = k |
1484- value .( BooleanValue ) . getValue ( ) = true and
1482+ value .asBooleanValue ( ) = true and
14851483 test .( CompareEQValueNumber ) .hasOperands ( op , const .getAUse ( ) )
14861484 or
1487- value .( BooleanValue ) . getValue ( ) = false and
1485+ value .asBooleanValue ( ) = false and
14881486 test .( CompareNEValueNumber ) .hasOperands ( op , const .getAUse ( ) )
14891487 )
14901488 or
1491- exists ( BooleanValue bv |
1489+ exists ( GuardValue bv |
14921490 bv = value and
14931491 mayBranchOn ( op .getDef ( ) ) and
14941492 op = test .getAUse ( )
14951493 |
14961494 k = 0 and
1497- bv .getValue ( ) = false
1495+ bv .asBooleanValue ( ) = false
14981496 or
14991497 k = 1 and
1500- bv .getValue ( ) = true
1498+ bv .asBooleanValue ( ) = true
15011499 )
15021500 }
15031501
@@ -1516,15 +1514,15 @@ private module Cached {
15161514 }
15171515
15181516 private predicate complex_eq (
1519- ValueNumber cmp , Operand left , Operand right , int k , boolean areEqual , AbstractValue value
1517+ ValueNumber cmp , Operand left , Operand right , int k , boolean areEqual , GuardValue value
15201518 ) {
15211519 sub_eq ( cmp , left , right , k , areEqual , value )
15221520 or
15231521 add_eq ( cmp , left , right , k , areEqual , value )
15241522 }
15251523
15261524 private predicate unary_complex_eq (
1527- ValueNumber test , Operand op , int k , boolean areEqual , AbstractValue value
1525+ ValueNumber test , Operand op , int k , boolean areEqual , GuardValue value
15281526 ) {
15291527 unary_sub_eq ( test , op , k , areEqual , value )
15301528 or
@@ -1539,41 +1537,41 @@ private module Cached {
15391537 /** Holds if `left < right + k` evaluates to `isLt` given that test is `value`. */
15401538 cached
15411539 predicate compares_lt (
1542- ValueNumber test , Operand left , Operand right , int k , boolean isLt , AbstractValue value
1540+ ValueNumber test , Operand left , Operand right , int k , boolean isLt , GuardValue value
15431541 ) {
15441542 /* In the simple case, the test is the comparison, so isLt = testIsTrue */
15451543 simple_comparison_lt ( test , left , right , k ) and
1546- value .( BooleanValue ) . getValue ( ) = isLt
1544+ value .asBooleanValue ( ) = isLt
15471545 or
15481546 complex_lt ( test , left , right , k , isLt , value )
15491547 or
15501548 /* (not (left < right + k)) => (left >= right + k) */
15511549 exists ( boolean isGe | isLt = isGe .booleanNot ( ) | compares_ge ( test , left , right , k , isGe , value ) )
15521550 or
15531551 /* (x is true => (left < right + k)) => (!x is false => (left < right + k)) */
1554- exists ( AbstractValue dual | value = dual .getDualValue ( ) |
1552+ exists ( GuardValue dual | value = dual .getDualValue ( ) |
15551553 compares_lt ( test .( LogicalNotValueNumber ) .getUnary ( ) , left , right , k , isLt , dual )
15561554 )
15571555 or
15581556 compares_lt ( test .( BuiltinExpectCallValueNumber ) .getCondition ( ) , left , right , k , isLt , value )
15591557 or
15601558 // See argument for why this is correct in compares_eq
1561- exists ( Operand l , BooleanValue bv |
1562- unary_compares_eq ( test , l , 0 , bv .getValue ( ) .booleanNot ( ) , value ) and
1559+ exists ( Operand l , GuardValue bv |
1560+ unary_compares_eq ( test , l , 0 , bv .asBooleanValue ( ) .booleanNot ( ) , value ) and
15631561 compares_lt ( valueNumber ( BooleanInstruction< isUnaryComparesEqLeft / 1 > :: get ( l .getDef ( ) ) ) , left ,
15641562 right , k , isLt , bv )
15651563 )
15661564 }
15671565
15681566 /** Holds if `op < k` evaluates to `isLt` given that `test` evaluates to `value`. */
15691567 cached
1570- predicate compares_lt ( ValueNumber test , Operand op , int k , boolean isLt , AbstractValue value ) {
1568+ predicate compares_lt ( ValueNumber test , Operand op , int k , boolean isLt , GuardValue value ) {
15711569 unary_simple_comparison_lt ( test , op , k , isLt , value )
15721570 or
15731571 complex_lt ( test , op , k , isLt , value )
15741572 or
15751573 /* (x is true => (op < k)) => (!x is false => (op < k)) */
1576- exists ( AbstractValue dual | value = dual .getDualValue ( ) |
1574+ exists ( GuardValue dual | value = dual .getDualValue ( ) |
15771575 compares_lt ( test .( LogicalNotValueNumber ) .getUnary ( ) , op , k , isLt , dual )
15781576 )
15791577 or
@@ -1586,16 +1584,16 @@ private module Cached {
15861584 compares_lt ( test .( BuiltinExpectCallValueNumber ) .getCondition ( ) , op , k , isLt , value )
15871585 or
15881586 // See argument for why this is correct in compares_eq
1589- exists ( Operand l , BooleanValue bv |
1590- unary_compares_eq ( test , l , 0 , bv .getValue ( ) .booleanNot ( ) , value ) and
1587+ exists ( Operand l , GuardValue bv |
1588+ unary_compares_eq ( test , l , 0 , bv .asBooleanValue ( ) .booleanNot ( ) , value ) and
15911589 compares_lt ( valueNumber ( BooleanInstruction< isUnaryComparesEqLeft / 1 > :: get ( l .getDef ( ) ) ) , op , k ,
15921590 isLt , bv )
15931591 )
15941592 }
15951593
15961594 /** `(a < b + k) => (b > a - k) => (b >= a + (1-k))` */
15971595 private predicate compares_ge (
1598- ValueNumber test , Operand left , Operand right , int k , boolean isGe , AbstractValue value
1596+ ValueNumber test , Operand left , Operand right , int k , boolean isGe , GuardValue value
15991597 ) {
16001598 exists ( int onemk | k = 1 - onemk | compares_lt ( test , right , left , onemk , isGe , value ) )
16011599 }
@@ -1621,34 +1619,32 @@ private module Cached {
16211619
16221620 /** Rearrange various simple comparisons into `op < k` form. */
16231621 private predicate unary_simple_comparison_lt (
1624- SwitchConditionValueNumber test , Operand op , int k , boolean isLt , AbstractValue value
1622+ SwitchConditionValueNumber test , Operand op , int k , boolean isLt , GuardValue value
16251623 ) {
1626- exists ( CaseEdge case |
1624+ exists ( string minValue , string maxValue |
16271625 test .getExpressionOperand ( ) = op and
1628- case = value . ( MatchValue ) . getCase ( ) and
1629- exists ( test . getSuccessor ( case ) ) and
1630- case . getMaxValue ( ) > case . getMinValue ( )
1626+ exists ( test . getSuccessor ( EdgeKind :: caseEdge ( minValue , maxValue ) ) ) and
1627+ value . asConstantValue ( ) . isRange ( minValue , maxValue ) and
1628+ minValue < maxValue
16311629 |
16321630 // op <= k => op < k - 1
16331631 isLt = true and
1634- case . getMaxValue ( ) .toInt ( ) = k - 1
1632+ maxValue .toInt ( ) = k - 1
16351633 or
16361634 isLt = false and
1637- case . getMinValue ( ) .toInt ( ) = k
1635+ minValue .toInt ( ) = k
16381636 )
16391637 }
16401638
16411639 private predicate complex_lt (
1642- ValueNumber cmp , Operand left , Operand right , int k , boolean isLt , AbstractValue value
1640+ ValueNumber cmp , Operand left , Operand right , int k , boolean isLt , GuardValue value
16431641 ) {
16441642 sub_lt ( cmp , left , right , k , isLt , value )
16451643 or
16461644 add_lt ( cmp , left , right , k , isLt , value )
16471645 }
16481646
1649- private predicate complex_lt (
1650- ValueNumber test , Operand left , int k , boolean isLt , AbstractValue value
1651- ) {
1647+ private predicate complex_lt ( ValueNumber test , Operand left , int k , boolean isLt , GuardValue value ) {
16521648 sub_lt ( test , left , k , isLt , value )
16531649 or
16541650 add_lt ( test , left , k , isLt , value )
@@ -1657,7 +1653,7 @@ private module Cached {
16571653 // left - x < right + c => left < right + (c+x)
16581654 // left < (right - x) + c => left < right + (c-x)
16591655 private predicate sub_lt (
1660- ValueNumber cmp , Operand left , Operand right , int k , boolean isLt , AbstractValue value
1656+ ValueNumber cmp , Operand left , Operand right , int k , boolean isLt , GuardValue value
16611657 ) {
16621658 exists ( SubInstruction lhs , int c , int x |
16631659 compares_lt ( cmp , lhs .getAUse ( ) , right , c , isLt , value ) and
@@ -1688,7 +1684,7 @@ private module Cached {
16881684 )
16891685 }
16901686
1691- private predicate sub_lt ( ValueNumber test , Operand left , int k , boolean isLt , AbstractValue value ) {
1687+ private predicate sub_lt ( ValueNumber test , Operand left , int k , boolean isLt , GuardValue value ) {
16921688 exists ( SubInstruction lhs , int c , int x |
16931689 compares_lt ( test , lhs .getAUse ( ) , c , isLt , value ) and
16941690 left = lhs .getLeftOperand ( ) and
@@ -1707,7 +1703,7 @@ private module Cached {
17071703 // left + x < right + c => left < right + (c-x)
17081704 // left < (right + x) + c => left < right + (c+x)
17091705 private predicate add_lt (
1710- ValueNumber cmp , Operand left , Operand right , int k , boolean isLt , AbstractValue value
1706+ ValueNumber cmp , Operand left , Operand right , int k , boolean isLt , GuardValue value
17111707 ) {
17121708 exists ( AddInstruction lhs , int c , int x |
17131709 compares_lt ( cmp , lhs .getAUse ( ) , right , c , isLt , value ) and
@@ -1750,7 +1746,7 @@ private module Cached {
17501746 )
17511747 }
17521748
1753- private predicate add_lt ( ValueNumber test , Operand left , int k , boolean isLt , AbstractValue value ) {
1749+ private predicate add_lt ( ValueNumber test , Operand left , int k , boolean isLt , GuardValue value ) {
17541750 exists ( AddInstruction lhs , int c , int x |
17551751 compares_lt ( test , lhs .getAUse ( ) , c , isLt , value ) and
17561752 (
@@ -1775,7 +1771,7 @@ private module Cached {
17751771 // left - x == right + c => left == right + (c+x)
17761772 // left == (right - x) + c => left == right + (c-x)
17771773 private predicate sub_eq (
1778- ValueNumber cmp , Operand left , Operand right , int k , boolean areEqual , AbstractValue value
1774+ ValueNumber cmp , Operand left , Operand right , int k , boolean areEqual , GuardValue value
17791775 ) {
17801776 exists ( SubInstruction lhs , int c , int x |
17811777 compares_eq ( cmp , lhs .getAUse ( ) , right , c , areEqual , value ) and
@@ -1808,7 +1804,7 @@ private module Cached {
18081804
18091805 // op - x == c => op == (c+x)
18101806 private predicate unary_sub_eq (
1811- ValueNumber test , Operand op , int k , boolean areEqual , AbstractValue value
1807+ ValueNumber test , Operand op , int k , boolean areEqual , GuardValue value
18121808 ) {
18131809 exists ( SubInstruction sub , int c , int x |
18141810 unary_compares_eq ( test , sub .getAUse ( ) , c , areEqual , value ) and
@@ -1828,7 +1824,7 @@ private module Cached {
18281824 // left + x == right + c => left == right + (c-x)
18291825 // left == (right + x) + c => left == right + (c+x)
18301826 private predicate add_eq (
1831- ValueNumber cmp , Operand left , Operand right , int k , boolean areEqual , AbstractValue value
1827+ ValueNumber cmp , Operand left , Operand right , int k , boolean areEqual , GuardValue value
18321828 ) {
18331829 exists ( AddInstruction lhs , int c , int x |
18341830 compares_eq ( cmp , lhs .getAUse ( ) , right , c , areEqual , value ) and
@@ -1873,7 +1869,7 @@ private module Cached {
18731869
18741870 // left + x == right + c => left == right + (c-x)
18751871 private predicate unary_add_eq (
1876- ValueNumber test , Operand left , int k , boolean areEqual , AbstractValue value
1872+ ValueNumber test , Operand left , int k , boolean areEqual , GuardValue value
18771873 ) {
18781874 exists ( AddInstruction lhs , int c , int x |
18791875 unary_compares_eq ( test , lhs .getAUse ( ) , c , areEqual , value ) and
@@ -1916,7 +1912,7 @@ private import Cached
19161912 * To find the specific guard that performs the comparison
19171913 * use `IRGuards.comparesLt`.
19181914 */
1919- predicate comparesLt ( Operand left , Operand right , int k , boolean isLt , AbstractValue value ) {
1915+ predicate comparesLt ( Operand left , Operand right , int k , boolean isLt , GuardValue value ) {
19201916 compares_lt ( _, left , right , k , isLt , value )
19211917}
19221918
@@ -1927,6 +1923,6 @@ predicate comparesLt(Operand left, Operand right, int k, boolean isLt, AbstractV
19271923 * To find the specific guard that performs the comparison
19281924 * use `IRGuards.comparesEq`.
19291925 */
1930- predicate comparesEq ( Operand left , Operand right , int k , boolean isLt , AbstractValue value ) {
1926+ predicate comparesEq ( Operand left , Operand right , int k , boolean isLt , GuardValue value ) {
19311927 compares_eq ( _, left , right , k , isLt , value )
19321928}
0 commit comments