On 11/2/18 3:36 AM, Prathamesh Kulkarni wrote:
> Hi,
> This patch adds two transforms to match.pd to CSE erf/erfc pair.
> erfc(x) is canonicalized to 1 - erf(x) and is then reversed to 1 -
> erf(x) when canonicalization is disabled and result of erf(x) has
> single use within 1 - erf(x).
>
> The patch regressed builtin-nonneg-1.c. The following test-case
> reproduces the issue with patch:
>
> void test(double d1) {
> if (signbit(erfc(d1)))
> link_failure_erfc();
> }
>
> ssa dump:
>
> <bb 2> :
> _5 = __builtin_erf (d1_4(D));
> _1 = 1.0e+0 - _5;
> _6 = _1 < 0.0;
> _2 = (int) _6;
> if (_2 != 0)
> goto <bb 3>; [INV]
> else
> goto <bb 4>; [INV]
>
> <bb 3> :
> link_failure_erfc ();
>
> <bb 4> :
> return;
>
> As can be seen, erfc(d1) is folded to 1 - erf(d1).
> forwprop then transforms the if condition from _2 != 0
> to _5 > 1.0e+0 and that defeats DCE thus resulting in link failure
> in undefined reference to link_failure_erfc().
>
> So, the patch adds another transform erf(x) > 1 -> 0
> which resolves the regression.
>
> Bootstrapped+tested on x86_64-unknown-linux-gnu.
> Cross-testing on arm and aarch64 variants in progress.
> OK for trunk if passes ?
>
> Thanks,
> Prathamesh
>
>
> pr83750-4.txt
>
> 2018-11-02 Prathamesh Kulkarni <[email protected]>
>
> * match.pd (erfc(x) -> 1 - erf(x)): New pattern.
> (1 - erf(x) -> erfc(x)): Likewise.
> (erf(x) > 1 -> 0): Likewise.
>
> testsuite/
> * gcc.dg/tree-ssa/pr83750-1.c: New test
> * gcc.dg/tree-ssa/pr83750-2.c: Likewise.
Don't we have a flag specific to honoring nans? Would that be better to
use than flag_unsafe_math_optimizations? As Uli mentioned, there's
other cases (where ABS (const) >= 1.0.).
jeff