On 11/6/24 1:12 AM, Soumya AR wrote:
On 29 Oct 2024, at 6:59 PM, Richard Biener <rguent...@suse.de> wrote:
External email: Use caution opening links or attachments
On Mon, 28 Oct 2024, Soumya AR wrote:
This patch implements transformations for the following optimizations.
logN(x) CMP CST -> x CMP expN(CST)
expN(x) CMP CST -> x CMP logN(CST)
For example:
int
foo (float x)
{
return __builtin_logf (x) < 0.0f;
}
can just be:
int
foo (float x)
{
return x < 1.0f;
}
The patch was bootstrapped and regtested on aarch64-linux-gnu, no regression.
OK for mainline?
+ (for cmp (lt le gt ge eq ne)
+ (for logs (LOG LOG2 LOG10)
+ exps (EXP EXP2 EXP10)
+ /* Simplify logN (x) CMP CST into x CMP expN (CST) */
+ (simplify
+ (cmp:c (logs:s @0) @1)
+ (cmp @0 (exps @1)))
+
+ /* Simplify expN (x) CMP CST into x CMP logN (CST) */
+ (simplify
+ (cmp:c (exps:s @0) @1)
+ (cmp @0 (logs @1))))))
this doesn't restrict @1 to be constant. You should use
(cmp:c (exps:s @0) REAL_CST@1)
Fixed.
I think this transform is also very susceptible to rounding
issues - esp. using it for eq and ne looks very dangerous
to me. Unless you check a roundtrip through exp/log gets
you back exactly the original constant.
I think the compare kinds "most safe" would be le and ge.
This makes sense, I’ve updated the patch to only optimize
for le and ge.
Thanks,
Soumya
You can look at fold-const-call.cc:do_mpfr_arg1, mpfr gets
you the information on whether the result is exact for example.
Richard.
Signed-off-by: Soumya AR <soum...@nvidia.com>
gcc/ChangeLog:
* match.pd: Fold logN(x) CMP CST -> x CMP expN(CST)
and expN(x) CMP CST -> x CMP logN(CST)
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/log_exp.c: New test.
The latest version looks good to me.
Jeff