https://gcc.gnu.org/g:d8a7f07f7cf008e359dad631aaae1028776b9e18

commit r15-7222-gd8a7f07f7cf008e359dad631aaae1028776b9e18
Author: Soumya AR <soum...@nvidia.com>
Date:   Mon Jan 27 11:12:33 2025 +0530

    match.pd: Fix indefinite recursion during exp-log transformations [PR118490]
    
    This patch fixes the ICE caused when comparing log or exp of a constant with
    another constant.
    
    The transform is now restricted to cases where the resultant
    log/exp (CST) can be constant folded.
    
    Signed-off-by: Soumya AR <soum...@nvidia.com>
    
    gcc/ChangeLog:
    
            PR target/118490
            * match.pd: Added ! to verify that log/exp (CST) can be constant 
folded.
    
    gcc/testsuite/ChangeLog:
    
            PR target/118490
            * gcc.dg/pr118490.c: New test.

Diff:
---
 gcc/match.pd                    | 4 ++--
 gcc/testsuite/gcc.dg/pr         | 0
 gcc/testsuite/gcc.dg/pr118490.c | 7 +++++++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 1cdc7e94f1fe..efc82d73cf4a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -8320,12 +8320,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
     /* Simplify logN (x) CMP CST into x CMP expN (CST) */
     (simplify
     (cmp:c (logs:s @0) REAL_CST@1)
-     (cmp @0 (exps @1)))
+     (cmp @0 (exps! @1)))
 
     /* Simplify expN (x) CMP CST into x CMP logN (CST) */
     (simplify
     (cmp:c (exps:s @0) REAL_CST@1)
-     (cmp @0 (logs @1))))))
+     (cmp @0 (logs! @1))))))
 
  (for logs (LOG LOG2 LOG10 LOG10)
       exps (EXP EXP2 EXP10 POW10)
diff --git a/gcc/testsuite/gcc.dg/pr b/gcc/testsuite/gcc.dg/pr
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/gcc/testsuite/gcc.dg/pr118490.c b/gcc/testsuite/gcc.dg/pr118490.c
new file mode 100644
index 000000000000..4ae0dacefeea
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr118490.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ffast-math -frounding-math -Wlogical-op" } */
+
+double exp(double);
+int foo(int v) {
+       return v && exp(1.) < 2.;
+}

Reply via email to