[gcc(refs/vendors/ARM/heads/arm-struct-reorg-wip)] i386: Avoid reversing a non-trapping comparison to a trapping one [PR95169]
Tamar Christina
tnfchris@gcc.gnu.org
Fri Jul 17 15:02:48 GMT 2020
https://gcc.gnu.org/g:ddfb80adbd91a0e45cc6e04a8b0dbe3ca15ba45f
commit ddfb80adbd91a0e45cc6e04a8b0dbe3ca15ba45f
Author: Uros Bizjak <ubizjak@gmail.com>
Date: Thu May 21 19:36:32 2020 +0200
i386: Avoid reversing a non-trapping comparison to a trapping one [PR95169]
2020-05-21 Uroš Bizjak <ubizjak@gmail.com>
gcc/ChangeLog:
PR target/95169
* config/i386/i386-expand.c (ix86_expand_int_movcc):
Avoid reversing a non-trapping comparison to a trapping one.
gcc/testsuite/ChangeLog:
PR target/95169
* gcc.target/i386/pr95169.c: New test.
Diff:
---
gcc/ChangeLog | 6 ++++++
gcc/config/i386/i386-expand.c | 27 +++++++++++++++++----------
gcc/testsuite/ChangeLog | 5 +++++
gcc/testsuite/gcc.target/i386/pr95169.c | 28 ++++++++++++++++++++++++++++
4 files changed, 56 insertions(+), 10 deletions(-)
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index be6787b08e9..076b8f4c906 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2020-05-21 Uroš Bizjak <ubizjak@gmail.com>
+
+ PR target/95169
+ * config/i386/i386-expand.c (ix86_expand_int_movcc):
+ Avoid reversing a non-trapping comparison to a trapping one.
+
2020-05-21 Martin Liska <mliska@suse.cz>
* common/config/aarch64/aarch64-common.c (aarch64_handle_option):
diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index 48f00c5fcfc..6c759b01edf 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -3059,11 +3059,14 @@ ix86_expand_int_movcc (rtx operands[])
{
gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
- /* We may be reversing unordered compare to normal compare, that
- is not valid in general (we may convert non-trapping condition
- to trapping one), however on i386 we currently emit all
- comparisons unordered. */
- new_code = reverse_condition_maybe_unordered (code);
+ /* We may be reversing a non-trapping
+ comparison to a trapping comparison. */
+ if (HONOR_NANS (cmp_mode) && flag_trapping_math
+ && code != EQ && code != NE
+ && code != ORDERED && code != UNORDERED)
+ new_code = UNKNOWN;
+ else
+ new_code = reverse_condition_maybe_unordered (code);
}
else
new_code = ix86_reverse_condition (code, cmp_mode);
@@ -3215,11 +3218,15 @@ ix86_expand_int_movcc (rtx operands[])
{
gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
- /* We may be reversing unordered compare to normal compare,
- that is not valid in general (we may convert non-trapping
- condition to trapping one), however on i386 we currently
- emit all comparisons unordered. */
- new_code = reverse_condition_maybe_unordered (code);
+ /* We may be reversing a non-trapping
+ comparison to a trapping comparison. */
+ if (HONOR_NANS (cmp_mode) && flag_trapping_math
+ && code != EQ && code != NE
+ && code != ORDERED && code != UNORDERED)
+ new_code = UNKNOWN;
+ else
+ new_code = reverse_condition_maybe_unordered (code);
+
}
else
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 92a989fab08..74b4d088591 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-05-21 Uroš Bizjak <ubizjak@gmail.com>
+
+ PR target/95169
+ * gcc.target/i386/pr95169.c: New test.
+
2020-05-21 Martin Liska <mliska@suse.cz>
* gcc.target/aarch64/target_attr_20.c: New test.
diff --git a/gcc/testsuite/gcc.target/i386/pr95169.c b/gcc/testsuite/gcc.target/i386/pr95169.c
new file mode 100644
index 00000000000..91411744228
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr95169.c
@@ -0,0 +1,28 @@
+/* PR target/95169 */
+/* { dg-do run { target ia32 } } */
+/* { dg-options "-O0 -march=i386 -mtune=generic" } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#include <fenv.h>
+
+void
+f (double y)
+{
+ if (__builtin_expect (y == 0.0, 0))
+ __builtin_abort ();
+}
+
+int
+main (void)
+{
+ double y = __builtin_nan ("");
+
+ feclearexcept (FE_INVALID);
+
+ f (y);
+
+ if (fetestexcept (FE_INVALID))
+ __builtin_abort ();
+
+ return 0;
+}
More information about the Gcc-cvs
mailing list