public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Check negative combined step
@ 2022-01-13  1:48 Jiufu Guo
  2022-01-13  1:48 ` [PATCH 2/2] Add assumption combining iv Jiufu Guo
  2022-01-24 10:37 ` [PATCH 1/2] Check negative combined step Richard Biener
  0 siblings, 2 replies; 11+ messages in thread
From: Jiufu Guo @ 2022-01-13  1:48 UTC (permalink / raw)
  To: gcc-patches
  Cc: rguenther, amker.cheng, guojiufu, wschmidt, segher, dje.gcc, jlaw

Hi,

Previously, there is discussion in:
https://gcc.gnu.org/pipermail/gcc-patches/2021-December/586460.html
I seperate it as two patches.

This first patch is to avoid negative step when combining two ivs.
The second patch is adding more accurate assumptions.

This patch pass bootstrap and regtest on ppc64, ppc64le and x86_64.
Is this ok for trunk?

BR,
Jiufu

	PR tree-optimization/100740

gcc/ChangeLog:

	* tree-ssa-loop-niter.c (number_of_iterations_cond): Check
	sign of combined step.

gcc/testsuite/ChangeLog:

	* gcc.c-torture/execute/pr100740.c: New test.



---
 gcc/tree-ssa-loop-niter.c                      |  6 ++++--
 gcc/testsuite/gcc.c-torture/execute/pr100740.c | 13 +++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr100740.c

diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index b767056aeb0..439d595a79f 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -1890,8 +1890,10 @@ number_of_iterations_cond (class loop *loop,
       tree step = fold_binary_to_constant (MINUS_EXPR, step_type,
 					   iv0->step, iv1->step);
 
-      /* No need to check sign of the new step since below code takes care
-	 of this well.  */
+      /* Like cases shown in PR100740/102131, negtive step is not safe.  */
+      if (tree_int_cst_sign_bit (step))
+	return false;
+
       if (code != NE_EXPR
 	  && (TREE_CODE (step) != INTEGER_CST
 	      || !iv0->no_overflow || !iv1->no_overflow))
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr100740.c b/gcc/testsuite/gcc.c-torture/execute/pr100740.c
new file mode 100644
index 00000000000..381cdeb947a
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr100740.c
@@ -0,0 +1,13 @@
+/* PR tree-optimization/100740 */
+
+unsigned a, b;
+int
+main ()
+{
+  unsigned c = 0;
+  for (a = 0; a < 2; a++)
+    for (b = 0; b < 2; b++)
+      if (++c < a)
+	__builtin_abort ();
+  return 0;
+}
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-01-27  9:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-13  1:48 [PATCH 1/2] Check negative combined step Jiufu Guo
2022-01-13  1:48 ` [PATCH 2/2] Add assumption combining iv Jiufu Guo
2022-01-24 10:37 ` [PATCH 1/2] Check negative combined step Richard Biener
2022-01-25  4:25   ` Jiufu Guo
2022-01-25  5:15     ` Jiufu Guo
2022-01-25  7:47       ` Richard Biener
2022-01-25 11:42         ` Jiufu Guo
2022-01-25 12:02           ` Richard Biener
2022-01-25 12:21             ` Richard Biener
2022-01-27  9:12               ` Jiufu Guo
2022-01-27  9:45                 ` 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).