]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
match.pd: Fix indefinite recursion during exp-log transformations [PR118490]
authorSoumya AR <soumyaa@nvidia.com>
Mon, 27 Jan 2025 05:42:33 +0000 (11:12 +0530)
committerSoumya AR <soumyaa@nvidia.com>
Mon, 27 Jan 2025 05:44:37 +0000 (11:14 +0530)
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 <soumyaa@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.

gcc/match.pd
gcc/testsuite/gcc.dg/pr [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr118490.c [new file with mode: 0644]

index 1cdc7e94f1feed429994ae7805567ec2ea83bb43..efc82d73cf4a361955a3d088a81e10b01fb299dd 100644 (file)
@@ -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 (file)
index 0000000..e69de29
diff --git a/gcc/testsuite/gcc.dg/pr118490.c b/gcc/testsuite/gcc.dg/pr118490.c
new file mode 100644 (file)
index 0000000..4ae0dac
--- /dev/null
@@ -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.;
+}