From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1011) id 852273857433; Mon, 4 Jul 2022 17:22:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 852273857433 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Macleod To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8549] Don't use gori depedencies to optimize. X-Act-Checkin: gcc X-Git-Author: Andrew MacLeod X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 32dfb075ad31413af9086ce546b5f5317a916d34 X-Git-Newrev: d4738cbb02e201c031a2a44d8bc10d3e17d987dc Message-Id: <20220704172204.852273857433@sourceware.org> Date: Mon, 4 Jul 2022 17:22:04 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jul 2022 17:22:04 -0000 https://gcc.gnu.org/g:d4738cbb02e201c031a2a44d8bc10d3e17d987dc commit r12-8549-gd4738cbb02e201c031a2a44d8bc10d3e17d987dc Author: Andrew MacLeod Date: Mon Jul 4 11:21:34 2022 -0400 Don't use gori depedencies to optimize. The routine fold_using_range::relation_fold_and_or needs to verify that both operands of 2 stmts are the same, and uses GORIs dependency cache for this. This cache cannot be counted on to reflect the current contents of a stmt, expecially in the presence of an IL changing pass. Instead, look at the statement operands. PR tree-optimization/106114 gcc/ * gimple-range-fold.cc (fold_using_range::relation_fold_and_or): Check statement operands instead of GORI cache. gcc/testsuite/ * gcc.dg/pr106114.c: New. Diff: --- gcc/gimple-range-fold.cc | 30 +++++++++++++++++------------- gcc/testsuite/gcc.dg/pr106114.c | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index dfacf6f14dc..7f03911e1c9 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -1374,14 +1374,25 @@ fold_using_range::relation_fold_and_or (irange& lhs_range, gimple *s, // Ideally we search dependencies for common names, and see what pops out. // until then, simply try to resolve direct dependencies. - // Both names will need to have 2 direct dependencies. - tree ssa1_dep2 = src.gori ()->depend2 (ssa1); - tree ssa2_dep2 = src.gori ()->depend2 (ssa2); - if (!ssa1_dep2 || !ssa2_dep2) + gimple *ssa1_stmt = SSA_NAME_DEF_STMT (ssa1); + gimple *ssa2_stmt = SSA_NAME_DEF_STMT (ssa2); + + range_operator *handler1 = gimple_range_handler (SSA_NAME_DEF_STMT (ssa1)); + range_operator *handler2 = gimple_range_handler (SSA_NAME_DEF_STMT (ssa2)); + + // If either handler is not present, no relation can be found. + if (!handler1 || !handler2) + return; + + // Both stmts will need to have 2 ssa names in the stmt. + tree ssa1_dep1 = gimple_range_ssa_p (gimple_range_operand1 (ssa1_stmt)); + tree ssa1_dep2 = gimple_range_ssa_p (gimple_range_operand2 (ssa1_stmt)); + tree ssa2_dep1 = gimple_range_ssa_p (gimple_range_operand1 (ssa2_stmt)); + tree ssa2_dep2 = gimple_range_ssa_p (gimple_range_operand2 (ssa2_stmt)); + + if (!ssa1_dep1 || !ssa1_dep2 || !ssa2_dep1 || !ssa2_dep2) return; - tree ssa1_dep1 = src.gori ()->depend1 (ssa1); - tree ssa2_dep1 = src.gori ()->depend1 (ssa2); // Make sure they are the same dependencies, and detect the order of the // relationship. bool reverse_op2 = true; @@ -1390,13 +1401,6 @@ fold_using_range::relation_fold_and_or (irange& lhs_range, gimple *s, else if (ssa1_dep1 != ssa2_dep2 || ssa1_dep2 != ssa2_dep1) return; - range_operator *handler1 = gimple_range_handler (SSA_NAME_DEF_STMT (ssa1)); - range_operator *handler2 = gimple_range_handler (SSA_NAME_DEF_STMT (ssa2)); - - // If either handler is not present, no relation is found. - if (!handler1 || !handler2) - return; - int_range<2> bool_one (boolean_true_node, boolean_true_node); relation_kind relation1 = handler1->op1_op2_relation (bool_one); diff --git a/gcc/testsuite/gcc.dg/pr106114.c b/gcc/testsuite/gcc.dg/pr106114.c new file mode 100644 index 00000000000..64c8b8d390a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr106114.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-dom2" } */ + +int printf(const char *, ...); +char a = 139, b; +int main() { + char c = 173; + b = a; + while (c <= a || a < -117) + c = printf("0\n"); + return 0; +} + +/* { dg-final { scan-tree-dump-times "if" 2 "dom2" } } */