aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2025-06-12 20:22:39 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2025-06-13 10:00:14 +0200
commitf45c7c4425f5a62b0b1f3ee4395f347f2a57c541 (patch)
treefc9d128920fc5d165d610df61c11d072c4e8a80b /gcc
parent7bd979469be5d5506be17248db2420b5759c0316 (diff)
downloadgcc-f45c7c4425f5a62b0b1f3ee4395f347f2a57c541.zip
gcc-f45c7c4425f5a62b0b1f3ee4395f347f2a57c541.tar.gz
gcc-f45c7c4425f5a62b0b1f3ee4395f347f2a57c541.tar.bz2
recip: Reset range info when replacing sqrt with rsqrt [PR120638]
This pass reuses a SSA_NAME on the lhs of sqrt etc. call as lhs of .RSQRT etc. call. The following testcase is miscompiled since my recent ranger cast changes, because we compute (correct) range for sqrtf argument as well as result but then recip pass keeps using that range for the .RQSRT call which returns 1. / sqrt, so the function then returns 0.5f unconditionally. Note, on foo this is a regression from GCC 15, but on bar it regressed already with the r14-536 change. 2025-06-12 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/120638 * tree-ssa-math-opts.cc (pass_cse_reciprocals::execute): Call reset_flow_sensitive_info on arg1. * gcc.dg/pr120638.c: New test. (cherry picked from commit 8804e5b5b127b27d099d0c361fa2161d0b13edef)
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.dg/pr120638.c31
-rw-r--r--gcc/tree-ssa-math-opts.cc1
2 files changed, 32 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/pr120638.c b/gcc/testsuite/gcc.dg/pr120638.c
new file mode 100644
index 0000000..4a057a0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr120638.c
@@ -0,0 +1,31 @@
+/* PR tree-optimization/120638 */
+/* { dg-do run } */
+/* { dg-options "-O2 -ffast-math" } */
+
+extern float sqrtf (float x);
+
+__attribute__((noipa)) float
+foo (unsigned int s)
+{
+ return 0.5f / sqrtf (1.f + s);
+}
+
+__attribute__((noipa)) float
+bar (float s)
+{
+ if (s < 0.0 || s > 65535.0f)
+ __builtin_unreachable ();
+ return 0.5f / sqrtf (1.f + s);
+}
+
+int
+main ()
+{
+ if (__builtin_fabsf (foo (3) - 0.25f) > 0.00390625f
+ || __builtin_fabsf (foo (15) - 0.125f) > 0.00390625f
+ || __builtin_fabsf (foo (63) - 0.0625f) > 0.00390625f
+ || __builtin_fabsf (bar (3.0f) - 0.25f) > 0.00390625f
+ || __builtin_fabsf (bar (15.0f) - 0.125f) > 0.00390625f
+ || __builtin_fabsf (bar (63.0f) - 0.0625f) > 0.00390625f)
+ __builtin_abort ();
+}
diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc
index eb03ebe..1954c28 100644
--- a/gcc/tree-ssa-math-opts.cc
+++ b/gcc/tree-ssa-math-opts.cc
@@ -1053,6 +1053,7 @@ pass_cse_reciprocals::execute (function *fun)
continue;
gimple_replace_ssa_lhs (call, arg1);
+ reset_flow_sensitive_info (arg1);
if (gimple_call_internal_p (call) != (ifn != IFN_LAST))
{
auto_vec<tree, 4> args;