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.
---
gcc/match.pd | 4 ++--
gcc/testsuite/gcc.dg/pr | 0
gcc/testsuite/gcc.dg/pr118490.c | 7 +++++++
3 files changed, 9 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/pr
create mode 100644 gcc/testsuite/gcc.dg/pr118490.c

diff --git a/gcc/match.pd b/gcc/match.pd
index b6cbb851897..fd1ddf627bf 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -8317,12 +8317,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 00000000000..e69de29bb2d
diff --git a/gcc/testsuite/gcc.dg/pr118490.c b/gcc/testsuite/gcc.dg/pr118490.c
new file mode 100644
index 00000000000..4ae0dacefee
--- /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.;
+}
-- 
2.43.2

Reply via email to