Add constant folding rules for floating-point comparison
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>
Thu, 15 Feb 2018 06:13:25 +0000 (22:13 -0800)
committerSteven Perron <stevenperron@google.com>
Sat, 17 Feb 2018 01:41:22 +0000 (20:41 -0500)
commit105441360043248e91ec1c8b981f9541dab11083
treed8ae67af3c8f6a969bb5508d75fba91b3f199420
parent27d23a92a0e893aa60d9e93bc7a02204493cf70d
Add constant folding rules for floating-point comparison

This change handles all 6 regular comparison types in two variations,
ordered (true if values are ordered *and* comparison is true) and
unordered (true if values are unordered *or* comparison is true).

Ordered comparison matches the default floating-point behavior on host
but we use std::isnan to check ordering explicitly anyway.

This change also slightly reworks the floating-point folding support
code to make it possible to define a folding operation that returns
boolean instead of floating point.

These tests exhaustively test ordered/unordered comparisons for
float/double.

Since for NaN inputs the comparison result doesn't depend on the
comparison function, we just test == and !=; NaN inputs result in true
unordered comparisons and false ordered comparisons.
source/opt/const_folding_rules.cpp
test/opt/fold_test.cpp