aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSoumya AR <soumyaa@nvidia.com>2025-01-27 11:12:33 +0530
committerSoumya AR <soumyaa@nvidia.com>2025-01-27 11:14:37 +0530
commitd8a7f07f7cf008e359dad631aaae1028776b9e18 (patch)
tree69e6bf092597bb632e1d42ba5518c9de72366319
parent1110ed77c1f22d5fc76df97d5353f27e4e91d5ae (diff)
downloadgcc-d8a7f07f7cf008e359dad631aaae1028776b9e18.zip
gcc-d8a7f07f7cf008e359dad631aaae1028776b9e18.tar.gz
gcc-d8a7f07f7cf008e359dad631aaae1028776b9e18.tar.bz2
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 <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.
-rw-r--r--gcc/match.pd4
-rw-r--r--gcc/testsuite/gcc.dg/pr0
-rw-r--r--gcc/testsuite/gcc.dg/pr118490.c7
3 files changed, 9 insertions, 2 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 1cdc7e9..efc82d7 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 0000000..e69de29
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr
diff --git a/gcc/testsuite/gcc.dg/pr118490.c b/gcc/testsuite/gcc.dg/pr118490.c
new file mode 100644
index 0000000..4ae0dac
--- /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.;
+}