angr.analyses.decompiler.peephole_optimizations.cmp_sub_const¶
- class angr.analyses.decompiler.peephole_optimizations.cmp_sub_const.CmpSubConst¶
Bases:
PeepholeOptimizationExprBaseCanonicalize equality/inequality comparisons against a constant where one side is a constant add/subtract, by folding the inner constant into the compared constant. This undoes the compiler’s strength-reduced
sub/dec-cascade lowering of switch-on-value statements, turning relative constants back into absolute ones:(A - C1) == C2 ==> A == (C1 + C2) (A - C1) != C2 ==> A != (C1 + C2) (C1 - A) == C2 ==> A == (C1 - C2) (A + C1) == C2 ==> A == (C2 - C1)
Note that this rule is only applied to
CmpEQ/CmpNE. Over the modular integersZ/2^n,A - C1 == C2iffA == C1 + C2andA + C1 == C2iffA == C2 - C1hold unconditionally, independent of signedness and regardless of any intermediate overflow. This rule is NOT applied to ordered comparisons (e.g.,CmpLT), for which folding across a subtract is unsound because of wraparound.- NAME = '(A - C1) cmp C2 => A cmp (C1 + C2)'¶
- expr_classes = (<class 'angr.ailment.expression.BinaryOp'>,)¶