public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-1243] middle-end/106070 - bogus cond-expr folding
@ 2022-06-24 12:50 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2022-06-24 12:50 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:b36a1c964f99758de1f3b169628965d3c3af812b
commit r13-1243-gb36a1c964f99758de1f3b169628965d3c3af812b
Author: Richard Biener <rguenther@suse.de>
Date: Fri Jun 24 13:37:22 2022 +0200
middle-end/106070 - bogus cond-expr folding
The following fixes up r13-469-g9a53101caadae1b5 by properly
implementing what operand_equal_for_comparison_p did.
2022-06-24 Richard Biener <rguenther@suse.de>
PR middle-end/106070
* match.pd (a != b ? a : b): Fix translation of
operand_equal_for_comparison_p.
* gcc.dg/torture/pr106070.c: New testcase.
Diff:
---
gcc/match.pd | 11 +++++++----
gcc/testsuite/gcc.dg/torture/pr106070.c | 20 ++++++++++++++++++++
2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/gcc/match.pd b/gcc/match.pd
index 4a570894b2e..e486b4be282 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4574,12 +4574,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(cond (cmp:c (nop_convert1?@c0 @0) (nop_convert2?@c1 @1))
(convert3? @0) (convert4? @1))
(if (!HONOR_SIGNED_ZEROS (type)
- && ((INTEGRAL_TYPE_P (type)
- /* Allow widening conversions of the data. */
+ && (/* Allow widening conversions of the compare operands as data. */
+ (INTEGRAL_TYPE_P (type)
+ && types_match (TREE_TYPE (@c0), TREE_TYPE (@0))
+ && types_match (TREE_TYPE (@c1), TREE_TYPE (@1))
&& TYPE_PRECISION (TREE_TYPE (@0)) <= TYPE_PRECISION (type)
&& TYPE_PRECISION (TREE_TYPE (@1)) <= TYPE_PRECISION (type))
- || (tree_nop_conversion_p (type, TREE_TYPE (@0))
- && tree_nop_conversion_p (type, TREE_TYPE (@1)))))
+ /* Or sign conversions for the comparison. */
+ || (types_match (type, TREE_TYPE (@0))
+ && types_match (type, TREE_TYPE (@1)))))
(switch
(if (cmp == EQ_EXPR)
(if (VECTOR_TYPE_P (type))
diff --git a/gcc/testsuite/gcc.dg/torture/pr106070.c b/gcc/testsuite/gcc.dg/torture/pr106070.c
new file mode 100644
index 00000000000..c36534f8a50
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr106070.c
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+
+unsigned int var_2 = 1;
+int var_4 = -1;
+int var_10 = 4;
+unsigned long arr_252;
+void __attribute__((noipa)) test() {
+ for (int a = 0; a < var_10; a += 2)
+ arr_252 = var_2 != (int)var_4 ? (unsigned long)var_4 : (unsigned long)var_2;
+}
+
+void test();
+
+int main()
+{
+ test();
+ if (arr_252 != 0xffffffffffffffff)
+ __builtin_abort();
+ return 0;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-24 12:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-24 12:50 [gcc r13-1243] middle-end/106070 - bogus cond-expr folding Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).