angr.analyses.decompiler.peephole_optimizations.fp_exact_identities

class angr.analyses.decompiler.peephole_optimizations.fp_exact_identities.FPExactIdentities

Bases: PeepholeOptimizationExprBase

Floating-point simplifications that are value-exact (bit for bit, for every input):

  • x * 1.0 and 1.0 * x -> x: exact for every x, including ±0, ±inf and NaN, in any rounding mode.

  • (Exp2(y) - 1.0) + 1.0 -> Exp2(y): x87 f2xm1; fld1; faddp. Exp2 comes only from f2xm1, which the converter lowers to Exp2(y) - 1.0; f2xm1 is defined only for y in [-1, 1], so e = exp2(y) lies in [0.5, 2]. By Sterbenz’s lemma e - 1.0 is then exact, and (e - 1.0) + 1.0 = e is representable, so the add is exact as well: the folded expression has the same value as the unfolded one in the operation’s type. (The hardware rounds 2^y - 1 to extended precision before adding 1, so either C form may differ from the machine result in the last bit; the fold does not change that.)

Not folded, since they are not exact: (x - 1.0) + 1.0 for arbitrary x (absorbs tiny x, rounds huge x), and -(a - b) -> b - a (a == b gives -0.0 vs +0.0).

NAME = 'Fold value-exact floating-point identities'
expr_classes = (<class 'angr.ailment.expression.BinaryOp'>,)
optimize(expr, **kwargs)
Parameters:

expr (BinaryOp)